content
stringlengths 23
1.05M
|
|---|
pragma License (Unrestricted);
-- extended unit
with Ada.Strings.Generic_Unbounded.Generic_Functions;
with Ada.Strings.Wide_Wide_Functions;
package Ada.Strings.Unbounded_Wide_Wide_Strings.Functions is
new Generic_Functions (Wide_Wide_Functions);
pragma Preelaborate (Ada.Strings.Unbounded_Wide_Wide_Strings.Functions);
|
with Ada.Finalization;
with Ada.Streams;
with League.String_Vectors;
with League.Strings;
with PB_Support.Boolean_Vectors;
with PB_Support.IEEE_Float_64_Vectors;
with PB_Support.Integer_32_Vectors;
with PB_Support.Integer_64_Vectors;
with PB_Support.Stream_Element_Vector_Vectors;
with PB_Support.Universal_String_Vectors;
with PB_Support.Unsigned_64_Vectors;
with PB_Support.Vectors;
package Google.Protobuf.Descriptor is
type PB_Type is
(TYPE_DOUBLE, TYPE_FLOAT, TYPE_INT64, TYPE_UINT64, TYPE_INT32,
TYPE_FIXED64, TYPE_FIXED32, TYPE_BOOL, TYPE_STRING, TYPE_GROUP,
TYPE_MESSAGE, TYPE_BYTES, TYPE_UINT32, TYPE_ENUM, TYPE_SFIXED32,
TYPE_SFIXED64, TYPE_SINT32, TYPE_SINT64);
for PB_Type use
(TYPE_DOUBLE => 1, TYPE_FLOAT => 2, TYPE_INT64 => 3,
TYPE_UINT64 => 4, TYPE_INT32 => 5, TYPE_FIXED64 => 6,
TYPE_FIXED32 => 7, TYPE_BOOL => 8, TYPE_STRING => 9,
TYPE_GROUP => 10, TYPE_MESSAGE => 11, TYPE_BYTES => 12,
TYPE_UINT32 => 13, TYPE_ENUM => 14, TYPE_SFIXED32 => 15,
TYPE_SFIXED64 => 16, TYPE_SINT32 => 17, TYPE_SINT64 => 18);
package PB_Type_Vectors is new PB_Support.Vectors (PB_Type);
type Label is (LABEL_OPTIONAL, LABEL_REQUIRED, LABEL_REPEATED);
for Label use
(LABEL_OPTIONAL => 1, LABEL_REQUIRED => 2, LABEL_REPEATED => 3);
package Label_Vectors is new PB_Support.Vectors (Label);
type Optimize_Mode is (SPEED, CODE_SIZE, LITE_RUNTIME);
for Optimize_Mode use
(SPEED => 1, CODE_SIZE => 2, LITE_RUNTIME => 3);
package Optimize_Mode_Vectors is new PB_Support.Vectors (Optimize_Mode);
type CType is (STRING, CORD, STRING_PIECE);
for CType use (STRING => 0, CORD => 1, STRING_PIECE => 2);
package CType_Vectors is new PB_Support.Vectors (CType);
type JSType is (JS_NORMAL, JS_STRING, JS_NUMBER);
for JSType use (JS_NORMAL => 0, JS_STRING => 1, JS_NUMBER => 2);
package JSType_Vectors is new PB_Support.Vectors (JSType);
type File_Descriptor_Set_Vector is tagged private
with Variable_Indexing => Get_File_Descriptor_Set_Variable_Reference,
Constant_Indexing => Get_File_Descriptor_Set_Constant_Reference;
type File_Descriptor_Proto_Vector is tagged private
with Variable_Indexing => Get_File_Descriptor_Proto_Variable_Reference,
Constant_Indexing => Get_File_Descriptor_Proto_Constant_Reference;
type Descriptor_Proto_Vector is tagged private
with Variable_Indexing => Get_Descriptor_Proto_Variable_Reference,
Constant_Indexing => Get_Descriptor_Proto_Constant_Reference;
type Extension_Range_Vector is tagged private
with Variable_Indexing => Get_Extension_Range_Variable_Reference,
Constant_Indexing => Get_Extension_Range_Constant_Reference;
type Reserved_Range_Vector is tagged private
with Variable_Indexing => Get_Reserved_Range_Variable_Reference,
Constant_Indexing => Get_Reserved_Range_Constant_Reference;
type Field_Descriptor_Proto_Vector is tagged private
with Variable_Indexing => Get_Field_Descriptor_Proto_Variable_Reference,
Constant_Indexing => Get_Field_Descriptor_Proto_Constant_Reference;
type Oneof_Descriptor_Proto_Vector is tagged private
with Variable_Indexing => Get_Oneof_Descriptor_Proto_Variable_Reference,
Constant_Indexing => Get_Oneof_Descriptor_Proto_Constant_Reference;
type Enum_Descriptor_Proto_Vector is tagged private
with Variable_Indexing => Get_Enum_Descriptor_Proto_Variable_Reference,
Constant_Indexing => Get_Enum_Descriptor_Proto_Constant_Reference;
type Enum_Value_Descriptor_Proto_Vector is tagged private
with Variable_Indexing =>
Get_Enum_Value_Descriptor_Proto_Variable_Reference,
Constant_Indexing => Get_Enum_Value_Descriptor_Proto_Constant_Reference;
type Service_Descriptor_Proto_Vector is tagged private
with Variable_Indexing => Get_Service_Descriptor_Proto_Variable_Reference,
Constant_Indexing => Get_Service_Descriptor_Proto_Constant_Reference;
type Method_Descriptor_Proto_Vector is tagged private
with Variable_Indexing => Get_Method_Descriptor_Proto_Variable_Reference,
Constant_Indexing => Get_Method_Descriptor_Proto_Constant_Reference;
type File_Options_Vector is tagged private
with Variable_Indexing => Get_File_Options_Variable_Reference,
Constant_Indexing => Get_File_Options_Constant_Reference;
type Message_Options_Vector is tagged private
with Variable_Indexing => Get_Message_Options_Variable_Reference,
Constant_Indexing => Get_Message_Options_Constant_Reference;
type Field_Options_Vector is tagged private
with Variable_Indexing => Get_Field_Options_Variable_Reference,
Constant_Indexing => Get_Field_Options_Constant_Reference;
type Oneof_Options_Vector is tagged private
with Variable_Indexing => Get_Oneof_Options_Variable_Reference,
Constant_Indexing => Get_Oneof_Options_Constant_Reference;
type Enum_Options_Vector is tagged private
with Variable_Indexing => Get_Enum_Options_Variable_Reference,
Constant_Indexing => Get_Enum_Options_Constant_Reference;
type Enum_Value_Options_Vector is tagged private
with Variable_Indexing => Get_Enum_Value_Options_Variable_Reference,
Constant_Indexing => Get_Enum_Value_Options_Constant_Reference;
type Service_Options_Vector is tagged private
with Variable_Indexing => Get_Service_Options_Variable_Reference,
Constant_Indexing => Get_Service_Options_Constant_Reference;
type Method_Options_Vector is tagged private
with Variable_Indexing => Get_Method_Options_Variable_Reference,
Constant_Indexing => Get_Method_Options_Constant_Reference;
type Uninterpreted_Option_Vector is tagged private
with Variable_Indexing => Get_Uninterpreted_Option_Variable_Reference,
Constant_Indexing => Get_Uninterpreted_Option_Constant_Reference;
type Name_Part_Vector is tagged private
with Variable_Indexing => Get_Name_Part_Variable_Reference,
Constant_Indexing => Get_Name_Part_Constant_Reference;
type Source_Code_Info_Vector is tagged private
with Variable_Indexing => Get_Source_Code_Info_Variable_Reference,
Constant_Indexing => Get_Source_Code_Info_Constant_Reference;
type Location_Vector is tagged private
with Variable_Indexing => Get_Location_Variable_Reference,
Constant_Indexing => Get_Location_Constant_Reference;
type Generated_Code_Info_Vector is tagged private
with Variable_Indexing => Get_Generated_Code_Info_Variable_Reference,
Constant_Indexing => Get_Generated_Code_Info_Constant_Reference;
type Annotation_Vector is tagged private
with Variable_Indexing => Get_Annotation_Variable_Reference,
Constant_Indexing => Get_Annotation_Constant_Reference;
type File_Descriptor_Set is
record
File : Google.Protobuf.Descriptor.File_Descriptor_Proto_Vector;
end record;
type Optional_File_Descriptor_Set (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.File_Descriptor_Set;
when False =>
null;
end case;
end record;
function Length (Self : File_Descriptor_Set_Vector) return Natural;
procedure Clear (Self : in out File_Descriptor_Set_Vector);
procedure Append
(Self : in out File_Descriptor_Set_Vector;
V : File_Descriptor_Set);
type File_Descriptor_Set_Variable_Reference
(Element : not null access File_Descriptor_Set) is null record
with Implicit_Dereference => Element;
not overriding function Get_File_Descriptor_Set_Variable_Reference
(Self : aliased in out File_Descriptor_Set_Vector;
Index : Positive)
return File_Descriptor_Set_Variable_Reference
with Inline;
type File_Descriptor_Set_Constant_Reference
(Element : not null access constant File_Descriptor_Set) is null record
with Implicit_Dereference => Element;
not overriding function Get_File_Descriptor_Set_Constant_Reference
(Self : aliased File_Descriptor_Set_Vector;
Index : Positive)
return File_Descriptor_Set_Constant_Reference
with Inline;
type Extension_Range is
record
Start : PB_Support.Integer_32_Vectors.Option;
PB_End : PB_Support.Integer_32_Vectors.Option;
end record;
type Optional_Extension_Range (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Extension_Range;
when False =>
null;
end case;
end record;
function Length (Self : Extension_Range_Vector) return Natural;
procedure Clear (Self : in out Extension_Range_Vector);
procedure Append
(Self : in out Extension_Range_Vector;
V : Extension_Range);
type Extension_Range_Variable_Reference
(Element : not null access Extension_Range) is null record
with Implicit_Dereference => Element;
not overriding function Get_Extension_Range_Variable_Reference
(Self : aliased in out Extension_Range_Vector;
Index : Positive)
return Extension_Range_Variable_Reference
with Inline;
type Extension_Range_Constant_Reference
(Element : not null access constant Extension_Range) is null record
with Implicit_Dereference => Element;
not overriding function Get_Extension_Range_Constant_Reference
(Self : aliased Extension_Range_Vector;
Index : Positive)
return Extension_Range_Constant_Reference
with Inline;
type Reserved_Range is
record
Start : PB_Support.Integer_32_Vectors.Option;
PB_End : PB_Support.Integer_32_Vectors.Option;
end record;
type Optional_Reserved_Range (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Reserved_Range;
when False =>
null;
end case;
end record;
function Length (Self : Reserved_Range_Vector) return Natural;
procedure Clear (Self : in out Reserved_Range_Vector);
procedure Append
(Self : in out Reserved_Range_Vector;
V : Reserved_Range);
type Reserved_Range_Variable_Reference
(Element : not null access Reserved_Range) is null record
with Implicit_Dereference => Element;
not overriding function Get_Reserved_Range_Variable_Reference
(Self : aliased in out Reserved_Range_Vector;
Index : Positive)
return Reserved_Range_Variable_Reference
with Inline;
type Reserved_Range_Constant_Reference
(Element : not null access constant Reserved_Range) is null record
with Implicit_Dereference => Element;
not overriding function Get_Reserved_Range_Constant_Reference
(Self : aliased Reserved_Range_Vector;
Index : Positive)
return Reserved_Range_Constant_Reference
with Inline;
type File_Options is
record
Java_Package : PB_Support.Universal_String_Vectors
.Option;
Java_Outer_Classname : PB_Support.Universal_String_Vectors
.Option;
Java_Multiple_Files : PB_Support.Boolean_Vectors.Option;
Java_Generate_Equals_And_Hash : PB_Support.Boolean_Vectors.Option;
Java_String_Check_Utf_8 : PB_Support.Boolean_Vectors.Option;
Optimize_For : Google.Protobuf.Descriptor
.Optimize_Mode_Vectors.Option;
Go_Package : PB_Support.Universal_String_Vectors
.Option;
Cc_Generic_Services : PB_Support.Boolean_Vectors.Option;
Java_Generic_Services : PB_Support.Boolean_Vectors.Option;
Py_Generic_Services : PB_Support.Boolean_Vectors.Option;
Deprecated : PB_Support.Boolean_Vectors.Option;
Cc_Enable_Arenas : PB_Support.Boolean_Vectors.Option;
Objc_Class_Prefix : PB_Support.Universal_String_Vectors
.Option;
Csharp_Namespace : PB_Support.Universal_String_Vectors
.Option;
Uninterpreted_Option : Google.Protobuf.Descriptor
.Uninterpreted_Option_Vector;
end record;
type Optional_File_Options (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.File_Options;
when False =>
null;
end case;
end record;
function Length (Self : File_Options_Vector) return Natural;
procedure Clear (Self : in out File_Options_Vector);
procedure Append (Self : in out File_Options_Vector; V : File_Options);
type File_Options_Variable_Reference
(Element : not null access File_Options) is null record
with Implicit_Dereference => Element;
not overriding function Get_File_Options_Variable_Reference
(Self : aliased in out File_Options_Vector;
Index : Positive)
return File_Options_Variable_Reference
with Inline;
type File_Options_Constant_Reference
(Element : not null access constant File_Options) is null record
with Implicit_Dereference => Element;
not overriding function Get_File_Options_Constant_Reference
(Self : aliased File_Options_Vector;
Index : Positive)
return File_Options_Constant_Reference
with Inline;
type Message_Options is
record
Message_Set_Wire_Format : PB_Support.Boolean_Vectors.Option;
No_Standard_Descriptor_Accessor : PB_Support.Boolean_Vectors.Option;
Deprecated : PB_Support.Boolean_Vectors.Option;
Map_Entry : PB_Support.Boolean_Vectors.Option;
Uninterpreted_Option : Google.Protobuf.Descriptor
.Uninterpreted_Option_Vector;
end record;
type Optional_Message_Options (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Message_Options;
when False =>
null;
end case;
end record;
function Length (Self : Message_Options_Vector) return Natural;
procedure Clear (Self : in out Message_Options_Vector);
procedure Append
(Self : in out Message_Options_Vector;
V : Message_Options);
type Message_Options_Variable_Reference
(Element : not null access Message_Options) is null record
with Implicit_Dereference => Element;
not overriding function Get_Message_Options_Variable_Reference
(Self : aliased in out Message_Options_Vector;
Index : Positive)
return Message_Options_Variable_Reference
with Inline;
type Message_Options_Constant_Reference
(Element : not null access constant Message_Options) is null record
with Implicit_Dereference => Element;
not overriding function Get_Message_Options_Constant_Reference
(Self : aliased Message_Options_Vector;
Index : Positive)
return Message_Options_Constant_Reference
with Inline;
type Field_Options is
record
Ctype : Google.Protobuf.Descriptor.CType_Vectors.Option;
Packed : PB_Support.Boolean_Vectors.Option;
Jstype : Google.Protobuf.Descriptor.JSType_Vectors
.Option;
Lazy : PB_Support.Boolean_Vectors.Option;
Deprecated : PB_Support.Boolean_Vectors.Option;
Weak : PB_Support.Boolean_Vectors.Option;
Uninterpreted_Option : Google.Protobuf.Descriptor
.Uninterpreted_Option_Vector;
end record;
type Optional_Field_Options (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Field_Options;
when False =>
null;
end case;
end record;
function Length (Self : Field_Options_Vector) return Natural;
procedure Clear (Self : in out Field_Options_Vector);
procedure Append (Self : in out Field_Options_Vector; V : Field_Options);
type Field_Options_Variable_Reference
(Element : not null access Field_Options) is null record
with Implicit_Dereference => Element;
not overriding function Get_Field_Options_Variable_Reference
(Self : aliased in out Field_Options_Vector;
Index : Positive)
return Field_Options_Variable_Reference
with Inline;
type Field_Options_Constant_Reference
(Element : not null access constant Field_Options) is null record
with Implicit_Dereference => Element;
not overriding function Get_Field_Options_Constant_Reference
(Self : aliased Field_Options_Vector;
Index : Positive)
return Field_Options_Constant_Reference
with Inline;
type Oneof_Options is
record
Uninterpreted_Option : Google.Protobuf.Descriptor
.Uninterpreted_Option_Vector;
end record;
type Optional_Oneof_Options (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Oneof_Options;
when False =>
null;
end case;
end record;
function Length (Self : Oneof_Options_Vector) return Natural;
procedure Clear (Self : in out Oneof_Options_Vector);
procedure Append (Self : in out Oneof_Options_Vector; V : Oneof_Options);
type Oneof_Options_Variable_Reference
(Element : not null access Oneof_Options) is null record
with Implicit_Dereference => Element;
not overriding function Get_Oneof_Options_Variable_Reference
(Self : aliased in out Oneof_Options_Vector;
Index : Positive)
return Oneof_Options_Variable_Reference
with Inline;
type Oneof_Options_Constant_Reference
(Element : not null access constant Oneof_Options) is null record
with Implicit_Dereference => Element;
not overriding function Get_Oneof_Options_Constant_Reference
(Self : aliased Oneof_Options_Vector;
Index : Positive)
return Oneof_Options_Constant_Reference
with Inline;
type Enum_Options is
record
Allow_Alias : PB_Support.Boolean_Vectors.Option;
Deprecated : PB_Support.Boolean_Vectors.Option;
Uninterpreted_Option : Google.Protobuf.Descriptor
.Uninterpreted_Option_Vector;
end record;
type Optional_Enum_Options (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Enum_Options;
when False =>
null;
end case;
end record;
function Length (Self : Enum_Options_Vector) return Natural;
procedure Clear (Self : in out Enum_Options_Vector);
procedure Append (Self : in out Enum_Options_Vector; V : Enum_Options);
type Enum_Options_Variable_Reference
(Element : not null access Enum_Options) is null record
with Implicit_Dereference => Element;
not overriding function Get_Enum_Options_Variable_Reference
(Self : aliased in out Enum_Options_Vector;
Index : Positive)
return Enum_Options_Variable_Reference
with Inline;
type Enum_Options_Constant_Reference
(Element : not null access constant Enum_Options) is null record
with Implicit_Dereference => Element;
not overriding function Get_Enum_Options_Constant_Reference
(Self : aliased Enum_Options_Vector;
Index : Positive)
return Enum_Options_Constant_Reference
with Inline;
type Enum_Value_Options is
record
Deprecated : PB_Support.Boolean_Vectors.Option;
Uninterpreted_Option : Google.Protobuf.Descriptor
.Uninterpreted_Option_Vector;
end record;
type Optional_Enum_Value_Options (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Enum_Value_Options;
when False =>
null;
end case;
end record;
function Length (Self : Enum_Value_Options_Vector) return Natural;
procedure Clear (Self : in out Enum_Value_Options_Vector);
procedure Append
(Self : in out Enum_Value_Options_Vector;
V : Enum_Value_Options);
type Enum_Value_Options_Variable_Reference
(Element : not null access Enum_Value_Options) is null record
with Implicit_Dereference => Element;
not overriding function Get_Enum_Value_Options_Variable_Reference
(Self : aliased in out Enum_Value_Options_Vector;
Index : Positive)
return Enum_Value_Options_Variable_Reference
with Inline;
type Enum_Value_Options_Constant_Reference
(Element : not null access constant Enum_Value_Options) is null record
with Implicit_Dereference => Element;
not overriding function Get_Enum_Value_Options_Constant_Reference
(Self : aliased Enum_Value_Options_Vector;
Index : Positive)
return Enum_Value_Options_Constant_Reference
with Inline;
type Service_Options is
record
Deprecated : PB_Support.Boolean_Vectors.Option;
Uninterpreted_Option : Google.Protobuf.Descriptor
.Uninterpreted_Option_Vector;
end record;
type Optional_Service_Options (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Service_Options;
when False =>
null;
end case;
end record;
function Length (Self : Service_Options_Vector) return Natural;
procedure Clear (Self : in out Service_Options_Vector);
procedure Append
(Self : in out Service_Options_Vector;
V : Service_Options);
type Service_Options_Variable_Reference
(Element : not null access Service_Options) is null record
with Implicit_Dereference => Element;
not overriding function Get_Service_Options_Variable_Reference
(Self : aliased in out Service_Options_Vector;
Index : Positive)
return Service_Options_Variable_Reference
with Inline;
type Service_Options_Constant_Reference
(Element : not null access constant Service_Options) is null record
with Implicit_Dereference => Element;
not overriding function Get_Service_Options_Constant_Reference
(Self : aliased Service_Options_Vector;
Index : Positive)
return Service_Options_Constant_Reference
with Inline;
type Method_Options is
record
Deprecated : PB_Support.Boolean_Vectors.Option;
Uninterpreted_Option : Google.Protobuf.Descriptor
.Uninterpreted_Option_Vector;
end record;
type Optional_Method_Options (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Method_Options;
when False =>
null;
end case;
end record;
function Length (Self : Method_Options_Vector) return Natural;
procedure Clear (Self : in out Method_Options_Vector);
procedure Append
(Self : in out Method_Options_Vector;
V : Method_Options);
type Method_Options_Variable_Reference
(Element : not null access Method_Options) is null record
with Implicit_Dereference => Element;
not overriding function Get_Method_Options_Variable_Reference
(Self : aliased in out Method_Options_Vector;
Index : Positive)
return Method_Options_Variable_Reference
with Inline;
type Method_Options_Constant_Reference
(Element : not null access constant Method_Options) is null record
with Implicit_Dereference => Element;
not overriding function Get_Method_Options_Constant_Reference
(Self : aliased Method_Options_Vector;
Index : Positive)
return Method_Options_Constant_Reference
with Inline;
type Name_Part is
record
Name_Part : League.Strings.Universal_String;
Is_Extension : Boolean := False;
end record;
type Optional_Name_Part (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Name_Part;
when False =>
null;
end case;
end record;
function Length (Self : Name_Part_Vector) return Natural;
procedure Clear (Self : in out Name_Part_Vector);
procedure Append (Self : in out Name_Part_Vector; V : Name_Part);
type Name_Part_Variable_Reference (Element : not null access Name_Part) is
null record
with Implicit_Dereference => Element;
not overriding function Get_Name_Part_Variable_Reference
(Self : aliased in out Name_Part_Vector;
Index : Positive)
return Name_Part_Variable_Reference
with Inline;
type Name_Part_Constant_Reference
(Element : not null access constant Name_Part) is null record
with Implicit_Dereference => Element;
not overriding function Get_Name_Part_Constant_Reference
(Self : aliased Name_Part_Vector;
Index : Positive)
return Name_Part_Constant_Reference
with Inline;
type Uninterpreted_Option is
record
Name : Google.Protobuf.Descriptor.Name_Part_Vector;
Identifier_Value : PB_Support.Universal_String_Vectors.Option;
Positive_Int_Value : PB_Support.Unsigned_64_Vectors.Option;
Negative_Int_Value : PB_Support.Integer_64_Vectors.Option;
Double_Value : PB_Support.IEEE_Float_64_Vectors.Option;
String_Value : PB_Support.Stream_Element_Vector_Vectors.Option;
Aggregate_Value : PB_Support.Universal_String_Vectors.Option;
end record;
type Optional_Uninterpreted_Option (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Uninterpreted_Option;
when False =>
null;
end case;
end record;
function Length (Self : Uninterpreted_Option_Vector) return Natural;
procedure Clear (Self : in out Uninterpreted_Option_Vector);
procedure Append
(Self : in out Uninterpreted_Option_Vector;
V : Uninterpreted_Option);
type Uninterpreted_Option_Variable_Reference
(Element : not null access Uninterpreted_Option) is null record
with Implicit_Dereference => Element;
not overriding function Get_Uninterpreted_Option_Variable_Reference
(Self : aliased in out Uninterpreted_Option_Vector;
Index : Positive)
return Uninterpreted_Option_Variable_Reference
with Inline;
type Uninterpreted_Option_Constant_Reference
(Element : not null access constant Uninterpreted_Option) is null record
with Implicit_Dereference => Element;
not overriding function Get_Uninterpreted_Option_Constant_Reference
(Self : aliased Uninterpreted_Option_Vector;
Index : Positive)
return Uninterpreted_Option_Constant_Reference
with Inline;
type Location is
record
Path : PB_Support.Integer_32_Vectors.Vector;
Span : PB_Support.Integer_32_Vectors.Vector;
Leading_Comments : PB_Support.Universal_String_Vectors.Option;
Trailing_Comments : PB_Support.Universal_String_Vectors.Option;
Leading_Detached_Comments : League.String_Vectors
.Universal_String_Vector;
end record;
type Optional_Location (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Location;
when False =>
null;
end case;
end record;
function Length (Self : Location_Vector) return Natural;
procedure Clear (Self : in out Location_Vector);
procedure Append (Self : in out Location_Vector; V : Location);
type Location_Variable_Reference (Element : not null access Location) is
null record
with Implicit_Dereference => Element;
not overriding function Get_Location_Variable_Reference
(Self : aliased in out Location_Vector;
Index : Positive)
return Location_Variable_Reference
with Inline;
type Location_Constant_Reference
(Element : not null access constant Location) is null record
with Implicit_Dereference => Element;
not overriding function Get_Location_Constant_Reference
(Self : aliased Location_Vector;
Index : Positive)
return Location_Constant_Reference
with Inline;
type Source_Code_Info is
record
Location : Google.Protobuf.Descriptor.Location_Vector;
end record;
type Optional_Source_Code_Info (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Source_Code_Info;
when False =>
null;
end case;
end record;
function Length (Self : Source_Code_Info_Vector) return Natural;
procedure Clear (Self : in out Source_Code_Info_Vector);
procedure Append
(Self : in out Source_Code_Info_Vector;
V : Source_Code_Info);
type Source_Code_Info_Variable_Reference
(Element : not null access Source_Code_Info) is null record
with Implicit_Dereference => Element;
not overriding function Get_Source_Code_Info_Variable_Reference
(Self : aliased in out Source_Code_Info_Vector;
Index : Positive)
return Source_Code_Info_Variable_Reference
with Inline;
type Source_Code_Info_Constant_Reference
(Element : not null access constant Source_Code_Info) is null record
with Implicit_Dereference => Element;
not overriding function Get_Source_Code_Info_Constant_Reference
(Self : aliased Source_Code_Info_Vector;
Index : Positive)
return Source_Code_Info_Constant_Reference
with Inline;
type Annotation is
record
Path : PB_Support.Integer_32_Vectors.Vector;
Source_File : PB_Support.Universal_String_Vectors.Option;
PB_Begin : PB_Support.Integer_32_Vectors.Option;
PB_End : PB_Support.Integer_32_Vectors.Option;
end record;
type Optional_Annotation (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Annotation;
when False =>
null;
end case;
end record;
function Length (Self : Annotation_Vector) return Natural;
procedure Clear (Self : in out Annotation_Vector);
procedure Append (Self : in out Annotation_Vector; V : Annotation);
type Annotation_Variable_Reference
(Element : not null access Annotation) is null record
with Implicit_Dereference => Element;
not overriding function Get_Annotation_Variable_Reference
(Self : aliased in out Annotation_Vector;
Index : Positive)
return Annotation_Variable_Reference
with Inline;
type Annotation_Constant_Reference
(Element : not null access constant Annotation) is null record
with Implicit_Dereference => Element;
not overriding function Get_Annotation_Constant_Reference
(Self : aliased Annotation_Vector;
Index : Positive)
return Annotation_Constant_Reference
with Inline;
type Generated_Code_Info is
record
Annotation : Google.Protobuf.Descriptor.Annotation_Vector;
end record;
type Optional_Generated_Code_Info (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Generated_Code_Info;
when False =>
null;
end case;
end record;
function Length (Self : Generated_Code_Info_Vector) return Natural;
procedure Clear (Self : in out Generated_Code_Info_Vector);
procedure Append
(Self : in out Generated_Code_Info_Vector;
V : Generated_Code_Info);
type Generated_Code_Info_Variable_Reference
(Element : not null access Generated_Code_Info) is null record
with Implicit_Dereference => Element;
not overriding function Get_Generated_Code_Info_Variable_Reference
(Self : aliased in out Generated_Code_Info_Vector;
Index : Positive)
return Generated_Code_Info_Variable_Reference
with Inline;
type Generated_Code_Info_Constant_Reference
(Element : not null access constant Generated_Code_Info) is null record
with Implicit_Dereference => Element;
not overriding function Get_Generated_Code_Info_Constant_Reference
(Self : aliased Generated_Code_Info_Vector;
Index : Positive)
return Generated_Code_Info_Constant_Reference
with Inline;
type File_Descriptor_Proto is
record
Name : PB_Support.Universal_String_Vectors.Option;
PB_Package : PB_Support.Universal_String_Vectors.Option;
Dependency : League.String_Vectors.Universal_String_Vector;
Public_Dependency : PB_Support.Integer_32_Vectors.Vector;
Weak_Dependency : PB_Support.Integer_32_Vectors.Vector;
Message_Type : Google.Protobuf.Descriptor.Descriptor_Proto_Vector;
Enum_Type : Google.Protobuf.Descriptor
.Enum_Descriptor_Proto_Vector;
Service : Google.Protobuf.Descriptor
.Service_Descriptor_Proto_Vector;
Extension : Google.Protobuf.Descriptor
.Field_Descriptor_Proto_Vector;
Options : Google.Protobuf.Descriptor.Optional_File_Options;
Source_Code_Info : Google.Protobuf.Descriptor
.Optional_Source_Code_Info;
Syntax : PB_Support.Universal_String_Vectors.Option;
end record;
type Optional_File_Descriptor_Proto (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.File_Descriptor_Proto;
when False =>
null;
end case;
end record;
function Length (Self : File_Descriptor_Proto_Vector) return Natural;
procedure Clear (Self : in out File_Descriptor_Proto_Vector);
procedure Append
(Self : in out File_Descriptor_Proto_Vector;
V : File_Descriptor_Proto);
type File_Descriptor_Proto_Variable_Reference
(Element : not null access File_Descriptor_Proto) is null record
with Implicit_Dereference => Element;
not overriding function Get_File_Descriptor_Proto_Variable_Reference
(Self : aliased in out File_Descriptor_Proto_Vector;
Index : Positive)
return File_Descriptor_Proto_Variable_Reference
with Inline;
type File_Descriptor_Proto_Constant_Reference
(Element : not null access constant File_Descriptor_Proto) is null record
with Implicit_Dereference => Element;
not overriding function Get_File_Descriptor_Proto_Constant_Reference
(Self : aliased File_Descriptor_Proto_Vector;
Index : Positive)
return File_Descriptor_Proto_Constant_Reference
with Inline;
type Descriptor_Proto is
record
Name : PB_Support.Universal_String_Vectors.Option;
Field : Google.Protobuf.Descriptor
.Field_Descriptor_Proto_Vector;
Extension : Google.Protobuf.Descriptor
.Field_Descriptor_Proto_Vector;
Nested_Type : Google.Protobuf.Descriptor.Descriptor_Proto_Vector;
Enum_Type : Google.Protobuf.Descriptor
.Enum_Descriptor_Proto_Vector;
Extension_Range : Google.Protobuf.Descriptor.Extension_Range_Vector;
Oneof_Decl : Google.Protobuf.Descriptor
.Oneof_Descriptor_Proto_Vector;
Options : Google.Protobuf.Descriptor.Optional_Message_Options;
Reserved_Range : Google.Protobuf.Descriptor.Reserved_Range_Vector;
Reserved_Name : League.String_Vectors.Universal_String_Vector;
end record;
type Optional_Descriptor_Proto (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Descriptor_Proto;
when False =>
null;
end case;
end record;
function Length (Self : Descriptor_Proto_Vector) return Natural;
procedure Clear (Self : in out Descriptor_Proto_Vector);
procedure Append
(Self : in out Descriptor_Proto_Vector;
V : Descriptor_Proto);
type Descriptor_Proto_Variable_Reference
(Element : not null access Descriptor_Proto) is null record
with Implicit_Dereference => Element;
not overriding function Get_Descriptor_Proto_Variable_Reference
(Self : aliased in out Descriptor_Proto_Vector;
Index : Positive)
return Descriptor_Proto_Variable_Reference
with Inline;
type Descriptor_Proto_Constant_Reference
(Element : not null access constant Descriptor_Proto) is null record
with Implicit_Dereference => Element;
not overriding function Get_Descriptor_Proto_Constant_Reference
(Self : aliased Descriptor_Proto_Vector;
Index : Positive)
return Descriptor_Proto_Constant_Reference
with Inline;
type Field_Descriptor_Proto is
record
Name : PB_Support.Universal_String_Vectors.Option;
Number : PB_Support.Integer_32_Vectors.Option;
Label : Google.Protobuf.Descriptor.Label_Vectors.Option;
PB_Type : Google.Protobuf.Descriptor.PB_Type_Vectors.Option;
Type_Name : PB_Support.Universal_String_Vectors.Option;
Extendee : PB_Support.Universal_String_Vectors.Option;
Default_Value : PB_Support.Universal_String_Vectors.Option;
Oneof_Index : PB_Support.Integer_32_Vectors.Option;
Json_Name : PB_Support.Universal_String_Vectors.Option;
Options : Google.Protobuf.Descriptor.Optional_Field_Options;
end record;
type Optional_Field_Descriptor_Proto (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Field_Descriptor_Proto;
when False =>
null;
end case;
end record;
function Length (Self : Field_Descriptor_Proto_Vector) return Natural;
procedure Clear (Self : in out Field_Descriptor_Proto_Vector);
procedure Append
(Self : in out Field_Descriptor_Proto_Vector;
V : Field_Descriptor_Proto);
type Field_Descriptor_Proto_Variable_Reference
(Element : not null access Field_Descriptor_Proto) is null record
with Implicit_Dereference => Element;
not overriding function Get_Field_Descriptor_Proto_Variable_Reference
(Self : aliased in out Field_Descriptor_Proto_Vector;
Index : Positive)
return Field_Descriptor_Proto_Variable_Reference
with Inline;
type Field_Descriptor_Proto_Constant_Reference
(Element : not null access constant Field_Descriptor_Proto) is null record
with Implicit_Dereference => Element;
not overriding function Get_Field_Descriptor_Proto_Constant_Reference
(Self : aliased Field_Descriptor_Proto_Vector;
Index : Positive)
return Field_Descriptor_Proto_Constant_Reference
with Inline;
type Oneof_Descriptor_Proto is
record
Name : PB_Support.Universal_String_Vectors.Option;
Options : Google.Protobuf.Descriptor.Optional_Oneof_Options;
end record;
type Optional_Oneof_Descriptor_Proto (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Oneof_Descriptor_Proto;
when False =>
null;
end case;
end record;
function Length (Self : Oneof_Descriptor_Proto_Vector) return Natural;
procedure Clear (Self : in out Oneof_Descriptor_Proto_Vector);
procedure Append
(Self : in out Oneof_Descriptor_Proto_Vector;
V : Oneof_Descriptor_Proto);
type Oneof_Descriptor_Proto_Variable_Reference
(Element : not null access Oneof_Descriptor_Proto) is null record
with Implicit_Dereference => Element;
not overriding function Get_Oneof_Descriptor_Proto_Variable_Reference
(Self : aliased in out Oneof_Descriptor_Proto_Vector;
Index : Positive)
return Oneof_Descriptor_Proto_Variable_Reference
with Inline;
type Oneof_Descriptor_Proto_Constant_Reference
(Element : not null access constant Oneof_Descriptor_Proto) is null record
with Implicit_Dereference => Element;
not overriding function Get_Oneof_Descriptor_Proto_Constant_Reference
(Self : aliased Oneof_Descriptor_Proto_Vector;
Index : Positive)
return Oneof_Descriptor_Proto_Constant_Reference
with Inline;
type Enum_Descriptor_Proto is
record
Name : PB_Support.Universal_String_Vectors.Option;
Value : Google.Protobuf.Descriptor
.Enum_Value_Descriptor_Proto_Vector;
Options : Google.Protobuf.Descriptor.Optional_Enum_Options;
end record;
type Optional_Enum_Descriptor_Proto (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Enum_Descriptor_Proto;
when False =>
null;
end case;
end record;
function Length (Self : Enum_Descriptor_Proto_Vector) return Natural;
procedure Clear (Self : in out Enum_Descriptor_Proto_Vector);
procedure Append
(Self : in out Enum_Descriptor_Proto_Vector;
V : Enum_Descriptor_Proto);
type Enum_Descriptor_Proto_Variable_Reference
(Element : not null access Enum_Descriptor_Proto) is null record
with Implicit_Dereference => Element;
not overriding function Get_Enum_Descriptor_Proto_Variable_Reference
(Self : aliased in out Enum_Descriptor_Proto_Vector;
Index : Positive)
return Enum_Descriptor_Proto_Variable_Reference
with Inline;
type Enum_Descriptor_Proto_Constant_Reference
(Element : not null access constant Enum_Descriptor_Proto) is null record
with Implicit_Dereference => Element;
not overriding function Get_Enum_Descriptor_Proto_Constant_Reference
(Self : aliased Enum_Descriptor_Proto_Vector;
Index : Positive)
return Enum_Descriptor_Proto_Constant_Reference
with Inline;
type Enum_Value_Descriptor_Proto is
record
Name : PB_Support.Universal_String_Vectors.Option;
Number : PB_Support.Integer_32_Vectors.Option;
Options : Google.Protobuf.Descriptor.Optional_Enum_Value_Options;
end record;
type Optional_Enum_Value_Descriptor_Proto (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Enum_Value_Descriptor_Proto;
when False =>
null;
end case;
end record;
function Length (Self : Enum_Value_Descriptor_Proto_Vector) return Natural;
procedure Clear (Self : in out Enum_Value_Descriptor_Proto_Vector);
procedure Append
(Self : in out Enum_Value_Descriptor_Proto_Vector;
V : Enum_Value_Descriptor_Proto);
type Enum_Value_Descriptor_Proto_Variable_Reference
(Element : not null access Enum_Value_Descriptor_Proto) is null record
with Implicit_Dereference => Element;
not overriding function Get_Enum_Value_Descriptor_Proto_Variable_Reference
(Self : aliased in out Enum_Value_Descriptor_Proto_Vector;
Index : Positive)
return Enum_Value_Descriptor_Proto_Variable_Reference
with Inline;
type Enum_Value_Descriptor_Proto_Constant_Reference
(Element : not null access constant Enum_Value_Descriptor_Proto) is
null record
with Implicit_Dereference => Element;
not overriding function Get_Enum_Value_Descriptor_Proto_Constant_Reference
(Self : aliased Enum_Value_Descriptor_Proto_Vector;
Index : Positive)
return Enum_Value_Descriptor_Proto_Constant_Reference
with Inline;
type Service_Descriptor_Proto is
record
Name : PB_Support.Universal_String_Vectors.Option;
Method : Google.Protobuf.Descriptor.Method_Descriptor_Proto_Vector;
Options : Google.Protobuf.Descriptor.Optional_Service_Options;
end record;
type Optional_Service_Descriptor_Proto (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Service_Descriptor_Proto;
when False =>
null;
end case;
end record;
function Length (Self : Service_Descriptor_Proto_Vector) return Natural;
procedure Clear (Self : in out Service_Descriptor_Proto_Vector);
procedure Append
(Self : in out Service_Descriptor_Proto_Vector;
V : Service_Descriptor_Proto);
type Service_Descriptor_Proto_Variable_Reference
(Element : not null access Service_Descriptor_Proto) is null record
with Implicit_Dereference => Element;
not overriding function Get_Service_Descriptor_Proto_Variable_Reference
(Self : aliased in out Service_Descriptor_Proto_Vector;
Index : Positive)
return Service_Descriptor_Proto_Variable_Reference
with Inline;
type Service_Descriptor_Proto_Constant_Reference
(Element : not null access constant Service_Descriptor_Proto) is
null record
with Implicit_Dereference => Element;
not overriding function Get_Service_Descriptor_Proto_Constant_Reference
(Self : aliased Service_Descriptor_Proto_Vector;
Index : Positive)
return Service_Descriptor_Proto_Constant_Reference
with Inline;
type Method_Descriptor_Proto is
record
Name : PB_Support.Universal_String_Vectors.Option;
Input_Type : PB_Support.Universal_String_Vectors.Option;
Output_Type : PB_Support.Universal_String_Vectors.Option;
Options : Google.Protobuf.Descriptor.Optional_Method_Options;
Client_Streaming : PB_Support.Boolean_Vectors.Option;
Server_Streaming : PB_Support.Boolean_Vectors.Option;
end record;
type Optional_Method_Descriptor_Proto (Is_Set : Boolean := False) is
record
case Is_Set is
when True =>
Value : Google.Protobuf.Descriptor.Method_Descriptor_Proto;
when False =>
null;
end case;
end record;
function Length (Self : Method_Descriptor_Proto_Vector) return Natural;
procedure Clear (Self : in out Method_Descriptor_Proto_Vector);
procedure Append
(Self : in out Method_Descriptor_Proto_Vector;
V : Method_Descriptor_Proto);
type Method_Descriptor_Proto_Variable_Reference
(Element : not null access Method_Descriptor_Proto) is null record
with Implicit_Dereference => Element;
not overriding function Get_Method_Descriptor_Proto_Variable_Reference
(Self : aliased in out Method_Descriptor_Proto_Vector;
Index : Positive)
return Method_Descriptor_Proto_Variable_Reference
with Inline;
type Method_Descriptor_Proto_Constant_Reference
(Element : not null access constant Method_Descriptor_Proto) is
null record
with Implicit_Dereference => Element;
not overriding function Get_Method_Descriptor_Proto_Constant_Reference
(Self : aliased Method_Descriptor_Proto_Vector;
Index : Positive)
return Method_Descriptor_Proto_Constant_Reference
with Inline;
private
procedure Read_File_Descriptor_Set
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out File_Descriptor_Set);
procedure Write_File_Descriptor_Set
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : File_Descriptor_Set);
for File_Descriptor_Set'Read use Read_File_Descriptor_Set;
for File_Descriptor_Set'Write use Write_File_Descriptor_Set;
type File_Descriptor_Set_Array is
array (Positive range <>) of aliased File_Descriptor_Set;
type File_Descriptor_Set_Array_Access is access File_Descriptor_Set_Array;
type File_Descriptor_Set_Vector is
new Ada.Finalization.Controlled
with record
Data : File_Descriptor_Set_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out File_Descriptor_Set_Vector);
overriding procedure Finalize (Self : in out File_Descriptor_Set_Vector);
procedure Read_File_Descriptor_Proto
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out File_Descriptor_Proto);
procedure Write_File_Descriptor_Proto
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : File_Descriptor_Proto);
for File_Descriptor_Proto'Read use Read_File_Descriptor_Proto;
for File_Descriptor_Proto'Write use Write_File_Descriptor_Proto;
type File_Descriptor_Proto_Array is
array (Positive range <>) of aliased File_Descriptor_Proto;
type File_Descriptor_Proto_Array_Access is
access File_Descriptor_Proto_Array;
type File_Descriptor_Proto_Vector is
new Ada.Finalization.Controlled
with record
Data : File_Descriptor_Proto_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out File_Descriptor_Proto_Vector);
overriding procedure Finalize (Self : in out File_Descriptor_Proto_Vector);
procedure Read_Extension_Range
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Extension_Range);
procedure Write_Extension_Range
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Extension_Range);
for Extension_Range'Read use Read_Extension_Range;
for Extension_Range'Write use Write_Extension_Range;
type Extension_Range_Array is
array (Positive range <>) of aliased Extension_Range;
type Extension_Range_Array_Access is access Extension_Range_Array;
type Extension_Range_Vector is
new Ada.Finalization.Controlled
with record
Data : Extension_Range_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Extension_Range_Vector);
overriding procedure Finalize (Self : in out Extension_Range_Vector);
procedure Read_Reserved_Range
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Reserved_Range);
procedure Write_Reserved_Range
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Reserved_Range);
for Reserved_Range'Read use Read_Reserved_Range;
for Reserved_Range'Write use Write_Reserved_Range;
type Reserved_Range_Array is
array (Positive range <>) of aliased Reserved_Range;
type Reserved_Range_Array_Access is access Reserved_Range_Array;
type Reserved_Range_Vector is
new Ada.Finalization.Controlled
with record
Data : Reserved_Range_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Reserved_Range_Vector);
overriding procedure Finalize (Self : in out Reserved_Range_Vector);
procedure Read_Descriptor_Proto
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Descriptor_Proto);
procedure Write_Descriptor_Proto
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Descriptor_Proto);
for Descriptor_Proto'Read use Read_Descriptor_Proto;
for Descriptor_Proto'Write use Write_Descriptor_Proto;
type Descriptor_Proto_Array is
array (Positive range <>) of aliased Descriptor_Proto;
type Descriptor_Proto_Array_Access is access Descriptor_Proto_Array;
type Descriptor_Proto_Vector is
new Ada.Finalization.Controlled
with record
Data : Descriptor_Proto_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Descriptor_Proto_Vector);
overriding procedure Finalize (Self : in out Descriptor_Proto_Vector);
procedure Read_Field_Descriptor_Proto
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Field_Descriptor_Proto);
procedure Write_Field_Descriptor_Proto
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Field_Descriptor_Proto);
for Field_Descriptor_Proto'Read use Read_Field_Descriptor_Proto;
for Field_Descriptor_Proto'Write use Write_Field_Descriptor_Proto;
type Field_Descriptor_Proto_Array is
array (Positive range <>) of aliased Field_Descriptor_Proto;
type Field_Descriptor_Proto_Array_Access is
access Field_Descriptor_Proto_Array;
type Field_Descriptor_Proto_Vector is
new Ada.Finalization.Controlled
with record
Data : Field_Descriptor_Proto_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Field_Descriptor_Proto_Vector);
overriding procedure Finalize (Self : in out Field_Descriptor_Proto_Vector);
procedure Read_Oneof_Descriptor_Proto
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Oneof_Descriptor_Proto);
procedure Write_Oneof_Descriptor_Proto
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Oneof_Descriptor_Proto);
for Oneof_Descriptor_Proto'Read use Read_Oneof_Descriptor_Proto;
for Oneof_Descriptor_Proto'Write use Write_Oneof_Descriptor_Proto;
type Oneof_Descriptor_Proto_Array is
array (Positive range <>) of aliased Oneof_Descriptor_Proto;
type Oneof_Descriptor_Proto_Array_Access is
access Oneof_Descriptor_Proto_Array;
type Oneof_Descriptor_Proto_Vector is
new Ada.Finalization.Controlled
with record
Data : Oneof_Descriptor_Proto_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Oneof_Descriptor_Proto_Vector);
overriding procedure Finalize (Self : in out Oneof_Descriptor_Proto_Vector);
procedure Read_Enum_Descriptor_Proto
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Enum_Descriptor_Proto);
procedure Write_Enum_Descriptor_Proto
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Enum_Descriptor_Proto);
for Enum_Descriptor_Proto'Read use Read_Enum_Descriptor_Proto;
for Enum_Descriptor_Proto'Write use Write_Enum_Descriptor_Proto;
type Enum_Descriptor_Proto_Array is
array (Positive range <>) of aliased Enum_Descriptor_Proto;
type Enum_Descriptor_Proto_Array_Access is
access Enum_Descriptor_Proto_Array;
type Enum_Descriptor_Proto_Vector is
new Ada.Finalization.Controlled
with record
Data : Enum_Descriptor_Proto_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Enum_Descriptor_Proto_Vector);
overriding procedure Finalize (Self : in out Enum_Descriptor_Proto_Vector);
procedure Read_Enum_Value_Descriptor_Proto
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Enum_Value_Descriptor_Proto);
procedure Write_Enum_Value_Descriptor_Proto
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Enum_Value_Descriptor_Proto);
for Enum_Value_Descriptor_Proto'Read use Read_Enum_Value_Descriptor_Proto;
for Enum_Value_Descriptor_Proto'Write use Write_Enum_Value_Descriptor_Proto;
type Enum_Value_Descriptor_Proto_Array is
array (Positive range <>) of aliased Enum_Value_Descriptor_Proto;
type Enum_Value_Descriptor_Proto_Array_Access is
access Enum_Value_Descriptor_Proto_Array;
type Enum_Value_Descriptor_Proto_Vector is
new Ada.Finalization.Controlled
with record
Data : Enum_Value_Descriptor_Proto_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust
(Self : in out Enum_Value_Descriptor_Proto_Vector);
overriding procedure Finalize
(Self : in out Enum_Value_Descriptor_Proto_Vector);
procedure Read_Service_Descriptor_Proto
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Service_Descriptor_Proto);
procedure Write_Service_Descriptor_Proto
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Service_Descriptor_Proto);
for Service_Descriptor_Proto'Read use Read_Service_Descriptor_Proto;
for Service_Descriptor_Proto'Write use Write_Service_Descriptor_Proto;
type Service_Descriptor_Proto_Array is
array (Positive range <>) of aliased Service_Descriptor_Proto;
type Service_Descriptor_Proto_Array_Access is
access Service_Descriptor_Proto_Array;
type Service_Descriptor_Proto_Vector is
new Ada.Finalization.Controlled
with record
Data : Service_Descriptor_Proto_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Service_Descriptor_Proto_Vector);
overriding procedure Finalize
(Self : in out Service_Descriptor_Proto_Vector);
procedure Read_Method_Descriptor_Proto
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Method_Descriptor_Proto);
procedure Write_Method_Descriptor_Proto
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Method_Descriptor_Proto);
for Method_Descriptor_Proto'Read use Read_Method_Descriptor_Proto;
for Method_Descriptor_Proto'Write use Write_Method_Descriptor_Proto;
type Method_Descriptor_Proto_Array is
array (Positive range <>) of aliased Method_Descriptor_Proto;
type Method_Descriptor_Proto_Array_Access is
access Method_Descriptor_Proto_Array;
type Method_Descriptor_Proto_Vector is
new Ada.Finalization.Controlled
with record
Data : Method_Descriptor_Proto_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Method_Descriptor_Proto_Vector);
overriding procedure Finalize
(Self : in out Method_Descriptor_Proto_Vector);
procedure Read_File_Options
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out File_Options);
procedure Write_File_Options
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : File_Options);
for File_Options'Read use Read_File_Options;
for File_Options'Write use Write_File_Options;
type File_Options_Array is
array (Positive range <>) of aliased File_Options;
type File_Options_Array_Access is access File_Options_Array;
type File_Options_Vector is
new Ada.Finalization.Controlled
with record
Data : File_Options_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out File_Options_Vector);
overriding procedure Finalize (Self : in out File_Options_Vector);
procedure Read_Message_Options
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Message_Options);
procedure Write_Message_Options
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Message_Options);
for Message_Options'Read use Read_Message_Options;
for Message_Options'Write use Write_Message_Options;
type Message_Options_Array is
array (Positive range <>) of aliased Message_Options;
type Message_Options_Array_Access is access Message_Options_Array;
type Message_Options_Vector is
new Ada.Finalization.Controlled
with record
Data : Message_Options_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Message_Options_Vector);
overriding procedure Finalize (Self : in out Message_Options_Vector);
procedure Read_Field_Options
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Field_Options);
procedure Write_Field_Options
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Field_Options);
for Field_Options'Read use Read_Field_Options;
for Field_Options'Write use Write_Field_Options;
type Field_Options_Array is
array (Positive range <>) of aliased Field_Options;
type Field_Options_Array_Access is access Field_Options_Array;
type Field_Options_Vector is
new Ada.Finalization.Controlled
with record
Data : Field_Options_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Field_Options_Vector);
overriding procedure Finalize (Self : in out Field_Options_Vector);
procedure Read_Oneof_Options
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Oneof_Options);
procedure Write_Oneof_Options
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Oneof_Options);
for Oneof_Options'Read use Read_Oneof_Options;
for Oneof_Options'Write use Write_Oneof_Options;
type Oneof_Options_Array is
array (Positive range <>) of aliased Oneof_Options;
type Oneof_Options_Array_Access is access Oneof_Options_Array;
type Oneof_Options_Vector is
new Ada.Finalization.Controlled
with record
Data : Oneof_Options_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Oneof_Options_Vector);
overriding procedure Finalize (Self : in out Oneof_Options_Vector);
procedure Read_Enum_Options
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Enum_Options);
procedure Write_Enum_Options
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Enum_Options);
for Enum_Options'Read use Read_Enum_Options;
for Enum_Options'Write use Write_Enum_Options;
type Enum_Options_Array is
array (Positive range <>) of aliased Enum_Options;
type Enum_Options_Array_Access is access Enum_Options_Array;
type Enum_Options_Vector is
new Ada.Finalization.Controlled
with record
Data : Enum_Options_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Enum_Options_Vector);
overriding procedure Finalize (Self : in out Enum_Options_Vector);
procedure Read_Enum_Value_Options
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Enum_Value_Options);
procedure Write_Enum_Value_Options
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Enum_Value_Options);
for Enum_Value_Options'Read use Read_Enum_Value_Options;
for Enum_Value_Options'Write use Write_Enum_Value_Options;
type Enum_Value_Options_Array is
array (Positive range <>) of aliased Enum_Value_Options;
type Enum_Value_Options_Array_Access is access Enum_Value_Options_Array;
type Enum_Value_Options_Vector is
new Ada.Finalization.Controlled
with record
Data : Enum_Value_Options_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Enum_Value_Options_Vector);
overriding procedure Finalize (Self : in out Enum_Value_Options_Vector);
procedure Read_Service_Options
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Service_Options);
procedure Write_Service_Options
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Service_Options);
for Service_Options'Read use Read_Service_Options;
for Service_Options'Write use Write_Service_Options;
type Service_Options_Array is
array (Positive range <>) of aliased Service_Options;
type Service_Options_Array_Access is access Service_Options_Array;
type Service_Options_Vector is
new Ada.Finalization.Controlled
with record
Data : Service_Options_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Service_Options_Vector);
overriding procedure Finalize (Self : in out Service_Options_Vector);
procedure Read_Method_Options
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Method_Options);
procedure Write_Method_Options
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Method_Options);
for Method_Options'Read use Read_Method_Options;
for Method_Options'Write use Write_Method_Options;
type Method_Options_Array is
array (Positive range <>) of aliased Method_Options;
type Method_Options_Array_Access is access Method_Options_Array;
type Method_Options_Vector is
new Ada.Finalization.Controlled
with record
Data : Method_Options_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Method_Options_Vector);
overriding procedure Finalize (Self : in out Method_Options_Vector);
procedure Read_Name_Part
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Name_Part);
procedure Write_Name_Part
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Name_Part);
for Name_Part'Read use Read_Name_Part;
for Name_Part'Write use Write_Name_Part;
type Name_Part_Array is array (Positive range <>) of aliased Name_Part;
type Name_Part_Array_Access is access Name_Part_Array;
type Name_Part_Vector is
new Ada.Finalization.Controlled
with record
Data : Name_Part_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Name_Part_Vector);
overriding procedure Finalize (Self : in out Name_Part_Vector);
procedure Read_Uninterpreted_Option
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Uninterpreted_Option);
procedure Write_Uninterpreted_Option
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Uninterpreted_Option);
for Uninterpreted_Option'Read use Read_Uninterpreted_Option;
for Uninterpreted_Option'Write use Write_Uninterpreted_Option;
type Uninterpreted_Option_Array is
array (Positive range <>) of aliased Uninterpreted_Option;
type Uninterpreted_Option_Array_Access is access Uninterpreted_Option_Array;
type Uninterpreted_Option_Vector is
new Ada.Finalization.Controlled
with record
Data : Uninterpreted_Option_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Uninterpreted_Option_Vector);
overriding procedure Finalize (Self : in out Uninterpreted_Option_Vector);
procedure Read_Location
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Location);
procedure Write_Location
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Location);
for Location'Read use Read_Location;
for Location'Write use Write_Location;
type Location_Array is array (Positive range <>) of aliased Location;
type Location_Array_Access is access Location_Array;
type Location_Vector is
new Ada.Finalization.Controlled
with record
Data : Location_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Location_Vector);
overriding procedure Finalize (Self : in out Location_Vector);
procedure Read_Source_Code_Info
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Source_Code_Info);
procedure Write_Source_Code_Info
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Source_Code_Info);
for Source_Code_Info'Read use Read_Source_Code_Info;
for Source_Code_Info'Write use Write_Source_Code_Info;
type Source_Code_Info_Array is
array (Positive range <>) of aliased Source_Code_Info;
type Source_Code_Info_Array_Access is access Source_Code_Info_Array;
type Source_Code_Info_Vector is
new Ada.Finalization.Controlled
with record
Data : Source_Code_Info_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Source_Code_Info_Vector);
overriding procedure Finalize (Self : in out Source_Code_Info_Vector);
procedure Read_Annotation
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Annotation);
procedure Write_Annotation
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Annotation);
for Annotation'Read use Read_Annotation;
for Annotation'Write use Write_Annotation;
type Annotation_Array is array (Positive range <>) of aliased Annotation;
type Annotation_Array_Access is access Annotation_Array;
type Annotation_Vector is
new Ada.Finalization.Controlled
with record
Data : Annotation_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Annotation_Vector);
overriding procedure Finalize (Self : in out Annotation_Vector);
procedure Read_Generated_Code_Info
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : out Generated_Code_Info);
procedure Write_Generated_Code_Info
(Stream : access Ada.Streams.Root_Stream_Type'Class;
V : Generated_Code_Info);
for Generated_Code_Info'Read use Read_Generated_Code_Info;
for Generated_Code_Info'Write use Write_Generated_Code_Info;
type Generated_Code_Info_Array is
array (Positive range <>) of aliased Generated_Code_Info;
type Generated_Code_Info_Array_Access is access Generated_Code_Info_Array;
type Generated_Code_Info_Vector is
new Ada.Finalization.Controlled
with record
Data : Generated_Code_Info_Array_Access;
Length : Natural := 0;
end record;
overriding procedure Adjust (Self : in out Generated_Code_Info_Vector);
overriding procedure Finalize (Self : in out Generated_Code_Info_Vector);
end Google.Protobuf.Descriptor;
|
-- Copyright (c) 2014 onox <denkpadje@gmail.com>
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package body Opus.Encoders is
type Get_Request_Type is
(Get_Application_Request,
Get_Bitrate_Request,
Get_Max_Bandwidth_Request,
Get_VBR_Request,
Get_Bandwidth_Request,
Get_Complexity_Request,
Get_Inband_FEC_Request,
Get_Packet_Loss_Request,
Get_DTX_Request,
Get_VBR_Constraint_Request,
Get_Force_Channels_Request,
Get_Signal_Request,
Get_Lookahead_Request,
Get_Sample_Rate_Request,
Get_Final_Range_Request,
Get_LSB_Depth_Request,
Get_Expert_Frame_Duration_Request,
Get_Prediction_Disabled_Request)
with
Convention => C;
for Get_Request_Type use
(Get_Application_Request => 4001,
Get_Bitrate_Request => 4003,
Get_Max_Bandwidth_Request => 4005,
Get_VBR_Request => 4007,
Get_Bandwidth_Request => 4009,
Get_Complexity_Request => 4011,
Get_Inband_FEC_Request => 4013,
Get_Packet_Loss_Request => 4015,
Get_DTX_Request => 4017,
Get_VBR_Constraint_Request => 4021,
Get_Force_Channels_Request => 4023,
Get_Signal_Request => 4025,
Get_Lookahead_Request => 4027,
Get_Sample_Rate_Request => 4029,
Get_Final_Range_Request => 4031,
Get_LSB_Depth_Request => 4037,
Get_Expert_Frame_Duration_Request => 4041,
Get_Prediction_Disabled_Request => 4043);
type Set_Request_Type is
(Set_Application_Request,
Set_Bitrate_Request,
Set_Max_Bandwidth_Request,
Set_VBR_Request,
Set_Bandwidth_Request,
Set_Complexity_Request,
Set_Inband_FEC_Request,
Set_Packet_Loss_Request,
Set_DTX_Request,
Set_VBR_Constraint_Request,
Set_Force_Channels_Request,
Set_Signal_Request,
Reset_State,
Set_LSB_Depth_Request,
Set_Expert_Frame_Duration_Request,
Set_Prediction_Disabled_Request)
with
Convention => C;
for Set_Request_Type use
(Set_Application_Request => 4000,
Set_Bitrate_Request => 4002,
Set_Max_Bandwidth_Request => 4004,
Set_VBR_Request => 4006,
Set_Bandwidth_Request => 4008,
Set_Complexity_Request => 4010,
Set_Inband_FEC_Request => 4012,
Set_Packet_Loss_Request => 4014,
Set_DTX_Request => 4016,
Set_VBR_Constraint_Request => 4020,
Set_Force_Channels_Request => 4022,
Set_Signal_Request => 4024,
Reset_State => 4028,
Set_LSB_Depth_Request => 4036,
Set_Expert_Frame_Duration_Request => 4040,
Set_Prediction_Disabled_Request => 4042);
generic
Request : Get_Request_Type;
type Return_Type is (<>);
function Get_Request (Encoder : in Encoder_Data) return Return_Type;
function Get_Request (Encoder : in Encoder_Data) return Return_Type is
Result : Return_Type;
function Opus_Encoder_Ctl
(State : in Opus_Encoder;
Request : in Get_Request_Type;
Result : out Return_Type) return Interfaces.C.int
with
Import, Convention => C, External_Name => "opus_encoder_ctl";
Error : constant Interfaces.C.int := Opus_Encoder_Ctl (Encoder.Encoder, Request, Result);
begin
Check_Error (Error);
if not Result'Valid then
raise Invalid_Result;
end if;
return Result;
end Get_Request;
generic
Request : Set_Request_Type;
type Argument_Type is (<>);
procedure Set_Request (Encoder : in Encoder_Data; Argument : in Argument_Type);
procedure Set_Request (Encoder : in Encoder_Data; Argument : in Argument_Type) is
function Opus_Encoder_Ctl
(State : in Opus_Encoder;
Request : in Set_Request_Type;
Argument : in Argument_Type) return Interfaces.C.int
with
Import, Convention => C, External_Name => "opus_encoder_ctl";
Error : constant Interfaces.C.int := Opus_Encoder_Ctl (Encoder.Encoder, Request, Argument);
begin
Check_Error (Error);
end Set_Request;
----------------------------------------------------------------------------
function Create
(Frequency : in Sampling_Rate;
Channels : in Channel_Type;
Application : in Application_Type) return Encoder_Data
is
function Opus_Encoder_Create
(Frequency : in Sampling_Rate;
Channels : in Channel_Type;
Application : in Application_Type;
Error : out Interfaces.C.int) return Opus_Encoder
with
Import, Convention => C, External_Name => "opus_encoder_create";
Error : Interfaces.C.int;
Encoder : Encoder_Data;
begin
Encoder.Encoder := Opus_Encoder_Create (Frequency, Channels, Application, Error);
Encoder.Channels := Channels;
Check_Error (Error);
return Encoder;
end Create;
procedure Destroy (Encoder : in Encoder_Data) is
procedure Opus_Encoder_Destroy (Encoder : in Opus_Encoder)
with Import, Convention => C, External_Name => "opus_encoder_destroy";
begin
Opus_Encoder_Destroy (Encoder.Encoder);
end Destroy;
function Encode
(Encoder : in Encoder_Data;
Audio_Frame : in PCM_Buffer;
Max_Data_Bytes : in Positive) return Byte_Array
is
Result : Byte_Array (0 .. Max_Data_Bytes);
function Opus_Encode
(State : in Opus_Encoder;
Frame : in PCM_Buffer;
Frame_Size : in Interfaces.C.int;
Data : out Byte_Array;
Data_Size : in Integer) return Interfaces.C.int
with Import, Convention => C, External_Name => "opus_encode";
Length_Data : Interfaces.C.int;
Channels : constant Integer := (if Get_Channels (Encoder) = Mono then 1 else 2);
Samples_Per_Channel : constant Interfaces.C.int := Interfaces.C.int (Audio_Frame'Length / Channels);
begin
-- TODO Assert PCM_Buffer'First = 1 and PCM_Buffer'Last >= 20
-- sampling_rate_hz / 1_000 => samples_per_ms
-- samples_per_ms * frame_size_in_ms / channels => samples_per_frame
-- Samples_Per_Millisecond : constant := Natural (Get_Sampling_Rate (Encoder)) / 1_000;
-- Frame_Size_In_Milliseconds : constant := Samples_Per_Channel / Samples_Per_Millisecond;
-- TODO Assert Frame_Size_In_Milliseconds = 2.5 | 5 | 10 | 20 | 40 | 60
Length_Data := Opus_Encode (Encoder.Encoder, Audio_Frame, Samples_Per_Channel, Result, Result'Length);
Check_Error (Length_Data);
return Result (0 .. Integer (Length_Data));
end Encode;
procedure Reset_State (Encoder : in Encoder_Data) is
function Opus_Encoder_Ctl
(State : in Opus_Encoder;
Request : in Interfaces.C.int) return Interfaces.C.int
with
Import, Convention => C, External_Name => "opus_encoder_ctl";
Reset_State_Request : constant := 4028;
Error : constant Interfaces.C.int := Opus_Encoder_Ctl (Encoder.Encoder, Reset_State_Request);
begin
Check_Error (Error);
end Reset_State;
----------------------------------------------------------------------------
procedure Internal_Set_Application is new Set_Request (Set_Application_Request, Application_Type);
procedure Set_Application
(Encoder : in Encoder_Data;
Application : in Application_Type) renames Internal_Set_Application;
function Internal_Get_Application is new Get_Request (Get_Application_Request, Application_Type);
function Get_Application (Encoder : in Encoder_Data) return Application_Type
renames Internal_Get_Application;
procedure Internal_Set_Bitrate is new Set_Request (Set_Bitrate_Request, Bitrate);
procedure Set_Bitrate
(Encoder : in Encoder_Data;
Rate : in Bitrate) renames Internal_Set_Bitrate;
function Internal_Get_Bitrate is new Get_Request (Get_Bitrate_Request, Bitrate);
function Get_Bitrate (Encoder : in Encoder_Data) return Bitrate
renames Internal_Get_Bitrate;
procedure Internal_Set_Bitrate_Type is new Set_Request (Set_Bitrate_Request, Bitrate_Type);
procedure Set_Bitrate
(Encoder : in Encoder_Data;
Rate : in Bitrate_Type) renames Internal_Set_Bitrate_Type;
procedure Internal_Set_Bandwidth is new Set_Request (Set_Bandwidth_Request, Bandwidth);
procedure Set_Bandwidth
(Encoder : in Encoder_Data;
Width : in Bandwidth) renames Internal_Set_Bandwidth;
function Internal_Get_Bandwidth is new Get_Request (Get_Bandwidth_Request, Bandwidth);
function Get_Bandwidth (Encoder : in Encoder_Data) return Bandwidth
renames Internal_Get_Bandwidth;
procedure Internal_Set_Max_Bandwidth is new Set_Request (Set_Max_Bandwidth_Request, Bandpass);
procedure Set_Max_Bandwidth
(Encoder : in Encoder_Data;
Width : in Bandpass) renames Internal_Set_Max_Bandwidth;
function Internal_Get_Max_Bandwidth is new Get_Request (Get_Max_Bandwidth_Request, Bandpass);
function Get_Max_Bandwidth (Encoder : in Encoder_Data) return Bandpass
renames Internal_Get_Max_Bandwidth;
function Get_Channels (Encoder : in Encoder_Data) return Channel_Type is
begin
return Encoder.Channels;
end Get_Channels;
procedure Internal_Set_Complexity is new Set_Request (Set_Complexity_Request, Complexity);
procedure Set_Complexity
(Encoder : in Encoder_Data;
Scale : in Complexity) renames Internal_Set_Complexity;
function Internal_Get_Complexity is new Get_Request (Get_Complexity_Request, Complexity);
function Get_Complexity (Encoder : in Encoder_Data) return Complexity
renames Internal_Get_Complexity;
procedure Set_DTX
(Encoder : in Encoder_Data;
Enable : in Boolean)
is
procedure Internal_Set_DTX is new Set_Request (Set_DTX_Request, C_Boolean);
begin
Internal_Set_DTX (Encoder, C_Boolean (Enable));
end Set_DTX;
function Get_DTX (Encoder : in Encoder_Data) return Boolean is
function Internal_Get_DTX is new Get_Request (Get_DTX_Request, C_Boolean);
begin
return Boolean (Internal_Get_DTX (Encoder));
end Get_DTX;
procedure Internal_Set_Force_Channels is new Set_Request (Set_Force_Channels_Request, Force_Channels);
procedure Set_Force_Channels
(Encoder : in Encoder_Data;
Channels : in Force_Channels) renames Internal_Set_Force_Channels;
function Internal_Get_Force_Channels is new Get_Request (Get_Force_Channels_Request, Force_Channels);
function Get_Force_Channels (Encoder : in Encoder_Data) return Force_Channels
renames Internal_Get_Force_Channels;
procedure Set_Inband_FEC
(Encoder : in Encoder_Data;
Enable : in Boolean)
is
procedure Internal_Set_Inband_FEC is new Set_Request (Set_Inband_FEC_Request, C_Boolean);
begin
Internal_Set_Inband_FEC (Encoder, C_Boolean (Enable));
end Set_Inband_FEC;
function Get_Inband_FEC (Encoder : in Encoder_Data) return Boolean is
function Internal_Get_Inband_FEC is new Get_Request (Get_Inband_FEC_Request, C_Boolean);
begin
return Boolean (Internal_Get_Inband_FEC (Encoder));
end Get_Inband_FEC;
procedure Internal_Set_LSB_Depth is new Set_Request (Set_LSB_Depth_Request, Signal_Depth);
procedure Set_LSB_Depth
(Encoder : in Encoder_Data;
Depth : in Signal_Depth) renames Internal_Set_LSB_Depth;
function Internal_Get_LSB_Depth is new Get_Request (Get_LSB_Depth_Request, Signal_Depth);
function Get_LSB_Depth (Encoder : in Encoder_Data) return Signal_Depth
renames Internal_Get_LSB_Depth;
procedure Internal_Set_Packet_Loss is new Set_Request (Set_Packet_Loss_Request, Percentage);
procedure Set_Packet_Loss
(Encoder : in Encoder_Data;
Expected_Loss : in Percentage) renames Internal_Set_Packet_Loss;
function Internal_Get_Packet_Loss is new Get_Request (Get_Packet_Loss_Request, Percentage);
function Get_Packet_Loss (Encoder : in Encoder_Data) return Percentage
renames Internal_Get_Packet_Loss;
procedure Set_Prediction_Disabled
(Encoder : in Encoder_Data;
Disable : in Boolean)
is
procedure Internal_Set_Prediction_Disabled is new Set_Request (Set_Prediction_Disabled_Request, C_Boolean);
begin
Internal_Set_Prediction_Disabled (Encoder, C_Boolean (Disable));
end Set_Prediction_Disabled;
function Get_Prediction_Disabled (Encoder : in Encoder_Data) return Boolean is
function Internal_Get_Prediction_Disabled is new Get_Request (Get_Prediction_Disabled_Request, C_Boolean);
begin
return Boolean (Internal_Get_Prediction_Disabled (Encoder));
end Get_Prediction_Disabled;
procedure Internal_Set_Signal is new Set_Request (Set_Signal_Request, Signal);
procedure Set_Signal
(Encoder : in Encoder_Data;
Hint : in Signal) renames Internal_Set_Signal;
function Internal_Get_Signal is new Get_Request (Get_Signal_Request, Signal);
function Get_Signal (Encoder : in Encoder_Data) return Signal
renames Internal_Get_Signal;
procedure Set_VBR
(Encoder : in Encoder_Data;
Enable : in Boolean)
is
procedure Internal_Set_VBR is new Set_Request (Set_VBR_Request, C_Boolean);
begin
Internal_Set_VBR (Encoder, C_Boolean (Enable));
end Set_VBR;
function Get_VBR (Encoder : in Encoder_Data) return Boolean is
function Internal_Get_VBR is new Get_Request (Get_VBR_Request, C_Boolean);
begin
return Boolean (Internal_Get_VBR (Encoder));
end Get_VBR;
procedure Set_VBR_Constraint
(Encoder : in Encoder_Data;
Constrain : in Boolean)
is
procedure Internal_Set_VBR_Constraint is new Set_Request (Set_VBR_Constraint_Request, C_Boolean);
begin
Internal_Set_VBR_Constraint (Encoder, C_Boolean (Constrain));
end Set_VBR_Constraint;
function Get_VBR_Constraint (Encoder : in Encoder_Data) return Boolean is
function Internal_Get_VBR_Constraint is new Get_Request (Get_VBR_Constraint_Request, C_Boolean);
begin
return Boolean (Internal_Get_VBR_Constraint (Encoder));
end Get_VBR_Constraint;
procedure Internal_Set_Expert_Frame_Duration is new Set_Request (Set_Expert_Frame_Duration_Request, Frame_Duration);
procedure Set_Expert_Frame_Duration
(Encoder : in Encoder_Data;
Duration : in Frame_Duration) renames Internal_Set_Expert_Frame_Duration;
function Internal_Get_Expert_Frame_Duration is new Get_Request (Get_Expert_Frame_Duration_Request, Frame_Duration);
function Get_Expert_Frame_Duration (Encoder : in Encoder_Data) return Frame_Duration
renames Internal_Get_Expert_Frame_Duration;
function Get_Final_Range (Encoder : in Encoder_Data) return Integer is
function Internal_Get_Final_Range is new Get_Request (Get_Final_Range_Request, Interfaces.C.int);
begin
return Integer (Internal_Get_Final_Range (Encoder));
end Get_Final_Range;
function Get_Lookahead (Encoder : in Encoder_Data) return Positive is
function Internal_Get_Lookahead is new Get_Request (Get_Lookahead_Request, Interfaces.C.int);
begin
return Positive (Internal_Get_Lookahead (Encoder));
end Get_Lookahead;
function Internal_Get_Sample_Rate is new Get_Request (Get_Sample_Rate_Request, Sampling_Rate);
function Get_Sample_Rate (Encoder : in Encoder_Data) return Sampling_Rate
renames Internal_Get_Sample_Rate;
end Opus.Encoders;
|
generic
type T is private;
procedure Cserel (A, B: in out T);
|
with Ada.Text_IO, Ada.Containers.Ordered_Sets;
procedure Set_Demo is
package CS is new Ada.Containers.Ordered_Sets(Character); use CS;
package IO renames Ada.Text_IO;
-- helper functions for string to something conversion, and vice versa
function To_Set(S: String) return Set is
Result: Set;
begin
for I in S'Range loop
begin
Result.Insert(S(I));
-- raises Constraint_Error if S(I) is already in Result
exception
when Constraint_Error => null;
end;
end loop;
return Result;
end To_Set;
function Image(S: Set) return String is
C: Character;
T: Set := S;
begin
if T.Is_Empty then
return "";
else
C:= T.First_Element;
T.Delete_First;
return C & Image(T);
end if;
end Image;
function Image(C: Ada.Containers.Count_Type) return String renames
Ada.Containers.Count_Type'Image;
S1, S2: Set;
begin -- main program
loop
S1 := To_Set(Ada.Text_IO.Get_Line);
exit when S1 = To_Set("quit!");
S2 := To_Set(Ada.Text_IO.Get_Line);
IO.Put_Line("Sets [" & Image(S1) & "], [" & Image(S2) & "] of size"
& Image(S1.Length) & " and" & Image(S2.Length) & ".");
IO.Put_Line("Intersection: [" & Image(Intersection(S1, S2)) & "],");
IO.Put_Line("Union: [" & Image(Union(S1, S2)) & "],");
IO.Put_Line("Difference: [" & Image(Difference(S1, S2)) & "],");
IO.Put_Line("Symmetric Diff: [" & Image(S1 xor S2) & "],");
IO.Put_Line("Subset: " & Boolean'Image(S1.Is_Subset(S2))
& ", Equal: " & Boolean'Image(S1 = S2) & ".");
end loop;
end Set_Demo;
|
with GLOBE_3D.Math;
pragma Elaborate_All (GLOBE_3D.Math);
with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
package body GLOBE_3D.Stars_sky is
Star_Colours : array (1 .. No_of_Stars) of GL.RGB_Color;
Star_Positions : array (1 .. No_of_Stars) of Point_3D; -- normalized position on sphere
procedure Display (Rotation : Matrix_33) is
use GLOBE_3D.Math;
begin
PushMatrix;
Set_GL_Matrix (Rotation);
Disable (TEXTURE_2D);
for i in 1 .. No_of_Stars loop
Color (Star_Colours (i));
GL_Begin (GL.POINTS);
Vertex (Star_Positions (i));
GL_End;
end loop;
PopMatrix;
end Display;
procedure Reset is
seed : Generator;
v : Vector_3D;
int : Real;
use REF, GLOBE_3D.Math;
function Amas return Real is -- expected tendencies : keep near or go far
r : Real;
begin
r := Real (Random (seed));
r := r * 2.0 - 1.0; -- r in - 1 .. 1
r := r ** 8; -- almost always ~0
r := Exp (r * 1.8) - 1.0;
return r;
end Amas;
begin
Reset (seed);
v := (far_side, 0.0, 0.0);
for i in 1 .. No_of_Stars loop
v := XYZ_rotation (Amas, Amas, Amas) * v;
Star_Positions (i) := v;
int := Real (Random (seed)) * 0.3;
Star_Colours (i) := (int + 0.15 * Real (Random (seed)),
int + 0.12 * Real (Random (seed)),
int + 0.12 * Real (Random (seed)));
end loop;
end Reset;
begin
Reset;
end GLOBE_3D.Stars_sky;
|
-------------------------------------------------------------------------------
-- Copyright 2021, The Septum Developers (see AUTHORS file)
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
-- http://www.apache.org/licenses/LICENSE-2.0
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-------------------------------------------------------------------------------
with Ada.Strings.Unbounded;
with ANSI;
with System;
with Trendy_Terminal.IO;
with Trendy_Terminal.VT100;
package SP.Terminal is
-- Functions for operations to the terminal. This hides the usage of Ada.Text_IO and may silently ignore
-- capabilities if the terminal does not support them, such as if coloring text or line clearing is added.
--
-- This module also hides dependencies on unbounded IO.
procedure Put (C : Character) renames Trendy_Terminal.IO.Put;
procedure Put (Str : String) renames Trendy_Terminal.IO.Put;
procedure Put (Str : Ada.Strings.Unbounded.Unbounded_String) renames Trendy_Terminal.IO.Put;
procedure Put_Line (Str : String) renames Trendy_Terminal.IO.Put_Line;
procedure Put_Line (Str : Ada.Strings.Unbounded.Unbounded_String) renames Trendy_Terminal.IO.Put_Line;
procedure New_Line (Spacing : Positive := 1) renames Trendy_Terminal.IO.New_Line;
procedure Set_Col (Spacing : Positive) renames Trendy_Terminal.IO.Set_Col;
procedure Beginning_Of_Line renames Trendy_Terminal.VT100.Beginning_Of_Line;
procedure Clear_Line renames Trendy_Terminal.VT100.Clear_Line;
function Colorize (S : String; Color : ANSI.Colors) return String;
function Colorize (US : Ada.Strings.Unbounded.Unbounded_String; Color : ANSI.Colors)
return Ada.Strings.Unbounded.Unbounded_String;
-- I'm not convinced that these aren't useful. I haven't figured out how best to deal with the really long and
-- verbose terminology of Ada.Strings.Unbounded.Unbounded_String.
-- function "&" (A : String; B : Unbounded_String) return Unbounded_String renames Ada.Strings.Unbounded."&";
-- function "&" (Ada : Unbounded_String; B : String) return Unbounded_String renames Ada.Strings.Unbounded."&";
type FILE_Ptr is new System.Address;
stdin : FILE_Ptr;
pragma Import (C, stdin, "stdin");
-- stdio.h
procedure clearerr (Stream : FILE_Ptr);
pragma Import (C, clearerr, "clearerr");
protected type Cancellation_Gate is
entry Closed;
procedure Finish;
procedure Cancel;
function Is_Cancelled return Boolean;
function Is_Finished return Boolean;
private
Cancelled : Boolean := False;
Finished : Boolean := False;
end Cancellation_Gate;
task type Terminal_Cancellation_Monitor(Gate : not null access Cancellation_Gate) is
entry Cancel;
entry Stop;
end;
end SP.Terminal;
|
-- The Cupcake GUI Toolkit
-- (c) Kristian Klomsten Skordal 2012 <kristian.skordal@gmail.com>
-- Report bugs and issues on <http://github.com/skordal/cupcake/issues>
-- vim:ts=3:sw=3:et:si:sta
with Ada.Text_IO;
with Interfaces.C.Strings;
package body Cupcake.Backends.Cairo is
-- Procedure settings the current color, used by several subprograms below:
procedure Backend_Set_Color (Window_Data : in Backends.Window_Data_Pointer;
R, G, B : in Colors.Color_Component_Type);
pragma Import (C, Backend_Set_Color);
-- Gets the name of the backend:
function Get_Name (This : in Cairo_Backend) return String is
pragma Unreferenced (This);
begin
return "cairo";
end Get_Name;
-- Initializes the backend:
procedure Initialize (This : in out Cairo_Backend) is
function Backend_Initialize return Integer;
pragma Import (C, Backend_Initialize);
begin
if Backend_Initialize /= 1 then
raise Initialization_Error;
end if;
This.Initialized := True;
end Initialize;
-- Checks if the backend has been initialized:
function Is_Initialized (This : in Cairo_Backend) return Boolean is
begin
return This.Initialized;
end Is_Initialized;
-- Finalizes the backend:
procedure Finalize (This : in out Cairo_Backend) is
procedure Backend_Finalize;
pragma Import (C, Backend_Finalize);
begin
if This.Initialized then
Backend_Finalize;
This.Initialized := False;
elsif Debug_Mode then
Ada.Text_IO.Put_Line (
"[Cupcake.Backends.Cairo.Cairo_Backend.Finalize] "
& "Cannot finalize an uninitialized backend!");
end if;
end Finalize;
-- Enters the main loop:
procedure Enter_Main_Loop (This : in out Cairo_Backend) is
pragma Unreferenced (This);
procedure Backend_Main_Loop;
pragma Import (C, Backend_Main_Loop);
begin
Backend_Main_Loop;
end Enter_Main_Loop;
-- Exits the main loop:
procedure Exit_Main_Loop (This : in out Cairo_Backend) is
pragma Unreferenced (This);
procedure Backend_Main_Loop_Terminate;
pragma Import (C, Backend_Main_Loop_Terminate);
begin
Backend_Main_Loop_Terminate;
end Exit_Main_Loop;
-- Creates a new window:
function New_Window (This : in Cairo_Backend; Title : in String;
Size : in Primitives.Dimension;
Position : in Primitives.Point := (0, 0);
Parent : in Window_Data_Pointer := Null_Window_Data_Pointer)
return Window_Data_Pointer
is
use type Cupcake.Primitives.Point;
function Backend_Window_Create (
Parent : in Window_Data_Pointer;
Width, Height : in Positive) return Window_Data_Pointer;
pragma Import (C, Backend_Window_Create);
Retval : constant Window_Data_Pointer := Backend_Window_Create (
Parent, Size.Width, Size.Height);
begin
if Debug_Mode and then Position /= (0, 0) then
Ada.Text_IO.Put_Line (
"[Cupcake.Backends.Cairo.Cairo_Backend.New_Window] "
& "The position argument is currently ignored.");
end if;
This.Set_Window_Title (Retval, Title);
return Retval;
end New_Window;
-- Destroys a window:
procedure Destroy_Window (This : in out Cairo_Backend;
Window_Data : in out Window_Data_Pointer)
is
pragma Unreferenced (This);
procedure Backend_Window_Finalize (Window : in out Window_Data_Pointer);
pragma Import (C, Backend_Window_Finalize);
begin
Backend_Window_Finalize (Window_Data);
end Destroy_Window;
-- Gets the ID for a window:
function Get_Window_ID (This : in Cairo_Backend;
Window_Data : in Backends.Window_Data_Pointer)
return Backends.Window_ID_Type
is
pragma Unreferenced (This);
function Backend_Window_Get_ID (Window_Data : in Window_Data_Pointer)
return Backends.Window_ID_Type;
pragma Import (C, Backend_Window_Get_ID);
begin
return Backend_Window_Get_ID (Window_Data);
end Get_Window_ID;
-- Sets the title of a window:
procedure Set_Window_Title (This : in Cairo_Backend;
Window_Data : in Window_Data_Pointer;
Title : in String)
is
use Interfaces.C.Strings;
pragma Unreferenced (This);
procedure Backend_Window_Set_Title (Window_Data : in Window_Data_Pointer;
Title : in chars_ptr);
pragma Import (C, Backend_Window_Set_Title);
C_Title : chars_ptr := New_String (Title);
begin
Backend_Window_Set_Title (Window_Data, C_Title);
Free (C_Title);
end Set_Window_Title;
-- Sets the size of a window:
procedure Set_Window_Size (This : in Cairo_Backend;
Window_Data : in Window_Data_Pointer;
Size : in Primitives.Dimension) is
begin
Ada.Text_IO.Put_Line (
"[Cupcake.Backends.Cairo.Cairo_Backend.Set_Window_Size]"
& "This procedure has not yet been implemented in this backend");
end Set_Window_Size;
-- Sets the window visibility:
procedure Set_Window_Visibility (This : in Cairo_Backend;
Window_Data : in Window_Data_Pointer;
Visibility : in Boolean)
is
pragma Unreferenced (This);
procedure Backend_Window_Show (Window_Data : in Window_Data_Pointer);
pragma Import (C, Backend_Window_Show);
procedure Backend_Window_Close (Window_Data : in Window_Data_Pointer);
pragma Import (C, Backend_Window_Close);
begin
if Visibility then
Backend_Window_Show (Window_Data);
else
Backend_Window_Close (Window_Data);
end if;
end Set_Window_Visibility;
-- Draws a line:
procedure Draw_Line (This : in out Cairo_Backend;
Window_Data : in Window_Data_Pointer;
Origin, Destination : in Primitives.Point;
Color : in Colors.Color := Colors.BLACK;
Line_Width : in Float := 1.0)
is
pragma Unreferenced (This);
procedure Backend_Draw_Line (Window_Data : in Window_Data_Pointer;
X1, Y1, X2, Y2 : in Natural; Line_Width : in Float);
pragma Import (C, Backend_Draw_Line);
begin
Backend_Set_Color (Window_Data, Color.R, Color.G, Color.B);
Backend_Draw_Line (Window_Data, Origin.X, Origin.Y,
Destination.X, Destination.Y, Line_Width);
end Draw_Line;
-- Draws a circle:
procedure Draw_Circle (This : in out Cairo_Backend;
Window_Data : in Window_Data_Pointer;
Origin : in Primitives.Point;
Radius : in Float; Arc : in Float := 2.0 * Pi;
Color : in Colors.Color := Colors.BLACK; Line_Width : in Float := 1.0) is
pragma Unreferenced (This);
begin
Ada.Text_IO.Put_Line (
"[Cupcake.Backends.Cairo.Cairo_Backend.Draw_Circle] "
& "Not implemented!");
end Draw_Circle;
-- Fills an area:
procedure Fill_Area (This : in out Cairo_Backend;
Window_Data : in Window_Data_Pointer;
Area : in Primitives.Rectangle;
Color : in Colors.Color)
is
pragma Unreferenced (This);
procedure Backend_Fill_Rectangle (Window_Data : in Window_Data_Pointer;
X, Y, W, H : in Natural);
pragma Import (C, Backend_Fill_Rectangle);
begin
Backend_Set_Color (Window_Data, Color.R, Color.G, Color.B);
Backend_Fill_Rectangle (Window_Data, Area.Origin.X, Area.Origin.Y,
Area.Size.Width, Area.Size.Height);
end Fill_Area;
end Cupcake.Backends.Cairo;
|
-- Copyright (c) 2021 Devin Hill
-- zlib License -- see LICENSE for details.
with Interfaces;
use Interfaces;
with Ada.Unchecked_Conversion;
package body GBA.Input is
function Cast is new Ada.Unchecked_Conversion(Key_Flags, Key_Set);
function Cast is new Ada.Unchecked_Conversion(Key_Set, Key_Flags);
function To_Flags (S : Key_Set) return Key_Flags is
( Cast(S) );
function To_Flags (K : Key) return Key_Flags is
function Cast is new Ada.Unchecked_Conversion(Unsigned_16, Key_Flags);
begin
return Cast(Shift_Left(1, Key'Enum_Rep(K)));
end;
function "or" (K1, K2 : Key) return Key_Flags is
( To_Flags(K1) or To_Flags(K2) );
function "or" (F : Key_Flags; K : Key) return Key_Flags is
( F or To_Flags(K) );
function Read_Key_State return Key_Flags is ( not Key_Input );
function Read_Key_State return Key_Set is ( not Cast(Key_Input) );
procedure Disable_Input_Interrupt_Request is
begin
Key_Control.Interrupt_Requested := False;
end;
procedure Request_Interrupt_If_Key_Pressed(K : Key) is
Flags : Key_Flags := To_Flags (K);
begin
Key_Control :=
( Flags => Flags
, Interrupt_Requested => True
, Interrupt_Op => Disjunction
);
end;
procedure Request_Interrupt_If_Any_Pressed(F : Key_Flags) is
begin
Key_Control :=
( Flags => F
, Interrupt_Requested => True
, Interrupt_Op => Disjunction
);
end;
procedure Request_Interrupt_If_All_Pressed(F : Key_Flags) is
begin
Key_Control :=
( Flags => F
, Interrupt_Requested => True
, Interrupt_Op => Conjunction
);
end;
end GBA.Input;
|
pragma Style_Checks (Off);
-- This spec has been automatically generated from ATSAMD51G19A.svd
pragma Restrictions (No_Elaboration_Code);
with HAL;
with System;
package SAM_SVD.PCC is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype PCC_MR_DSIZE_Field is HAL.UInt2;
subtype PCC_MR_ISIZE_Field is HAL.UInt3;
subtype PCC_MR_CID_Field is HAL.UInt2;
-- Mode Register
type PCC_MR_Register is record
-- Parallel Capture Enable
PCEN : Boolean := False;
-- unspecified
Reserved_1_3 : HAL.UInt3 := 16#0#;
-- Data size
DSIZE : PCC_MR_DSIZE_Field := 16#0#;
-- unspecified
Reserved_6_7 : HAL.UInt2 := 16#0#;
-- Scale data
SCALE : Boolean := False;
-- Always Sampling
ALWYS : Boolean := False;
-- Half Sampling
HALFS : Boolean := False;
-- First sample
FRSTS : Boolean := False;
-- unspecified
Reserved_12_15 : HAL.UInt4 := 16#0#;
-- Input Data Size
ISIZE : PCC_MR_ISIZE_Field := 16#0#;
-- unspecified
Reserved_19_29 : HAL.UInt11 := 16#0#;
-- Clear If Disabled
CID : PCC_MR_CID_Field := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PCC_MR_Register use record
PCEN at 0 range 0 .. 0;
Reserved_1_3 at 0 range 1 .. 3;
DSIZE at 0 range 4 .. 5;
Reserved_6_7 at 0 range 6 .. 7;
SCALE at 0 range 8 .. 8;
ALWYS at 0 range 9 .. 9;
HALFS at 0 range 10 .. 10;
FRSTS at 0 range 11 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
ISIZE at 0 range 16 .. 18;
Reserved_19_29 at 0 range 19 .. 29;
CID at 0 range 30 .. 31;
end record;
-- Interrupt Enable Register
type PCC_IER_Register is record
-- Write-only. Data Ready Interrupt Enable
DRDY : Boolean := False;
-- Write-only. Overrun Error Interrupt Enable
OVRE : Boolean := False;
-- unspecified
Reserved_2_31 : HAL.UInt30 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PCC_IER_Register use record
DRDY at 0 range 0 .. 0;
OVRE at 0 range 1 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
-- Interrupt Disable Register
type PCC_IDR_Register is record
-- Write-only. Data Ready Interrupt Disable
DRDY : Boolean := False;
-- Write-only. Overrun Error Interrupt Disable
OVRE : Boolean := False;
-- unspecified
Reserved_2_31 : HAL.UInt30 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PCC_IDR_Register use record
DRDY at 0 range 0 .. 0;
OVRE at 0 range 1 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
-- Interrupt Mask Register
type PCC_IMR_Register is record
-- Read-only. Data Ready Interrupt Mask
DRDY : Boolean;
-- Read-only. Overrun Error Interrupt Mask
OVRE : Boolean;
-- unspecified
Reserved_2_31 : HAL.UInt30;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PCC_IMR_Register use record
DRDY at 0 range 0 .. 0;
OVRE at 0 range 1 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
-- Interrupt Status Register
type PCC_ISR_Register is record
-- Read-only. Data Ready Interrupt Status
DRDY : Boolean;
-- Read-only. Overrun Error Interrupt Status
OVRE : Boolean;
-- unspecified
Reserved_2_31 : HAL.UInt30;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PCC_ISR_Register use record
DRDY at 0 range 0 .. 0;
OVRE at 0 range 1 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
subtype PCC_WPMR_WPKEY_Field is HAL.UInt24;
-- Write Protection Mode Register
type PCC_WPMR_Register is record
-- Write Protection Enable
WPEN : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
-- Write Protection Key
WPKEY : PCC_WPMR_WPKEY_Field := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PCC_WPMR_Register use record
WPEN at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
WPKEY at 0 range 8 .. 31;
end record;
subtype PCC_WPSR_WPVSRC_Field is HAL.UInt16;
-- Write Protection Status Register
type PCC_WPSR_Register is record
-- Read-only. Write Protection Violation Source
WPVS : Boolean;
-- unspecified
Reserved_1_7 : HAL.UInt7;
-- Read-only. Write Protection Violation Status
WPVSRC : PCC_WPSR_WPVSRC_Field;
-- unspecified
Reserved_24_31 : HAL.UInt8;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PCC_WPSR_Register use record
WPVS at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
WPVSRC at 0 range 8 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Parallel Capture Controller
type PCC_Peripheral is record
-- Mode Register
MR : aliased PCC_MR_Register;
-- Interrupt Enable Register
IER : aliased PCC_IER_Register;
-- Interrupt Disable Register
IDR : aliased PCC_IDR_Register;
-- Interrupt Mask Register
IMR : aliased PCC_IMR_Register;
-- Interrupt Status Register
ISR : aliased PCC_ISR_Register;
-- Reception Holding Register
RHR : aliased HAL.UInt32;
-- Write Protection Mode Register
WPMR : aliased PCC_WPMR_Register;
-- Write Protection Status Register
WPSR : aliased PCC_WPSR_Register;
end record
with Volatile;
for PCC_Peripheral use record
MR at 16#0# range 0 .. 31;
IER at 16#4# range 0 .. 31;
IDR at 16#8# range 0 .. 31;
IMR at 16#C# range 0 .. 31;
ISR at 16#10# range 0 .. 31;
RHR at 16#14# range 0 .. 31;
WPMR at 16#E0# range 0 .. 31;
WPSR at 16#E4# range 0 .. 31;
end record;
-- Parallel Capture Controller
PCC_Periph : aliased PCC_Peripheral
with Import, Address => PCC_Base;
end SAM_SVD.PCC;
|
with Ada.Text_IO;
with Progress_Indicators.Bars;
with Progress_Indicators.Spinners;
procedure Test is
use Progress_Indicators.Spinners;
use Progress_Indicators.Bars;
S : Spinner := Make;
Bar_Widths : constant array (Natural range <>) of Natural := (100, 50, 10, 5, 0);
begin
for Width of Bar_Widths loop
for I in Percentage'(0) .. 100 loop
delay 0.02;
Ada.Text_IO.Put (Get_Bar (I, Width));
end loop;
Ada.Text_IO.New_Line;
end loop;
for I in 1 .. 100 loop
delay 0.02;
Tick (S);
Ada.Text_IO.Put (Value (S));
end loop;
end Test;
|
-- This file is generated by SWIG. Please do *not* modify by hand.
--
with Interfaces.C;
with clib.lconv;
with Interfaces.C.Pointers;
with Interfaces.C.Strings;
with System;
package clib.Binding is
function setlocale
(a_a_category : in Interfaces.C.int;
a_a_locale : in Interfaces.C.Strings.chars_ptr)
return Interfaces.C.Strings.chars_ptr;
function localeconv return access clib.lconv.Item;
function lc_CTYPE return Interfaces.C.int;
function lc_NUMERIC return Interfaces.C.int;
function lc_TIME return Interfaces.C.int;
function lc_COLLATE return Interfaces.C.int;
function lc_MONETARY return Interfaces.C.int;
function lc_MESSAGES return Interfaces.C.int;
function lc_ALL return Interfaces.C.int;
function lc_PAPER return Interfaces.C.int;
function lc_NAME return Interfaces.C.int;
function lc_ADDRESS return Interfaces.C.int;
function lc_TELEPHONE return Interfaces.C.int;
function lc_MEASUREMENT return Interfaces.C.int;
function lc_IDENTIFICATION return Interfaces.C.int;
private
pragma Import (C, setlocale, "setlocale");
pragma Import (C, localeconv, "localeconv");
pragma Import (C, lc_CTYPE, "lc_CTYPE");
pragma Import (C, lc_NUMERIC, "lc_NUMERIC");
pragma Import (C, lc_TIME, "lc_TIME");
pragma Import (C, lc_COLLATE, "lc_COLLATE");
pragma Import (C, lc_MONETARY, "lc_MONETARY");
pragma Import (C, lc_MESSAGES, "lc_MESSAGES");
pragma Import (C, lc_ALL, "lc_ALL");
pragma Import (C, lc_PAPER, "lc_PAPER");
pragma Import (C, lc_NAME, "lc_NAME");
pragma Import (C, lc_ADDRESS, "lc_ADDRESS");
pragma Import (C, lc_TELEPHONE, "lc_TELEPHONE");
pragma Import (C, lc_MEASUREMENT, "lc_MEASUREMENT");
pragma Import (C, lc_IDENTIFICATION, "lc_IDENTIFICATION");
end clib.Binding;
|
------------------------------------------------------------------------------
-- G E L A A S I S --
-- ASIS implementation for Gela project, a portable Ada compiler --
-- http://gela.ada-ru.org --
-- - - - - - - - - - - - - - - - --
-- Read copyright and license at the end of this file --
------------------------------------------------------------------------------
-- $Revision: 209 $ $Date: 2013-11-30 21:03:24 +0200 (Сб., 30 нояб. 2013) $:
with XASIS.Utils;
with Asis.Gela.Debug;
with Asis.Gela.Units;
with Asis.Gela.Pools;
with Asis.Gela.Parser;
with Asis.Gela.Errors;
with Asis.Gela.Library;
with Asis.Gela.Implicit;
with Asis.Gela.Implicit.Limited_View;
with Asis.Gela.Resolver;
with Asis.Gela.Normalizer;
with Asis.Gela.Text_Utils;
with Asis.Gela.Unit_Utils;
with Asis.Gela.Compilations;
with Asis.Gela.Element_Utils;
with Ada.Strings.Wide_Maps;
with Gela.Decoders.Create;
package body Asis.Gela.Contexts.Utils is
procedure Normalize
(The_Context : in out Concrete_Context_Node;
Limited_View : in Boolean);
procedure Read_Parent
(The_Context : in out Concrete_Context_Node;
An_Unit : in Compilation_Unit;
Limited_View : in Boolean);
function Parent_Name (An_Unit : Compilation_Unit) return Wide_String;
procedure Read_Unit_Body
(The_Context : in out Concrete_Context_Node;
Full_Unit_Name : in Wide_String;
Place : in Element;
Result : out Compilation_Unit);
procedure Read_Unit_Declaration
(The_Context : in out Concrete_Context_Node;
Full_Unit_Name : in Wide_String;
Place : in Element;
Limited_View : in Boolean;
Result : out Compilation_Unit);
procedure Read_Declaration
(The_Context : in out Concrete_Context_Node;
An_Unit : in Compilation_Unit);
procedure Read_Withed
(The_Context : in out Concrete_Context_Node;
An_Unit : in Compilation_Unit);
procedure Move_First_Pragmas (The_Context : in out Concrete_Context_Node);
procedure Move_Last_Pragmas (The_Context : in out Concrete_Context_Node);
procedure Split_Compilation
(The_Context : in out Concrete_Context_Node;
Limited_View : in Boolean);
procedure Set_Encoding
(The_Context : in out Concrete_Context_Node;
Encoding_Name : in Wide_String);
------------------------
-- Move_First_Pragmas --
------------------------
procedure Move_First_Pragmas (The_Context : in out Concrete_Context_Node) is
use Primary_Unit_Lists;
use Secondary_Pragma_Lists;
use Asis.Gela.Unit_Utils;
function Find_Unit return Asis.Compilation_Unit is
Next : Asis.Element;
begin
for J in 1 .. Length (The_Context.Compilation.all) loop
Next := Get_Item (The_Context.Compilation, J);
if Next.all in Compilation_Unit_Node'Class then
return Asis.Compilation_Unit (Next);
end if;
end loop;
return Asis.Nil_Compilation_Unit;
end Find_Unit;
Index : Natural;
Next : Asis.Element;
Last_Unit : Asis.Element;
begin
Index := Length (The_Context.Compilation.all);
while Index > 0 loop
Next := Get_Item (The_Context.Compilation, Index);
if Next.all in Compilation_Unit_Node'Class then
Last_Unit := Next;
elsif Element_Kind (Next.all) = A_Pragma then
Remove (The_Context.Compilation.all, Next);
Asis.Gela.Element_Utils.Set_Pragma_Kind (Next);
if Is_Program_Unit_Pragma (Pragma_Kind (Next.all))
and Assigned (Last_Unit)
then
Add_Pragma (Last_Unit, Next);
elsif not Is_Configuration_Pragma (Pragma_Kind (Next.all))
and Assigned (Last_Unit)
then
Add_Pragma (Last_Unit, Next, True);
elsif Is_Configuration_Pragma (Pragma_Kind (Next.all)) then
Make_Configuration_Unit (The_Context);
Add_Pragma
(Asis.Element (The_Context.Configuration_Unit), Next);
elsif Is_Program_Unit_Pragma (Pragma_Kind (Next.all)) then
Element_Utils.Set_Enclosing_Compilation_Unit (Next, Find_Unit);
Errors.Report (Item => Next,
What => Errors.Error_Syntax_Misplaced_Pragma,
Argument1 => Pragma_Name_Image (Next.all));
else
Element_Utils.Set_Enclosing_Compilation_Unit (Next, Find_Unit);
Errors.Report (Item => Next,
What => Errors.Warning_Syntax_Ignored_Pragma,
Argument1 => Pragma_Name_Image (Next.all));
end if;
end if;
Index := Index - 1;
end loop;
end Move_First_Pragmas;
-----------------------
-- Move_Last_Pragmas --
-----------------------
procedure Move_Last_Pragmas (The_Context : in out Concrete_Context_Node) is
use Primary_Unit_Lists;
-------------
-- Is_Spec --
-------------
function Is_Spec (Next : Asis.Element) return Boolean is
Kind : Unit_Kinds := Not_A_Unit;
begin
if Next.all in Compilation_Unit_Node'Class then
Kind := Unit_Kind (Compilation_Unit (Next).all);
end if;
if Kind in A_Subprogram_Declaration
or Kind in A_Generic_Procedure .. A_Generic_Function
or Kind in A_Generic_Unit_Instance
then
return True;
else
return False;
end if;
end Is_Spec;
---------------------
-- Is_Right_Pragma --
---------------------
function Is_Right_Pragma (Next, Spec : Asis.Element) return Boolean is
function Direct_Name (Spec : Asis.Element) return Wide_String is
use Asis.Gela.Units;
Name : constant Wide_String :=
Unit_Full_Name (Any_Compilation_Unit_Node (Spec.all));
begin
return Name;
-- for I in reverse Name'Range loop
-- if Name (I) = '.' then
-- Index := I + 1;
-- exit;
-- end if;
-- end loop;
-- return Name (Index .. Name'Last);
end Direct_Name;
Name : constant Wide_String := Direct_Name (Spec);
Args : constant Asis.Association_List :=
Pragma_Argument_Associations (Next.all);
begin
for I in Args'Range loop
declare
use XASIS.Utils;
Param : constant Asis.Element :=
Actual_Parameter (Args (I).all);
Kind : constant Asis.Expression_Kinds :=
Expression_Kind (Param.all);
begin
if (Kind = An_Identifier or Kind = A_Selected_Component)
and then Are_Equal_Identifiers
(Element_Utils.Compound_Name_Image (Param), Name)
then
return True;
end if;
end;
end loop;
return False;
end Is_Right_Pragma;
Index : Positive := 1;
Found : Boolean := False;
Spec : Asis.Element;
Next : Asis.Element;
begin
while Index <= Length (The_Context.Compilation.all) loop
Next := Get_Item (The_Context.Compilation, Index);
if Is_Spec (Next) then
Spec := Next;
Found := True;
Index := Index + 1;
elsif Element_Kind (Next.all) = A_Pragma then
if Found and then Is_Right_Pragma (Next, Spec) then
Remove (The_Context.Compilation.all, Next);
Unit_Utils.Add_Pragma (Spec, Next);
else
Index := Index + 1;
end if;
else
Found := False;
Index := Index + 1;
end if;
end loop;
end Move_Last_Pragmas;
---------------
-- Normalize --
---------------
procedure Normalize
(The_Context : in out Concrete_Context_Node;
Limited_View : in Boolean) is
begin
Move_Last_Pragmas (The_Context);
Move_First_Pragmas (The_Context);
Split_Compilation (The_Context, Limited_View);
end Normalize;
-----------------
-- Parent_Name --
-----------------
function Parent_Name (An_Unit : Compilation_Unit) return Wide_String is
Full_Name : constant Wide_String := Unit_Full_Name (An_Unit.all);
Kind : constant Unit_Kinds := Unit_Kind (An_Unit.all);
begin
if Kind in A_Subunit then
return Separate_Name_Image (An_Unit.all);
elsif XASIS.Utils.Are_Equal_Identifiers (Full_Name, "Standard") then
return "";
else
for I in reverse Full_Name'Range loop
if Full_Name (I) = '.' then
return Full_Name (1 .. I - 1);
end if;
end loop;
return "Standard";
end if;
end Parent_Name;
----------------------
-- Parse_Parameters --
----------------------
procedure Parse_Parameters (The_Context : in out Concrete_Context_Node) is
use Asis.Gela.Library;
use Ada.Strings.Wide_Maps;
Space : constant Wide_Character_Set := To_Set (' ');
Params : U.Unbounded_Wide_String := The_Context.Parameters;
From : Positive;
To : Natural;
begin
Clear_Search_Path;
U.Find_Token (Params, Space, Ada.Strings.Outside, From, To);
while To > 0 loop
declare
Slice : constant Wide_String := U.Slice (Params, From, To);
Word : constant Wide_String (1 .. Slice'Length) := Slice;
begin
U.Delete (Params, 1, To);
U.Find_Token (Params, Space, Ada.Strings.Outside, From, To);
if Word'Length >= 2 and then Word (1) = '-' then
case Word (2) is
when 'I' =>
Add_To_Search_Path (Word (3 .. Word'Last));
when 'A' =>
pragma Assert (Debug.Set (Word (3 .. Word'Last)));
null;
when 'E' =>
Set_Encoding (The_Context, Word (3 .. Word'Last));
when others =>
null;
end case;
else
The_Context.Current_File := U.To_Unbounded_Wide_String (Word);
end if;
end;
end loop;
end Parse_Parameters;
----------------------
-- Read_Declaration --
----------------------
procedure Read_Declaration
(The_Context : in out Concrete_Context_Node;
An_Unit : in Compilation_Unit)
is
use Asis.Gela.Unit_Utils;
Full_Name : constant Wide_String := Unit_Full_Name (An_Unit.all);
Kind : constant Unit_Kinds := Unit_Kind (An_Unit.all);
Class : constant Unit_Classes := Unit_Class (An_Unit.all);
Place : constant Element := Unit_Declaration (An_Unit.all);
Result : Asis.Compilation_Unit;
begin
if Kind in A_Library_Unit_Body
and Class /= A_Public_Declaration_And_Body
then
Read_Unit_Declaration (The_Context, Full_Name, Place, False, Result);
if Unit_Class (Result.all) /= A_Public_Declaration
and Unit_Class (Result.all) /= A_Private_Declaration
then
Errors.Report (Item => Place,
What => Errors.Error_Cant_Read_Unit_Decl,
Argument1 => Full_Name);
Result := Make_Nonexistent_Unit
(The_Context.This, Full_Name, A_Nonexistent_Declaration);
end if;
Set_Body (Result, An_Unit);
end if;
end Read_Declaration;
------------------------------
-- Read_File_And_Supporters --
------------------------------
procedure Read_File_And_Supporters
(The_Context : in out Concrete_Context_Node;
Limited_View : in Boolean := False)
is
use Primary_Unit_Lists;
State : constant Pools.Pool_State := Pools.State (Pool);
use Asis.Gela.Compilations;
Empty_Unit : Asis.Compilation_Unit;
File : constant Wide_String := Current_File (The_Context);
Encoding : Encodings.Encoding := The_Context.User_Encoding;
Buffer : Text_Utils.Source_Buffer_Access;
Decoder : Text_Utils.Decoder_Access;
Root : Asis.Element;
Implicit : Asis.Compilation_Unit;
New_Version : Compilation;
Old_Version : constant Compilation :=
Get_Compilation (The_Context.Compilation_List, File);
begin
if Library.Is_Predefined_Unit (File) then
Encoding := Encodings.UTF_8;
end if;
Decoder := Decoders.Create (Encoding);
Buffer := Text_Utils.New_Buffer (File);
Lines.Vectors.Clear (The_Context.Line_List);
New_Compilation
(The_Context.Compilation_List, File, Buffer, Decoder, New_Version);
Empty_Unit := New_Compilation_Unit (The_Context'Access);
Parser.Run (The_Context.This,
Buffer.all,
Encoding,
Decoder.all,
The_Context.Line_List,
Root);
Set_Line_List (The_Context.Compilation_List,
New_Version,
The_Context.Line_List);
The_Context.Compilation := List (Root);
declare
Units : constant Compilation_Unit_List :=
To_Compilation_Unit_List (The_Context.Compilation.all);
begin
for I in Units'Range loop
Unit_Utils.Set_Compilation (Units (I), New_Version);
Normalizer.Run (Units (I));
end loop;
Normalize (The_Context, Limited_View);
for I in Units'Range loop
Asis.Gela.Implicit.Process_Unit (Units (I));
if Unit_Kind (Units (I).all) = A_Package then
Implicit := Unit_Utils.Make_Limited_View_Unit
(The_Context.This, Units (I));
Gela.Implicit.Limited_View.Populate
(Implicit, Unit_Declaration (Units (I).all));
Secondary_Unit_Lists.Add
(The_Context.Limited_Views, Asis.Element (Implicit));
Read_Parent (The_Context, Implicit, Limited_View => True);
Resolver.Run (Implicit);
end if;
if not Limited_View then
Read_Parent (The_Context, Units (I), Limited_View);
Read_Declaration (The_Context, Units (I));
Read_Withed (The_Context, Units (I));
Resolver.Run (Units (I));
end if;
end loop;
end;
Drop_Compilation
(The_Context.Compilation_List,
Old_Version);
Pools.Set_State (Pool, State);
end Read_File_And_Supporters;
-----------------
-- Read_Parent --
-----------------
procedure Read_Parent
(The_Context : in out Concrete_Context_Node;
An_Unit : in Compilation_Unit;
Limited_View : in Boolean)
is
Parent : constant Wide_String := Parent_Name (An_Unit);
Kind : constant Unit_Kinds := Unit_Kind (An_Unit.all);
Place : constant Element := Unit_Declaration (An_Unit.all);
Result : Compilation_Unit;
begin
if Parent = "" then
return;
elsif Kind in A_Subunit then
Read_Unit_Body (The_Context, Parent, Place, Result);
Unit_Utils.Add_Subunit (Result, An_Unit);
else
Read_Unit_Declaration (The_Context, Parent, Place, Limited_View,
Result);
Unit_Utils.Add_Child (Result, An_Unit);
end if;
end Read_Parent;
--------------------
-- Read_Unit_Body --
--------------------
procedure Read_Unit_Body
(The_Context : in out Concrete_Context_Node;
Full_Unit_Name : in Wide_String;
Place : in Element;
Result : out Compilation_Unit)
is
Body_Name : constant Wide_String := Library.Body_File (Full_Unit_Name);
begin
Result := Compilation_Unit_Body (Full_Unit_Name, The_Context);
if Assigned (Result) then
return;
end if;
if Library.File_Exists (Body_Name) then
The_Context.Current_File := W.To_Unbounded_Wide_String (Body_Name);
else
Errors.Report (Item => Place,
What => Errors.Error_Cant_Read_Unit,
Argument1 => Full_Unit_Name);
return;
end if;
-- recursive call --------------------------------
Read_File_And_Supporters (The_Context); -- <-
-- recursive call --------------------------------
Result := Compilation_Unit_Body (Full_Unit_Name, The_Context);
if not Assigned (Result) then
Result := Unit_Utils.Make_Nonexistent_Unit
(The_Context.This, Full_Unit_Name, A_Nonexistent_Body);
end if;
end Read_Unit_Body;
---------------------------
-- Read_Unit_Declaration --
---------------------------
procedure Read_Unit_Declaration
(The_Context : in out Concrete_Context_Node;
Full_Unit_Name : in Wide_String;
Place : in Element;
Limited_View : in Boolean;
Result : out Compilation_Unit)
is
Decl_Name : constant Wide_String :=
Library.Declaration_File (Full_Unit_Name);
begin
if not Limited_View then
Result := Library_Unit_Declaration (Full_Unit_Name, The_Context);
if Assigned (Result) then
return;
end if;
end if;
Result := Contexts.Limited_View (Full_Unit_Name, The_Context);
if Assigned (Result) then
if not Limited_View then
-- Turn limited view into ordinary
Result := Corresponding_Declaration (Result.all);
Secondary_Unit_Lists.Add
(The_Context.Library_Unit_Declarations, Asis.Element (Result));
Read_Parent (The_Context, Result, Limited_View => False);
Read_Declaration (The_Context, Result);
Read_Withed (The_Context, Result);
Resolver.Run (Result);
end if;
return;
end if;
if Library.Has_Declaration (Full_Unit_Name) then
The_Context.Current_File := W.To_Unbounded_Wide_String (Decl_Name);
else
Read_Unit_Body (The_Context, Full_Unit_Name, Place, Result);
return;
end if;
-- recursive call ----------------------------------------------
Read_File_And_Supporters (The_Context, Limited_View); -- <-
-- recursive call ----------------------------------------------
if Limited_View then
Result := Contexts.Limited_View (Full_Unit_Name, The_Context);
else
Result := Library_Unit_Declaration (Full_Unit_Name, The_Context);
end if;
if not Assigned (Result) then
Result := Unit_Utils.Make_Nonexistent_Unit
(The_Context.This, Full_Unit_Name, A_Nonexistent_Declaration);
end if;
end Read_Unit_Declaration;
-----------------
-- Read_Withed --
-----------------
procedure Read_Withed
(The_Context : in out Concrete_Context_Node;
An_Unit : in Compilation_Unit)
is
Clauses : constant Asis.Context_Clause_List :=
Context_Clause_Elements (An_Unit.all);
Result : Asis.Compilation_Unit;
begin
for I in Clauses'Range loop
if Clause_Kind (Clauses (I).all) = A_With_Clause then
declare
Names : constant Name_List := Clause_Names (Clauses (I).all);
Limited_View : constant Boolean :=
Has_Limited (Clauses (I).all);
begin
for J in Names'Range loop
declare
Full_Name : constant Program_Text :=
XASIS.Utils.Name_Image (Names (J));
begin
Result := Nil_Compilation_Unit;
Read_Unit_Declaration
(The_Context, Full_Name, Names (J), Limited_View,
Result);
end;
end loop;
end;
end if;
end loop;
end Read_Withed;
------------------
-- Set_Encoding --
------------------
procedure Set_Encoding
(The_Context : in out Concrete_Context_Node;
Encoding_Name : in Wide_String) is
begin
The_Context.User_Encoding :=
Encodings.Encoding'Wide_Value (Encoding_Name);
exception when Constraint_Error =>
Report_Error (The_Context, Text => "Unknown encoding: " & Encoding_Name);
end Set_Encoding;
-----------------------
-- Split_Compilation --
-----------------------
procedure Split_Compilation
(The_Context : in out Concrete_Context_Node;
Limited_View : in Boolean)
is
use Primary_Unit_Lists;
use Secondary_Unit_Lists;
use Asis.Gela.Unit_Utils;
Index : Natural;
Next : Asis.Element;
begin
Index := Length (The_Context.Compilation.all);
while Index > 0 loop
Next := Get_Item (The_Context.Compilation, Index);
Remove (The_Context.Compilation.all, Next);
if Limited_View then
-- Partially processed units shouldn't be available
null;
elsif Next.all in Compilation_Unit_Node'Class then
if Is_Compilation_Unit_Body (Compilation_Unit (Next)) then
Add (The_Context.Compilation_Unit_Bodies, Next);
else
Add (The_Context.Library_Unit_Declarations, Next);
end if;
end if;
Index := Index - 1;
end loop;
end Split_Compilation;
----------------------
-- Compilation_List --
----------------------
function Compilation_List
(The_Context : in Asis.Context)
return Gela.Compilations.Compilation_List
is
Node : Concrete_Context_Node renames
Concrete_Context_Node (The_Context.all);
begin
return Node.Compilation_List;
end Compilation_List;
end Asis.Gela.Contexts.Utils;
------------------------------------------------------------------------------
-- Copyright (c) 2006-2013, Maxim Reznik
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- * Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
-- * Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
-- * Neither the name of the Maxim Reznik, IE nor the names of its
-- contributors may be used to endorse or promote products derived from
-- this software without specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
|
with RASCAL.Utility; use RASCAL.Utility;
with RASCAL.Heap; use RASCAL.Heap;
package AcronymList is
------------------------------------------------------------------------
-- | Generic ADT for one-way linked lists
-- | Author: Michael B. Feldman, The George Washington University
-- | Last Modified: January 1996
------------------------------------------------------------------------
-- exported types
type Meaning_Type is
record
Category: UString;
Buffer : Heap_Block_Pointer;
FileSize: natural;
end record;
type Meaning_Pointer is access Meaning_Type;
type Position is private;
type List is limited private;
type ListPointer is access List;
-- exported exceptions
OutOfSpace : exception; -- raised if no space left for a new node
PastEnd : exception; -- raised if a Position is past the end
PastBegin : exception; -- raised if a Position is before the begin
EmptyList : exception;
-- basic constructors
procedure AddToRear (L : in out List; X : Meaning_Pointer);
-- Pre: L and X are defined
-- Post: a node containing X is inserted
-- at the front or rear of L, respectively
-- basic selectors
function First (L : List) return Position;
function Retrieve (L : in List; P : in Position)
return Meaning_Pointer;
-- Pre: L and P are defined; P designates a node in L
-- Post: returns the value of the element at position P
-- Raises: EmptyList if L is empty
-- PastBegin if P points before the beginning of L
-- PastEnd if P points beyond the end of L
-- other constructors
procedure Delete (L : in out List; P : Position);
-- Pre: L and P are defined; P designates a node in L
-- Post: the node at position P of L is deleted
-- Raises: EmptyList if L is empty
-- PastBegin if P is NULL
-- iterator operations
procedure GoAhead (L : List; P : in out Position);
-- Pre: L and P are defined; P designates a node in L
-- Post: P is advanced to designate the next node of L
-- Raises: EmptyList if L is empty
-- PastEnd if P points beyond the end of L
procedure GoBack (L : List; P : in out Position);
-- Pre: L and P are defined; P designates a node in L
-- Post: P is moved to designate the previous node of L
-- Raises: EmptyList if L is empty
-- PastBegin if P points beyond the end of L
-- inquiry operators
function IsEmpty (L : List) return Boolean;
function IsFirst (L : List; P : Position) return Boolean;
function IsLast (L : List; P : Position) return Boolean;
function IsPastEnd (L : List; P : Position) return Boolean;
function IsPastBegin (L : List; P : Position) return Boolean;
-- Pre: L and P are defined
-- Post: return True if the condition is met; False otherwise
private
type Node;
type Position is access Node;
type Node is record
Info : Meaning_Pointer;
Link : Position;
end record;
type List is record
Head : Position;
Tail : Position;
end record;
end AcronymList;
|
package EU_Projects.Nodes.Risks is
type Risk_Descriptor is new Nodes.Node_Type with private;
type Risk_Access is access Risk_Descriptor;
type Risk_Label is new Dotted_Identifier;
type Risk_Index is new Nodes.Node_Index;
type Risk_Severity is (Very_Small, Small, Medium, Large, Very_Large);
type Risk_Likeness is (Very_Small, Small, Medium, Large, Very_Large);
function New_Risk (Label : Risk_Label;
Description : String;
Countermeasures : String;
Severity : Risk_Severity;
Likeness : Risk_Likeness)
return Risk_Access;
function Label (Item : Risk_Descriptor) return Risk_Label;
function Description (Item : Risk_Descriptor) return String;
function Countermeasures (Item : Risk_Descriptor) return String;
function Severity (Item : Risk_Descriptor) return Risk_Severity;
function Likeness (Item : Risk_Descriptor) return Risk_Likeness;
function Full_Index (Item : Risk_Descriptor;
Prefixed : Boolean) return String;
pragma Warnings (Off);
function Get_Symbolic_Instant (Item : Risk_Descriptor;
Var : Simple_Identifier)
return Times.Time_Expressions.Symbolic_Instant
is (raise Unknown_Instant_Var);
function Get_Symbolic_Duration (Item : Risk_Descriptor;
Var : Simple_Identifier)
return Times.Time_Expressions.Symbolic_Duration
is (raise Unknown_Duration_Var);
function Dependency_List (Item : Risk_Descriptor)
return Node_Label_Lists.Vector
is (Node_Label_Lists.Empty_Vector);
pragma Warnings (On);
private
type Risk_Descriptor is
new Nodes.Node_Type
with record
Countemeasures : Unbounded_String;
Severity : Risk_Severity;
Likeness : Risk_Likeness;
end record;
function Full_Index (Item : Risk_Descriptor;
Prefixed : Boolean) return String
is ("R" & Item.Index_Image);
end EU_Projects.Nodes.Risks;
|
with AWS.Response;
with AWS.Services.Page_Server;
with AWS.Services.Directory;
with AWS.Server;
with AWS.Status;
package Server is
function Callback (Request : AWS.Status.Data) return AWS.Response.Data;
procedure Start_Server;
private
end Server;
|
-- This package has been generated automatically by GNATtest.
-- Do not edit any part of it, see GNATtest documentation for more details.
-- begin read only
with Gnattest_Generated;
package Tk.Bind.Test_Data.Tests is
type Test is new GNATtest_Generated.GNATtest_Standard.Tk.Bind.Test_Data
.Test with
null record;
procedure Test_Modifier_Type_Image_4c8acf_353f1d(Gnattest_T: in out Test);
-- tk-bind.ads:259:4:Modifier_Type_Image:Test_Modifier_Type_Image
procedure Test_Key_Syms_Type_Image_c4d722_679161(Gnattest_T: in out Test);
-- tk-bind.ads:262:4:Key_Syms_Type_Image:Test_Key_Syms_Image
procedure Test_Tk_Bind_09337a_b9da3f(Gnattest_T: in out Test);
-- tk-bind.ads:265:4:Tk_Bind:Test_Bind
procedure Test_Tk_Bind_45f058_8585f0(Gnattest_T: in out Test);
-- tk-bind.ads:271:4:Tk_Bind:Test_Bind2
end Tk.Bind.Test_Data.Tests;
-- end read only
|
with Ada.Text_IO, Ada.Characters.Latin_1, VisitableIntrospectorPackage, VisitablePackage;
use Ada.Text_IO, Ada.Characters.Latin_1, VisitableIntrospectorPackage, VisitablePackage;
package body EnvironmentPackage is
--private
procedure makeEnvironment(env: in out Environment; len: Integer ; intro: IntrospectorPtr) is
begin
env.omega := new IntArray(0..len);
env.subterm := new ObjectPtrArray(0..len);
env.current := 0; -- root is in subterm(0)
env.omega(0) := 0; -- the first cell is not used
env.introspector := intro;
end;
procedure makeEnvironment(env: in out Environment) is
begin
makeEnvironment(env, DEFAULT_LENGTH, getInstance);
end;
procedure makeEnvironment(env: in out Environment; intro: IntrospectorPtr) is
begin
makeEnvironment(env, DEFAULT_LENGTH, intro);
end;
function newEnvironment return EnvironmentPtr is
ret : EnvironmentPtr := new Environment;
begin
makeEnvironment(ret.all);
return ret;
end;
function newEnvironment(intro: IntrospectorPtr) return EnvironmentPtr is
ret : EnvironmentPtr := new Environment;
begin
makeEnvironment(ret.all, intro);
return ret;
end;
--private
procedure ensureLength(env: in out Environment; minLength: Integer) is
max : Integer := Integer'Max(env.omega'Length * 2 , minLength);
newOmega : IntArrayPtr := new IntArray(0..max-1);
newSubterm : ObjectPtrArrayPtr := new ObjectPtrArray(0..max-1);
begin
if minLength > env.omega'Length then
newOmega( env.omega'Range ) := env.omega( env.omega'Range );
newSubterm( env.omega'Range ) := env.subterm( env.subterm'Range );
env.omega := newOmega;
env.subterm := newSubterm;
end if;
end;
function clone(env: Environment) return Environment is
newEnv : Environment := env;
begin
newEnv.omega := new IntArray(env.omega'Range);
newEnv.subterm := new ObjectPtrArray(env.subterm'Range);
newEnv.omega( newEnv.omega'Range ) := env.omega( env.omega'Range );
newEnv.subterm( newEnv.subterm'Range ) := env.subterm( env.subterm'Range );
return newEnv;
end;
function equals(env1, env2 : Environment) return Boolean is
c : Integer := env1.current;
begin
if env1.current = env2.current and then
env1.omega(0..c) = env2.omega(0..c) and then env2.subterm(0..c) = env2.subterm(0..c) then
return true;
else
return False;
end if;
end;
function hashCode(env: Environment) return Integer is
begin
return 0;
end;
function getStatus(env: Environment) return Integer is
begin
return env.status;
end;
procedure setStatus(env: in out Environment; s: Integer) is
begin
env.status := s;
end;
function getRoot(env: Environment) return ObjectPtr is
begin
return env.subterm(env.subterm'First);
end;
procedure setRoot(env: in out Environment; r: ObjectPtr) is
begin
env.subterm(env.subterm'First) := r;
end;
function getCurrentStack(env: Environment) return ObjectPtrArray is
begin
return env.subterm(0..env.current-1);
end;
function getAncestor(env: Environment) return ObjectPtr is
begin
return env.subterm(env.current-1);
end;
function getSubject(env: Environment) return ObjectPtr is
begin
return env.subterm(env.current);
end;
procedure setSubject(env: in out Environment; root: ObjectPtr) is
begin
env.subterm(env.current) := root;
end;
function getIntrospector(env: Environment) return IntrospectorPtr is
begin
return env.introspector;
end;
procedure setIntrospector(env: in out Environment; i: IntrospectorPtr) is
begin
env.introspector := i;
end;
function getSubOmega(env: Environment) return Integer is
begin
return env.omega(env.current);
end;
function depth(env: Environment) return Integer is
begin
return env.current;
end;
function getPosition(env: Environment) return Position is
begin
return PositionPackage.makeFromSubarray(env.omega, env.omega'First+1, depth(env));
end;
procedure up(env: in out Environment) is
childIndex : Integer := env.omega(env.current)-1;
child : ObjectPtr := env.subterm(env.current);
begin
env.current := env.current - 1;
env.subterm(env.current) := setChildAt(env.introspector, env.subterm(env.current) , childIndex, child);
end;
procedure upLocal(env: in out Environment) is
begin
env.current := env.current - 1;
end;
procedure down(env: in out Environment; n: Integer) is
child : ObjectPtr := null;
begin
--put_line("before down: " & toString(env));
if n > 0 then
child := env.subterm(env.current);
env.current := env.current + 1;
if env.current = env.omega'length then
ensureLength(env, env.current + 1);
end if;
env.omega(env.current) := n;
env.subterm(env.current) := getChildAt(env.introspector, child, n-1);
end if;
--put_line("after down: " & toString(env));
end;
--private
procedure genericFollowPath(env: in out Environment; p: Path'Class; local: Boolean) is
normalizerdPathArray : IntArrayPtr := toIntArray( getCanonicalPath( p ) );
len : Integer := normalizerdPathArray'Length;
begin
for i in normalizerdPathArray'Range loop
if normalizerdPathArray(i) > 0 then
down(env, normalizerdPathArray(i));
if env.subterm(env.current).all in Position'Class and then i+1 < normalizerdPathArray'Last then
genericFollowPath(env, Position(env.subterm(env.current).all), local);
end if;
elsif local then
upLocal(env);
else
up(env);
end if;
end loop;
end;
procedure followPath(env: in out Environment; p: Path'Class) is
begin
genericFollowPath(env, p, false);
end;
procedure followPathLocal(env: in out Environment; p: Path'Class) is
begin
genericFollowPath(env, p, true);
end;
procedure goToPosition(env: in out Environment; p: Position) is
begin
followPath(env, PositionPackage.sub(p, getPosition(env)));
end;
overriding
function toString(env: Environment) return String is
str : access String := new String'("[");
begin
for i in 0..env.current loop
str := new String'(str.all & Integer'Image( env.omega(i) ) );
if i < env.current then
str := new String'(str.all & "," );
end if;
end loop;
str := new String'(str.all & "]" & LF & "[");
for i in 0..env.current loop
if env.subterm(i) = null then
str := new String'(str.all & "null" );
else
str := new String'(str.all & ObjectPack.toString( env.subterm(i).all ) );
end if;
if i < env.current then
str := new String'(str.all & "," );
end if;
end loop;
str := new String'(str.all & "]");
return str.all;
end;
end EnvironmentPackage;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . S O F T _ L I N K S --
-- --
-- B o d y --
-- --
-- $Revision$
-- --
-- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
pragma Polling (Off);
-- We must turn polling off for this unit, because otherwise we get
-- an infinite loop from the code within the Poll routine itself.
with System.Machine_State_Operations; use System.Machine_State_Operations;
-- Used for Create_TSD, Destroy_TSD
with System.Parameters;
-- Used for Sec_Stack_Ratio
with System.Secondary_Stack;
package body System.Soft_Links is
package SST renames System.Secondary_Stack;
-- Allocate an exception stack for the main program to use.
-- We make sure that the stack has maximum alignment. Some systems require
-- this (e.g. Sun), and in any case it is a good idea for efficiency.
NT_Exc_Stack : array (0 .. 8192) of aliased Character;
for NT_Exc_Stack'Alignment use Standard'Maximum_Alignment;
NT_TSD : TSD;
--------------------
-- Abort_Defer_NT --
--------------------
procedure Abort_Defer_NT is
begin
null;
end Abort_Defer_NT;
----------------------
-- Abort_Handler_NT --
----------------------
procedure Abort_Handler_NT is
begin
null;
end Abort_Handler_NT;
----------------------
-- Abort_Undefer_NT --
----------------------
procedure Abort_Undefer_NT is
begin
null;
end Abort_Undefer_NT;
---------------------------
-- Check_Abort_Status_NT --
---------------------------
function Check_Abort_Status_NT return Integer is
begin
return Boolean'Pos (False);
end Check_Abort_Status_NT;
------------------------
-- Complete_Master_NT --
------------------------
procedure Complete_Master_NT is
begin
null;
end Complete_Master_NT;
----------------
-- Create_TSD --
----------------
procedure Create_TSD (New_TSD : in out TSD) is
use type Parameters.Size_Type;
SS_Ratio_Dynamic : constant Boolean :=
Parameters.Sec_Stack_Ratio = Parameters.Dynamic;
begin
if SS_Ratio_Dynamic then
SST.SS_Init
(New_TSD.Sec_Stack_Addr, SST.Default_Secondary_Stack_Size);
end if;
New_TSD.Machine_State_Addr :=
System.Address
(System.Machine_State_Operations.Allocate_Machine_State);
end Create_TSD;
-----------------------
-- Current_Master_NT --
-----------------------
function Current_Master_NT return Integer is
begin
return 0;
end Current_Master_NT;
-----------------
-- Destroy_TSD --
-----------------
procedure Destroy_TSD (Old_TSD : in out TSD) is
begin
SST.SS_Free (Old_TSD.Sec_Stack_Addr);
System.Machine_State_Operations.Free_Machine_State
(Machine_State (Old_TSD.Machine_State_Addr));
end Destroy_TSD;
---------------------
-- Enter_Master_NT --
---------------------
procedure Enter_Master_NT is
begin
null;
end Enter_Master_NT;
--------------------------
-- Get_Current_Excep_NT --
--------------------------
function Get_Current_Excep_NT return EOA is
begin
return NT_TSD.Current_Excep'Access;
end Get_Current_Excep_NT;
---------------------------
-- Get_Exc_Stack_Addr_NT --
---------------------------
function Get_Exc_Stack_Addr_NT return Address is
begin
return NT_TSD.Exc_Stack_Addr;
end Get_Exc_Stack_Addr_NT;
-----------------------------
-- Get_Exc_Stack_Addr_Soft --
-----------------------------
function Get_Exc_Stack_Addr_Soft return Address is
begin
return Get_Exc_Stack_Addr.all;
end Get_Exc_Stack_Addr_Soft;
------------------------
-- Get_GNAT_Exception --
------------------------
function Get_GNAT_Exception return Ada.Exceptions.Exception_Id is
begin
return Ada.Exceptions.Exception_Identity (Get_Current_Excep.all.all);
end Get_GNAT_Exception;
---------------------------
-- Get_Jmpbuf_Address_NT --
---------------------------
function Get_Jmpbuf_Address_NT return Address is
begin
return NT_TSD.Jmpbuf_Address;
end Get_Jmpbuf_Address_NT;
-----------------------------
-- Get_Jmpbuf_Address_Soft --
-----------------------------
function Get_Jmpbuf_Address_Soft return Address is
begin
return Get_Jmpbuf_Address.all;
end Get_Jmpbuf_Address_Soft;
-------------------------------
-- Get_Machine_State_Addr_NT --
-------------------------------
function Get_Machine_State_Addr_NT return Address is
begin
return NT_TSD.Machine_State_Addr;
end Get_Machine_State_Addr_NT;
---------------------------------
-- Get_Machine_State_Addr_Soft --
---------------------------------
function Get_Machine_State_Addr_Soft return Address is
begin
return Get_Machine_State_Addr.all;
end Get_Machine_State_Addr_Soft;
---------------------------
-- Get_Sec_Stack_Addr_NT --
---------------------------
function Get_Sec_Stack_Addr_NT return Address is
begin
return NT_TSD.Sec_Stack_Addr;
end Get_Sec_Stack_Addr_NT;
-----------------------------
-- Get_Sec_Stack_Addr_Soft --
-----------------------------
function Get_Sec_Stack_Addr_Soft return Address is
begin
return Get_Sec_Stack_Addr.all;
end Get_Sec_Stack_Addr_Soft;
-----------------------
-- Get_Stack_Info_NT --
-----------------------
function Get_Stack_Info_NT return Stack_Checking.Stack_Access is
begin
return NT_TSD.Pri_Stack_Info'Access;
end Get_Stack_Info_NT;
-------------------
-- Null_Adafinal --
-------------------
procedure Null_Adafinal is
begin
null;
end Null_Adafinal;
---------------------------
-- Set_Exc_Stack_Addr_NT --
---------------------------
procedure Set_Exc_Stack_Addr_NT (Self_ID : Address; Addr : Address) is
begin
NT_TSD.Exc_Stack_Addr := Addr;
end Set_Exc_Stack_Addr_NT;
-----------------------------
-- Set_Exc_Stack_Addr_Soft --
-----------------------------
procedure Set_Exc_Stack_Addr_Soft (Self_ID : Address; Addr : Address) is
begin
Set_Exc_Stack_Addr (Self_ID, Addr);
end Set_Exc_Stack_Addr_Soft;
---------------------------
-- Set_Jmpbuf_Address_NT --
---------------------------
procedure Set_Jmpbuf_Address_NT (Addr : Address) is
begin
NT_TSD.Jmpbuf_Address := Addr;
end Set_Jmpbuf_Address_NT;
procedure Set_Jmpbuf_Address_Soft (Addr : Address) is
begin
Set_Jmpbuf_Address (Addr);
end Set_Jmpbuf_Address_Soft;
-------------------------------
-- Set_Machine_State_Addr_NT --
-------------------------------
procedure Set_Machine_State_Addr_NT (Addr : Address) is
begin
NT_TSD.Machine_State_Addr := Addr;
end Set_Machine_State_Addr_NT;
---------------------------------
-- Set_Machine_State_Addr_Soft --
---------------------------------
procedure Set_Machine_State_Addr_Soft (Addr : Address) is
begin
Set_Machine_State_Addr (Addr);
end Set_Machine_State_Addr_Soft;
---------------------------
-- Set_Sec_Stack_Addr_NT --
---------------------------
procedure Set_Sec_Stack_Addr_NT (Addr : Address) is
begin
NT_TSD.Sec_Stack_Addr := Addr;
end Set_Sec_Stack_Addr_NT;
-----------------------------
-- Set_Sec_Stack_Addr_Soft --
-----------------------------
procedure Set_Sec_Stack_Addr_Soft (Addr : Address) is
begin
Set_Sec_Stack_Addr (Addr);
end Set_Sec_Stack_Addr_Soft;
------------------
-- Task_Lock_NT --
------------------
procedure Task_Lock_NT is
begin
null;
end Task_Lock_NT;
--------------------
-- Task_Unlock_NT --
--------------------
procedure Task_Unlock_NT is
begin
null;
end Task_Unlock_NT;
-------------------------
-- Update_Exception_NT --
-------------------------
procedure Update_Exception_NT (X : EO := Current_Target_Exception) is
begin
Ada.Exceptions.Save_Occurrence (NT_TSD.Current_Excep, X);
end Update_Exception_NT;
-------------------------
-- Package Elaboration --
-------------------------
begin
NT_TSD.Exc_Stack_Addr := NT_Exc_Stack (8192)'Address;
Ada.Exceptions.Save_Occurrence
(NT_TSD.Current_Excep, Ada.Exceptions.Null_Occurrence);
end System.Soft_Links;
|
with AUnit.Assertions; use AUnit.Assertions;
package body Missing.AUnit.Assertions is
procedure Generic_Assert
(Actual, Expected : Element_T; Message : String;
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line)
is
begin
Assert
(Condition => Actual = Expected,
Message =>
Message & ASCII.LF & "Actual : " & Element_T'Image (Actual) &
ASCII.LF & "Expected : " & Element_T'Image (Expected),
Source => Source, Line => Line);
end Generic_Assert;
end Missing.AUnit.Assertions;
|
-- SPDX-FileCopyrightText: 2020 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
----------------------------------------------------------------
with League.Strings;
with Markdown.Blocks;
limited with Markdown.Visitors;
package Markdown.Lists is
type List is new Markdown.Blocks.Container_Block with private;
function Is_Loose (Self : List'Class) return Boolean;
-- A list is loose if any of its constituent list items are separated by
-- blank lines, or if any of its constituent list items directly contain
-- two block-level elements with a blank line between them.
function Is_Ordered (Self : List'Class) return Boolean;
-- Return True if list item has an ordered list marker.
function Start (Self : List'Class) return Natural
with Pre => Self.Is_Ordered;
-- Start number of the first list item in case of ordered list
function Match
(Self : List'Class;
Marker : League.Strings.Universal_String) return Boolean;
private
type List is new Markdown.Blocks.Container_Block with record
Is_Loose : Boolean := False;
Ends_Blank : Boolean := False;
Is_Ordered : Boolean := False;
Start : Natural := 1;
Marker : League.Strings.Universal_String;
end record;
overriding function Create
(Line : not null access Markdown.Blocks.Text_Line) return List;
overriding procedure Append_Child
(Self : in out List;
Child : not null Markdown.Blocks.Block_Access);
overriding procedure Visit
(Self : in out List;
Visitor : in out Markdown.Visitors.Visitor'Class);
overriding procedure Consume_Continuation_Markers
(Self : in out List;
Line : in out Markdown.Blocks.Text_Line;
Match : out Boolean) is null;
end Markdown.Lists;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure Euler10 Is
function Sum_Prime_Under(N: Integer) return Long_Long_Integer is
Is_Prime : array (2 .. N - 1) of Boolean := (others => True);
Sum : Long_Long_Integer := 0;
begin
for I in Is_Prime'Range loop
if Is_Prime(I) then
Sum := Sum + Long_Long_Integer(I);
declare
J : Integer := I * 2;
begin
while J <= Is_Prime'Last loop
Is_Prime(J) := False;
J := J + I;
end loop;
end;
end if;
end loop;
return Sum;
end;
begin
Put_Line(Long_Long_Integer'Image(Sum_Prime_Under(2_000_000)));
end;
|
with Ada.Text_IO;
with Ada.Characters.Handling;
with Simple_Logging;
with CLIC.TTY;
package body CLIC.User_Input is
package TIO renames Ada.Text_IO;
package Char renames Ada.Characters.Handling;
User_Input_Error : exception;
Answer_Char : constant array (Answer_Kind) of Character :=
(Yes => 'Y',
No => 'N',
Always => 'A');
-----------------
-- Answer_Kind --
-----------------
function Answer_String (Kind : Answer_Kind) return String
is (case Kind is
when Yes => "yes",
when No => "no",
when Always => "always");
---------------
-- Flush_TTY --
---------------
procedure Flush_TTY is
C : Character;
Available : Boolean;
begin
loop
TIO.Get_Immediate (C, Available);
exit when not Available;
end loop;
exception
when TIO.End_Error => null;
end Flush_TTY;
-------------------------
-- Print_Valid_Answers --
-------------------------
procedure Print_Valid_Answers (Valid : Answer_Set; Default : Answer_Kind) is
begin
for Kind in Answer_Kind loop
if Valid (Kind) then
TIO.Put ("["
& (if Kind = Default
then TTY.Bold ("" & Answer_Char (Kind))
else "" & Answer_Char (Kind))
& "] " & Img (Kind) & " ");
end if;
end loop;
TIO.Put ("(default is " & TTY.Bold (Img (Default)) & ") ");
end Print_Valid_Answers;
-----------
-- Query --
-----------
function Query (Question : String;
Valid : Answer_Set;
Default : Answer_Kind)
return Answer_Kind
is
-----------------
-- Use_Default --
-----------------
function Use_Default return Answer_Kind is
begin
TIO.Put_Line ("Using default: " & Img (Default));
return Default;
end Use_Default;
begin
loop
TIO.Put_Line (Question);
if Not_Interactive or else not TTY.Is_TTY then
return Use_Default;
end if;
-- Flush the input that the user may have entered by mistake before
-- the question is asked.
Flush_TTY;
Print_Valid_Answers (Valid, Default);
-- Get user input
declare
Input : constant String := TIO.Get_Line;
begin
-- Empty line means the user pressed enter without any answer
if Input'Length = 0 then
return Use_Default;
end if;
if Input'Length = 1 then
for Kind in Answer_Kind loop
if Valid (Kind)
and then
Char.To_Upper (Input (Input'First)) = Answer_Char (Kind)
then
-- We got a valid answer
return Kind;
end if;
end loop;
end if;
--- Check if the user input the whole answer
for Kind in Answer_Kind loop
if Valid (Kind)
and then
Char.To_Lower (Input) = Answer_String (Kind)
then
return Kind;
end if;
end loop;
TIO.Put_Line ("Invalid answer.");
end;
end loop;
exception
when TIO.End_Error =>
-- This happens on the user hitting Ctrl-D, and no further
-- input can be obtained as stdin is closed
raise User_Interrupt;
end Query;
-----------------
-- Query_Multi --
-----------------
function Query_Multi (Question : String;
Choices : AAA.Strings.Vector;
Page_Size : Positive := 10)
return Positive
is
Answers : constant array (Positive range <>) of Character :=
('1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z');
pragma Assert (Answers'First = Positive'First);
Use_Pager : constant Boolean := Natural (Choices.Length) > Page_Size;
Page_Start : Positive := 1;
Page_End : Positive;
-- Points always to the last valid choice; there can be an extra choice
-- if Use_Pager, to move forward the list.
-------------------
-- Print_Choices --
-------------------
procedure Print_Choices is
begin
Page_End := Positive'Min (Choices.Last_Index,
Page_Start + Page_Size - 1);
-- Print the choices proper
for I in Page_Start .. Page_End loop
TIO.Put_Line
(" "
& (if I = Page_Start
then TTY.Bold ("" & Answers (I - Page_Start + 1))
else TTY.Emph ("" & Answers (I - Page_Start + 1)))
& ". " & Choices (I));
end loop;
-- And the pager if needed
if Use_Pager then
TIO.Put_Line (TTY.Emph (" " & Answers (Page_End - Page_Start + 2))
& ". (See more choices...)");
end if;
end Print_Choices;
begin
loop
begin
TIO.Put_Line (Question);
if Not_Interactive then
Simple_Logging.Info
("Using default choice in non-interactive mode: "
& Choices.First_Element);
Simple_Logging.Warning (TTY.Is_TTY'Image);
return Choices.First_Index;
end if;
-- Flush the input that the user may have entered by mistake
-- before the question is asked.
Flush_TTY;
Print_Choices;
TIO.Put_Line ("Enter your choice index (first is default): ");
TIO.Put ("> ");
declare
Answer_Line : constant String := TIO.Get_Line;
Answer_Char : Character;
Answer_Pos : Natural := 0;
Extra : constant Natural := (if Use_Pager then 1 else 0);
-- We have an extra entry in the list in this case
begin
if Answer_Line = "" then
return Page_Start;
elsif Answer_Line'Length > 1 then
raise User_Input_Error with "answer too long";
end if;
Answer_Char := Answer_Line (Answer_Line'First);
-- Find the user's choice, and correct it with the actual page
-- we are showing to them.
for I in Answers'Range loop
if Answer_Char = Answers (I) then
Answer_Pos := I;
end if;
end loop;
if Answer_Pos = 0 then
raise User_Input_Error with "Choice out of range";
end if;
Answer_Pos := Answer_Pos + Page_Start - 1;
if Answer_Pos not in Page_Start .. Page_End + Extra
then
raise User_Input_Error with "Choice out of range";
end if;
-- We have a valid choice; either change pages or return choice
if Answer_Pos = Page_End + 1 then
Page_Start := Page_Start + Page_Size;
if Page_Start > Choices.Last_Index then
Page_Start := Choices.First_Index;
end if;
else
return Answer_Pos;
end if;
end;
exception
when TIO.End_Error =>
-- This happens on the user hitting Ctrl-D, and no further
-- input can be obtained as stdin is closed
raise User_Interrupt;
when others =>
Simple_Logging.Info
(TTY.Error ("✗ ") &
"Not a valid choice, please use a line index.");
end;
end loop;
end Query_Multi;
---------
-- Img --
---------
function Img (Kind : Answer_Kind) return String
is (case Kind is
when Yes => "Yes",
when No => "No",
when Always => "Always");
------------------
-- Query_String --
------------------
function Query_String (Question : String;
Default : String;
Validation : String_Validation_Access)
return String
is
-----------------
-- Use_Default --
-----------------
function Use_Default return String is
begin
TIO.Put_Line ("Using default: '" & Default & "'");
return Default;
end Use_Default;
--------------
-- Is_Valid --
--------------
function Is_Valid (Str : String) return Boolean
is (Validation = null or else Validation (Str));
begin
loop
TIO.Put_Line (Question & " (" & "default: '" & Default & "')");
if Not_Interactive or else not TTY.Is_TTY then
return Use_Default;
end if;
-- Print a prompt
TIO.Put ("> ");
-- Flush the input that the user may have entered by mistake before
-- the question is asked.
Flush_TTY;
-- Get user input
declare
Input : constant String := TIO.Get_Line;
begin
-- Empty line means the user pressed enter without any answer
if Input'Length = 0 and then Is_Valid (Default) then
return Use_Default;
end if;
if Is_Valid (Input) then
-- We got a valid answer
return Input;
end if;
TIO.Put_Line ("Invalid answer.");
end;
end loop;
exception
when TIO.End_Error =>
-- This happens on the user hitting Ctrl-D, and no further
-- input can be obtained as stdin is closed
raise User_Interrupt;
end Query_String;
-----------------------
-- Continue_Or_Abort --
-----------------------
procedure Continue_Or_Abort is
Foo : String := "bar";
Bar : Integer;
begin
if Not_Interactive then
Simple_Logging.Detail ("Non-interactive session, continuing");
else
Flush_TTY;
TIO.Put_Line ("Press Enter to continue or Ctrl-C to abort");
TIO.Get_Line (Foo, Bar);
end if;
end Continue_Or_Abort;
---------------------
-- Validated_Input --
---------------------
function Validated_Input
(Question : String;
Prompt : String;
Valid : Answer_Set;
Default : access function (User_Input : String) return Answer_Kind;
Confirm : String := "Is this information correct?";
Is_Valid : access function (User_Input : String) return Boolean)
return Answer_With_Input
is
begin
TIO.Put_Line (Question);
loop
TIO.Put (Prompt);
declare
Input : constant String := TIO.Get_Line;
begin
if Is_Valid (Input) then
declare
Result : Answer_With_Input := (Input'Length, Input, No);
begin
Result.Answer := Query (Confirm, Valid, Default (Input));
if Result.Answer /= No then
return Result;
end if;
end;
end if;
end;
end loop;
end Validated_Input;
end CLIC.User_Input;
|
-- { dg-do compile }
-- { dg-options "-O -gnatn -Winline" }
with Inline2_Pkg; use Inline2_Pkg;
procedure Inline2 is
F : Float := Invalid_Real;
begin
if Valid_Real (F) then
F := F + 1.0;
end if;
end;
|
with Ada.Text_IO;
use Ada;
procedure point_test is
type Point is record
x, y, z : float;
end record;
location : Point;
begin
location := (x=>1.0, y=>1.0, z=>0.0);
end point_test;
|
PROCEDURE Tax IS
SUBTYPE NonNegFloat IS Float RANGE 0.0 .. Float'Last;
Tot_Tax : NonNegFloat;
Taxable_Income : Float;
BEGIN
Float (Tot_Tax) := Taxable_Income;
END TAX;
|
with Terminal_Interface.Curses; use Terminal_Interface.Curses;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
With Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
with Ada.Text_IO;
with Ada.Directories;
use Ada.Text_IO;
use Ada.Directories;
with Ada.Calendar; use Ada.Calendar;
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Strings.Maps.Constants;
with Ada.Strings.Fixed;
with Texaco;
with Display_Warning;
with Ada.IO_Exceptions;
Package Message.Login is
package SU renames Ada.Strings.Unbounded;
package SUIO renames Ada.Text_IO.Unbounded_IO;
procedure Create_User;
procedure Login_User;
end Message.Login;
|
-- { dg-do compile }
-- { dg-options "-g" }
with Taft_Type2_Pkg; use Taft_Type2_Pkg;
package body Taft_Type2 is
procedure Proc is
A : T;
function F return T is
My_T : T;
begin
My_T := Open;
return My_T;
end;
begin
A := F;
end;
end Taft_Type2;
|
-- Copyright (c) 2015-2017 Maxim Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with League.Strings;
package Incr.Lexers.Batch_Lexers is
-- @summary
-- Batch Lexer
--
-- @description
-- This package provides batch lexical analyser and related types.
type Batch_Lexer is abstract tagged limited private;
-- Type to perform lexical analysis
type Batch_Lexer_Access is access all Batch_Lexer'Class;
type Abstract_Source is abstract tagged limited null record;
-- Abstract source of text for lexer
type Source_Access is access all Abstract_Source'Class;
not overriding function Get_Next
(Self : not null access Abstract_Source)
return Wide_Wide_Character is abstract;
-- Retrive next character of text. Return End_Of_Input when no more data
-- available.
End_Of_Input : constant Wide_Wide_Character := Wide_Wide_Character'Val (4);
-- Special character to represend end of input stream
procedure Set_Source
(Self : in out Batch_Lexer'Class;
Source : not null Source_Access);
-- Configure new text source before perform a lexical analysis.
type State is new Natural;
-- State of lexer automaton
INITIAL : constant State := 0;
-- Initial state of lexer, valid to start analysis from very begining
procedure Set_Start_Condition
(Self : in out Batch_Lexer'Class; Condition : State);
-- Assign new state.
function Get_Start_Condition
(Self : Batch_Lexer'Class) return State;
-- Return current lexer state.
type Rule_Index is new Natural;
-- Recognized token rule, 0 for end of stream or error.
not overriding procedure Get_Token
(Self : access Batch_Lexer;
Result : out Rule_Index) is abstract;
-- Recognize next token in the stream and return its rule number.
function Get_Text
(Self : Batch_Lexer'Class) return League.Strings.Universal_String;
-- Return text of last recognized token.
function Get_Token_Length (Self : Batch_Lexer'Class) return Positive;
-- Return length of text of last recognized token.
function Get_Token_Lookahead (Self : Batch_Lexer'Class) return Positive;
-- Return number of character seen by lexer after end of the last
-- recognized token.
type Character_Class is new Natural;
private
Buffer_Size : constant := 1024;
-- Max length of any token
subtype Buffer_Index is Positive range 1 .. Buffer_Size;
type Character_Class_Array is array (Buffer_Index) of Character_Class;
Error_Character : constant Character_Class := 0;
type Batch_Lexer is abstract tagged limited record
Source : Source_Access;
Start : State := INITIAL;
Next : Buffer_Index := 1; -- First empty position in Buffer
To : Natural := 0; -- Last char of the last read token
Rule : Rule_Index; -- Rule of the last read token
Buffer : Wide_Wide_String (Buffer_Index);
Classes : Character_Class_Array;
end record;
end Incr.Lexers.Batch_Lexers;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../../License.txt
private
with Ada.Finalization;
package AdaBase.Statement is
pragma Pure;
type Base_Pure is abstract tagged private;
private
package FIN renames Ada.Finalization;
type Base_Pure is abstract new FIN.Controlled with
record
null;
end record;
end AdaBase.Statement;
|
package Constrained_Array_Definition is
type Array_Type_1 is array (Natural range 1..10) of Integer;
type Array_Type_2 is array (1..10) of Integer;
end Constrained_Array_Definition;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with AMF.Internals.UML_Named_Elements;
with AMF.String_Collections;
with AMF.UML.Activities;
with AMF.UML.Activity_Edges.Collections;
with AMF.UML.Activity_Groups.Collections;
with AMF.UML.Activity_Nodes.Collections;
with AMF.UML.Activity_Partitions.Collections;
with AMF.UML.Classifiers.Collections;
with AMF.UML.Clauses.Collections;
with AMF.UML.Conditional_Nodes;
with AMF.UML.Constraints.Collections;
with AMF.UML.Dependencies.Collections;
with AMF.UML.Element_Imports.Collections;
with AMF.UML.Exception_Handlers.Collections;
with AMF.UML.Input_Pins.Collections;
with AMF.UML.Interruptible_Activity_Regions.Collections;
with AMF.UML.Named_Elements.Collections;
with AMF.UML.Namespaces;
with AMF.UML.Output_Pins.Collections;
with AMF.UML.Package_Imports.Collections;
with AMF.UML.Packageable_Elements.Collections;
with AMF.UML.Packages.Collections;
with AMF.UML.Redefinable_Elements.Collections;
with AMF.UML.String_Expressions;
with AMF.UML.Structured_Activity_Nodes;
with AMF.UML.Variables.Collections;
with AMF.Visitors;
package AMF.Internals.UML_Conditional_Nodes is
type UML_Conditional_Node_Proxy is
limited new AMF.Internals.UML_Named_Elements.UML_Named_Element_Proxy
and AMF.UML.Conditional_Nodes.UML_Conditional_Node with null record;
overriding function Get_Clause
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Clauses.Collections.Set_Of_UML_Clause;
-- Getter of ConditionalNode::clause.
--
-- Set of clauses composing the conditional.
overriding function Get_Is_Assured
(Self : not null access constant UML_Conditional_Node_Proxy)
return Boolean;
-- Getter of ConditionalNode::isAssured.
--
-- If true, the modeler asserts that at least one test will succeed.
overriding procedure Set_Is_Assured
(Self : not null access UML_Conditional_Node_Proxy;
To : Boolean);
-- Setter of ConditionalNode::isAssured.
--
-- If true, the modeler asserts that at least one test will succeed.
overriding function Get_Is_Determinate
(Self : not null access constant UML_Conditional_Node_Proxy)
return Boolean;
-- Getter of ConditionalNode::isDeterminate.
--
-- If true, the modeler asserts that at most one test will succeed.
overriding procedure Set_Is_Determinate
(Self : not null access UML_Conditional_Node_Proxy;
To : Boolean);
-- Setter of ConditionalNode::isDeterminate.
--
-- If true, the modeler asserts that at most one test will succeed.
overriding function Get_Result
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Output_Pins.Collections.Ordered_Set_Of_UML_Output_Pin;
-- Getter of ConditionalNode::result.
--
-- A list of output pins that constitute the data flow outputs of the
-- conditional.
overriding function Get_Activity
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Activities.UML_Activity_Access;
-- Getter of StructuredActivityNode::activity.
--
-- Activity immediately containing the node.
overriding procedure Set_Activity
(Self : not null access UML_Conditional_Node_Proxy;
To : AMF.UML.Activities.UML_Activity_Access);
-- Setter of StructuredActivityNode::activity.
--
-- Activity immediately containing the node.
overriding function Get_Edge
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Activity_Edges.Collections.Set_Of_UML_Activity_Edge;
-- Getter of StructuredActivityNode::edge.
--
-- Edges immediately contained in the structured node.
overriding function Get_Must_Isolate
(Self : not null access constant UML_Conditional_Node_Proxy)
return Boolean;
-- Getter of StructuredActivityNode::mustIsolate.
--
-- If true, then the actions in the node execute in isolation from actions
-- outside the node.
overriding procedure Set_Must_Isolate
(Self : not null access UML_Conditional_Node_Proxy;
To : Boolean);
-- Setter of StructuredActivityNode::mustIsolate.
--
-- If true, then the actions in the node execute in isolation from actions
-- outside the node.
overriding function Get_Node
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Activity_Nodes.Collections.Set_Of_UML_Activity_Node;
-- Getter of StructuredActivityNode::node.
--
-- Nodes immediately contained in the group.
overriding function Get_Structured_Node_Input
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Input_Pins.Collections.Set_Of_UML_Input_Pin;
-- Getter of StructuredActivityNode::structuredNodeInput.
--
overriding function Get_Structured_Node_Output
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Output_Pins.Collections.Set_Of_UML_Output_Pin;
-- Getter of StructuredActivityNode::structuredNodeOutput.
--
overriding function Get_Variable
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Variables.Collections.Set_Of_UML_Variable;
-- Getter of StructuredActivityNode::variable.
--
-- A variable defined in the scope of the structured activity node. It has
-- no value and may not be accessed
overriding function Get_Element_Import
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Element_Imports.Collections.Set_Of_UML_Element_Import;
-- Getter of Namespace::elementImport.
--
-- References the ElementImports owned by the Namespace.
overriding function Get_Imported_Member
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Packageable_Elements.Collections.Set_Of_UML_Packageable_Element;
-- Getter of Namespace::importedMember.
--
-- References the PackageableElements that are members of this Namespace
-- as a result of either PackageImports or ElementImports.
overriding function Get_Member
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element;
-- Getter of Namespace::member.
--
-- A collection of NamedElements identifiable within the Namespace, either
-- by being owned or by being introduced by importing or inheritance.
overriding function Get_Owned_Member
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element;
-- Getter of Namespace::ownedMember.
--
-- A collection of NamedElements owned by the Namespace.
overriding function Get_Owned_Rule
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Constraints.Collections.Set_Of_UML_Constraint;
-- Getter of Namespace::ownedRule.
--
-- Specifies a set of Constraints owned by this Namespace.
overriding function Get_Package_Import
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Package_Imports.Collections.Set_Of_UML_Package_Import;
-- Getter of Namespace::packageImport.
--
-- References the PackageImports owned by the Namespace.
overriding function Get_Client_Dependency
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Dependencies.Collections.Set_Of_UML_Dependency;
-- Getter of NamedElement::clientDependency.
--
-- Indicates the dependencies that reference the client.
overriding function Get_Name_Expression
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.String_Expressions.UML_String_Expression_Access;
-- Getter of NamedElement::nameExpression.
--
-- The string expression used to define the name of this named element.
overriding procedure Set_Name_Expression
(Self : not null access UML_Conditional_Node_Proxy;
To : AMF.UML.String_Expressions.UML_String_Expression_Access);
-- Setter of NamedElement::nameExpression.
--
-- The string expression used to define the name of this named element.
overriding function Get_Namespace
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Namespaces.UML_Namespace_Access;
-- Getter of NamedElement::namespace.
--
-- Specifies the namespace that owns the NamedElement.
overriding function Get_Qualified_Name
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.Optional_String;
-- Getter of NamedElement::qualifiedName.
--
-- A name which allows the NamedElement to be identified within a
-- hierarchy of nested Namespaces. It is constructed from the names of the
-- containing namespaces starting at the root of the hierarchy and ending
-- with the name of the NamedElement itself.
overriding function Get_Contained_Edge
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Activity_Edges.Collections.Set_Of_UML_Activity_Edge;
-- Getter of ActivityGroup::containedEdge.
--
-- Edges immediately contained in the group.
overriding function Get_Contained_Node
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Activity_Nodes.Collections.Set_Of_UML_Activity_Node;
-- Getter of ActivityGroup::containedNode.
--
-- Nodes immediately contained in the group.
overriding function Get_In_Activity
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Activities.UML_Activity_Access;
-- Getter of ActivityGroup::inActivity.
--
-- Activity containing the group.
overriding procedure Set_In_Activity
(Self : not null access UML_Conditional_Node_Proxy;
To : AMF.UML.Activities.UML_Activity_Access);
-- Setter of ActivityGroup::inActivity.
--
-- Activity containing the group.
overriding function Get_Subgroup
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Activity_Groups.Collections.Set_Of_UML_Activity_Group;
-- Getter of ActivityGroup::subgroup.
--
-- Groups immediately contained in the group.
overriding function Get_Super_Group
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Activity_Groups.UML_Activity_Group_Access;
-- Getter of ActivityGroup::superGroup.
--
-- Group immediately containing the group.
overriding function Get_Context
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Classifiers.UML_Classifier_Access;
-- Getter of Action::context.
--
-- The classifier that owns the behavior of which this action is a part.
overriding function Get_Input
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Input_Pins.Collections.Ordered_Set_Of_UML_Input_Pin;
-- Getter of Action::input.
--
-- The ordered set of input pins connected to the Action. These are among
-- the total set of inputs.
overriding function Get_Is_Locally_Reentrant
(Self : not null access constant UML_Conditional_Node_Proxy)
return Boolean;
-- Getter of Action::isLocallyReentrant.
--
-- If true, the action can begin a new, concurrent execution, even if
-- there is already another execution of the action ongoing. If false, the
-- action cannot begin a new execution until any previous execution has
-- completed.
overriding procedure Set_Is_Locally_Reentrant
(Self : not null access UML_Conditional_Node_Proxy;
To : Boolean);
-- Setter of Action::isLocallyReentrant.
--
-- If true, the action can begin a new, concurrent execution, even if
-- there is already another execution of the action ongoing. If false, the
-- action cannot begin a new execution until any previous execution has
-- completed.
overriding function Get_Local_Postcondition
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Constraints.Collections.Set_Of_UML_Constraint;
-- Getter of Action::localPostcondition.
--
-- Constraint that must be satisfied when executed is completed.
overriding function Get_Local_Precondition
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Constraints.Collections.Set_Of_UML_Constraint;
-- Getter of Action::localPrecondition.
--
-- Constraint that must be satisfied when execution is started.
overriding function Get_Output
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Output_Pins.Collections.Ordered_Set_Of_UML_Output_Pin;
-- Getter of Action::output.
--
-- The ordered set of output pins connected to the Action. The action
-- places its results onto pins in this set.
overriding function Get_Handler
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Exception_Handlers.Collections.Set_Of_UML_Exception_Handler;
-- Getter of ExecutableNode::handler.
--
-- A set of exception handlers that are examined if an uncaught exception
-- propagates to the outer level of the executable node.
overriding function Get_In_Group
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Activity_Groups.Collections.Set_Of_UML_Activity_Group;
-- Getter of ActivityNode::inGroup.
--
-- Groups containing the node.
overriding function Get_In_Interruptible_Region
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Interruptible_Activity_Regions.Collections.Set_Of_UML_Interruptible_Activity_Region;
-- Getter of ActivityNode::inInterruptibleRegion.
--
-- Interruptible regions containing the node.
overriding function Get_In_Partition
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Activity_Partitions.Collections.Set_Of_UML_Activity_Partition;
-- Getter of ActivityNode::inPartition.
--
-- Partitions containing the node.
overriding function Get_In_Structured_Node
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Structured_Activity_Nodes.UML_Structured_Activity_Node_Access;
-- Getter of ActivityNode::inStructuredNode.
--
-- Structured activity node containing the node.
overriding procedure Set_In_Structured_Node
(Self : not null access UML_Conditional_Node_Proxy;
To : AMF.UML.Structured_Activity_Nodes.UML_Structured_Activity_Node_Access);
-- Setter of ActivityNode::inStructuredNode.
--
-- Structured activity node containing the node.
overriding function Get_Incoming
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Activity_Edges.Collections.Set_Of_UML_Activity_Edge;
-- Getter of ActivityNode::incoming.
--
-- Edges that have the node as target.
overriding function Get_Outgoing
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Activity_Edges.Collections.Set_Of_UML_Activity_Edge;
-- Getter of ActivityNode::outgoing.
--
-- Edges that have the node as source.
overriding function Get_Redefined_Node
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Activity_Nodes.Collections.Set_Of_UML_Activity_Node;
-- Getter of ActivityNode::redefinedNode.
--
-- Inherited nodes replaced by this node in a specialization of the
-- activity.
overriding function Get_Is_Leaf
(Self : not null access constant UML_Conditional_Node_Proxy)
return Boolean;
-- Getter of RedefinableElement::isLeaf.
--
-- Indicates whether it is possible to further redefine a
-- RedefinableElement. If the value is true, then it is not possible to
-- further redefine the RedefinableElement. Note that this property is
-- preserved through package merge operations; that is, the capability to
-- redefine a RedefinableElement (i.e., isLeaf=false) must be preserved in
-- the resulting RedefinableElement of a package merge operation where a
-- RedefinableElement with isLeaf=false is merged with a matching
-- RedefinableElement with isLeaf=true: the resulting RedefinableElement
-- will have isLeaf=false. Default value is false.
overriding procedure Set_Is_Leaf
(Self : not null access UML_Conditional_Node_Proxy;
To : Boolean);
-- Setter of RedefinableElement::isLeaf.
--
-- Indicates whether it is possible to further redefine a
-- RedefinableElement. If the value is true, then it is not possible to
-- further redefine the RedefinableElement. Note that this property is
-- preserved through package merge operations; that is, the capability to
-- redefine a RedefinableElement (i.e., isLeaf=false) must be preserved in
-- the resulting RedefinableElement of a package merge operation where a
-- RedefinableElement with isLeaf=false is merged with a matching
-- RedefinableElement with isLeaf=true: the resulting RedefinableElement
-- will have isLeaf=false. Default value is false.
overriding function Get_Redefined_Element
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Redefinable_Elements.Collections.Set_Of_UML_Redefinable_Element;
-- Getter of RedefinableElement::redefinedElement.
--
-- The redefinable element that is being redefined by this element.
overriding function Get_Redefinition_Context
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Classifiers.Collections.Set_Of_UML_Classifier;
-- Getter of RedefinableElement::redefinitionContext.
--
-- References the contexts that this element may be redefined from.
overriding function Exclude_Collisions
(Self : not null access constant UML_Conditional_Node_Proxy;
Imps : AMF.UML.Packageable_Elements.Collections.Set_Of_UML_Packageable_Element)
return AMF.UML.Packageable_Elements.Collections.Set_Of_UML_Packageable_Element;
-- Operation Namespace::excludeCollisions.
--
-- The query excludeCollisions() excludes from a set of
-- PackageableElements any that would not be distinguishable from each
-- other in this namespace.
overriding function Get_Names_Of_Member
(Self : not null access constant UML_Conditional_Node_Proxy;
Element : AMF.UML.Named_Elements.UML_Named_Element_Access)
return AMF.String_Collections.Set_Of_String;
-- Operation Namespace::getNamesOfMember.
--
-- The query getNamesOfMember() takes importing into account. It gives
-- back the set of names that an element would have in an importing
-- namespace, either because it is owned, or if not owned then imported
-- individually, or if not individually then from a package.
-- The query getNamesOfMember() gives a set of all of the names that a
-- member would have in a Namespace. In general a member can have multiple
-- names in a Namespace if it is imported more than once with different
-- aliases. The query takes account of importing. It gives back the set of
-- names that an element would have in an importing namespace, either
-- because it is owned, or if not owned then imported individually, or if
-- not individually then from a package.
overriding function Import_Members
(Self : not null access constant UML_Conditional_Node_Proxy;
Imps : AMF.UML.Packageable_Elements.Collections.Set_Of_UML_Packageable_Element)
return AMF.UML.Packageable_Elements.Collections.Set_Of_UML_Packageable_Element;
-- Operation Namespace::importMembers.
--
-- The query importMembers() defines which of a set of PackageableElements
-- are actually imported into the namespace. This excludes hidden ones,
-- i.e., those which have names that conflict with names of owned members,
-- and also excludes elements which would have the same name when imported.
overriding function Imported_Member
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Packageable_Elements.Collections.Set_Of_UML_Packageable_Element;
-- Operation Namespace::importedMember.
--
-- The importedMember property is derived from the ElementImports and the
-- PackageImports. References the PackageableElements that are members of
-- this Namespace as a result of either PackageImports or ElementImports.
overriding function Members_Are_Distinguishable
(Self : not null access constant UML_Conditional_Node_Proxy)
return Boolean;
-- Operation Namespace::membersAreDistinguishable.
--
-- The Boolean query membersAreDistinguishable() determines whether all of
-- the namespace's members are distinguishable within it.
overriding function Owned_Member
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element;
-- Operation Namespace::ownedMember.
--
-- Missing derivation for Namespace::/ownedMember : NamedElement
overriding function All_Owning_Packages
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Packages.Collections.Set_Of_UML_Package;
-- Operation NamedElement::allOwningPackages.
--
-- The query allOwningPackages() returns all the directly or indirectly
-- owning packages.
overriding function Is_Distinguishable_From
(Self : not null access constant UML_Conditional_Node_Proxy;
N : AMF.UML.Named_Elements.UML_Named_Element_Access;
Ns : AMF.UML.Namespaces.UML_Namespace_Access)
return Boolean;
-- Operation NamedElement::isDistinguishableFrom.
--
-- The query isDistinguishableFrom() determines whether two NamedElements
-- may logically co-exist within a Namespace. By default, two named
-- elements are distinguishable if (a) they have unrelated types or (b)
-- they have related types but different names.
overriding function Namespace
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Namespaces.UML_Namespace_Access;
-- Operation NamedElement::namespace.
--
-- Missing derivation for NamedElement::/namespace : Namespace
overriding function Context
(Self : not null access constant UML_Conditional_Node_Proxy)
return AMF.UML.Classifiers.UML_Classifier_Access;
-- Operation Action::context.
--
-- Missing derivation for Action::/context : Classifier
overriding function Is_Consistent_With
(Self : not null access constant UML_Conditional_Node_Proxy;
Redefinee : AMF.UML.Redefinable_Elements.UML_Redefinable_Element_Access)
return Boolean;
-- Operation RedefinableElement::isConsistentWith.
--
-- The query isConsistentWith() specifies, for any two RedefinableElements
-- in a context in which redefinition is possible, whether redefinition
-- would be logically consistent. By default, this is false; this
-- operation must be overridden for subclasses of RedefinableElement to
-- define the consistency conditions.
overriding function Is_Redefinition_Context_Valid
(Self : not null access constant UML_Conditional_Node_Proxy;
Redefined : AMF.UML.Redefinable_Elements.UML_Redefinable_Element_Access)
return Boolean;
-- Operation RedefinableElement::isRedefinitionContextValid.
--
-- The query isRedefinitionContextValid() specifies whether the
-- redefinition contexts of this RedefinableElement are properly related
-- to the redefinition contexts of the specified RedefinableElement to
-- allow this element to redefine the other. By default at least one of
-- the redefinition contexts of this element must be a specialization of
-- at least one of the redefinition contexts of the specified element.
overriding procedure Enter_Element
(Self : not null access constant UML_Conditional_Node_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
-- Dispatch call to corresponding subprogram of visitor interface.
overriding procedure Leave_Element
(Self : not null access constant UML_Conditional_Node_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
-- Dispatch call to corresponding subprogram of visitor interface.
overriding procedure Visit_Element
(Self : not null access constant UML_Conditional_Node_Proxy;
Iterator : in out AMF.Visitors.Abstract_Iterator'Class;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
-- Dispatch call to corresponding subprogram of iterator interface.
end AMF.Internals.UML_Conditional_Nodes;
|
-- Copyright 2017-2021 Bartek thindil Jasicki
--
-- This file is part of Steam Sky.
--
-- Steam Sky is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- Steam Sky is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with Steam Sky. If not, see <http://www.gnu.org/licenses/>.
with Messages; use Messages;
with Ships.Cargo; use Ships.Cargo;
with Ships.Crew; use Ships.Crew;
with Crafts; use Crafts;
with Trades; use Trades;
with Utils; use Utils;
with Bases.Cargo; use Bases.Cargo;
with Config; use Config;
with BasesTypes; use BasesTypes;
with Maps; use Maps;
package body Bases.Trade is
-- ****if* BTrade/BTrade.CheckMoney
-- FUNCTION
-- Check if player have enough money
-- PARAMETERS
-- Price - Miniumum amount of money which player must have
-- Message - Additional message to return when player don't have enough
-- money
-- RESULT
-- Cargo index of money from the player ship
-- SOURCE
function CheckMoney
(Price: Positive; Message: String := "") return Positive is
-- ****
MoneyIndex2: constant Natural :=
FindItem(Player_Ship.Cargo, Money_Index);
begin
if MoneyIndex2 = 0 then
if Message /= "" then
raise Trade_No_Money with Message;
else
raise Trade_No_Money;
end if;
end if;
if Player_Ship.Cargo(MoneyIndex2).Amount < Price then
if Message /= "" then
raise Trade_Not_Enough_Money with Message;
else
raise Trade_Not_Enough_Money;
end if;
end if;
return MoneyIndex2;
end CheckMoney;
procedure HireRecruit
(RecruitIndex: Recruit_Container.Extended_Index; Cost: Positive;
DailyPayment, TradePayment: Natural; ContractLenght: Integer) is
BaseIndex: constant Bases_Range :=
SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).BaseIndex;
MoneyIndex2: Inventory_Container.Extended_Index;
Price: Natural;
Recruit: constant Recruit_Data :=
Sky_Bases(BaseIndex).Recruits(RecruitIndex);
Morale: Skill_Range;
Inventory: Inventory_Container.Vector;
TraderIndex: constant Crew_Container.Extended_Index := FindMember(Talk);
begin
if TraderIndex = 0 then
raise Trade_No_Trader;
end if;
Price := Cost;
Count_Price(Price, TraderIndex);
MoneyIndex2 := CheckMoney(Price, To_String(Recruit.Name));
Add_Recruit_Inventory_Loop :
for Item of Recruit.Inventory loop
Inventory.Append
(New_Item =>
(ProtoIndex => Item, Amount => 1, Name => Null_Unbounded_String,
Durability => Default_Item_Durability, Price => 0));
end loop Add_Recruit_Inventory_Loop;
if Factions_List(Sky_Bases(BaseIndex).Owner).Flags.Contains
(To_Unbounded_String("nomorale")) then
Morale := 50;
else
Morale :=
(if 50 + Sky_Bases(BaseIndex).Reputation(1) > 100 then 100
else 50 + Sky_Bases(BaseIndex).Reputation(1));
end if;
Player_Ship.Crew.Append
(New_Item =>
(Amount_Of_Attributes => Attributes_Amount,
Amount_Of_Skills => Skills_Amount, Name => Recruit.Name,
Gender => Recruit.Gender, Health => 100, Tired => 0,
Skills => Recruit.Skills, Hunger => 0, Thirst => 0, Order => Rest,
PreviousOrder => Rest, OrderTime => 15, Orders => (others => 0),
Attributes => Recruit.Attributes, Inventory => Inventory,
Equipment => Recruit.Equipment,
Payment => (DailyPayment, TradePayment),
ContractLength => ContractLenght, Morale => (Morale, 0),
Loyalty => Morale, HomeBase => Recruit.Home_Base,
Faction => Recruit.Faction));
UpdateCargo
(Ship => Player_Ship, CargoIndex => MoneyIndex2, Amount => -(Price));
GainExp(1, Talking_Skill, TraderIndex);
Gain_Rep(BaseIndex, 1);
AddMessage
("You hired " & To_String(Recruit.Name) & " for" &
Positive'Image(Price) & " " & To_String(Money_Name) & ".",
TradeMessage);
Sky_Bases(BaseIndex).Recruits.Delete(Index => RecruitIndex);
Sky_Bases(BaseIndex).Population := Sky_Bases(BaseIndex).Population - 1;
Update_Game(5);
end HireRecruit;
procedure BuyRecipe(RecipeIndex: Unbounded_String) is
BaseIndex: constant Bases_Range :=
SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).BaseIndex;
MoneyIndex2: Inventory_Container.Extended_Index;
Cost: Natural;
RecipeName: constant String :=
To_String(Items_List(Recipes_List(RecipeIndex).ResultIndex).Name);
BaseType: constant Unbounded_String := Sky_Bases(BaseIndex).Base_Type;
TraderIndex: constant Crew_Container.Extended_Index := FindMember(Talk);
begin
if not Bases_Types_List(BaseType).Recipes.Contains(RecipeIndex) then
raise Trade_Cant_Buy;
end if;
if Known_Recipes.Find_Index(Item => RecipeIndex) /=
Positive_Container.No_Index then
raise Trade_Already_Known;
end if;
if TraderIndex = 0 then
raise Trade_No_Trader;
end if;
if Get_Price
(Sky_Bases(BaseIndex).Base_Type,
Recipes_List(RecipeIndex).ResultIndex) >
0 then
Cost :=
Get_Price
(Sky_Bases(BaseIndex).Base_Type,
Recipes_List(RecipeIndex).ResultIndex) *
Recipes_List(RecipeIndex).Difficulty * 10;
else
Cost := Recipes_List(RecipeIndex).Difficulty * 10;
end if;
Cost := Natural(Float(Cost) * Float(New_Game_Settings.Prices_Bonus));
if Cost = 0 then
Cost := 1;
end if;
Count_Price(Cost, TraderIndex);
MoneyIndex2 := CheckMoney(Cost, RecipeName);
UpdateCargo
(Ship => Player_Ship, CargoIndex => MoneyIndex2, Amount => -(Cost));
Update_Base_Cargo(Money_Index, Cost);
Known_Recipes.Append(New_Item => RecipeIndex);
AddMessage
("You bought the recipe for " & RecipeName & " for" &
Positive'Image(Cost) & " of " & To_String(Money_Name) & ".",
TradeMessage);
GainExp(1, Talking_Skill, TraderIndex);
Gain_Rep(BaseIndex, 1);
Update_Game(5);
end BuyRecipe;
procedure HealWounded(MemberIndex: Crew_Container.Extended_Index) is
BaseIndex: constant Bases_Range :=
SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).BaseIndex;
MoneyIndex2: Inventory_Container.Extended_Index := 0;
Cost, Time: Natural := 0;
TraderIndex: constant Crew_Container.Extended_Index := FindMember(Talk);
begin
HealCost(Cost, Time, MemberIndex);
if Cost = 0 then
raise Trade_Cant_Heal;
end if;
if TraderIndex = 0 then
raise Trade_No_Trader;
end if;
MoneyIndex2 := CheckMoney(Cost);
if MemberIndex > 0 then
Player_Ship.Crew(MemberIndex).Health := 100;
AddMessage
("You paid for healing " &
To_String(Player_Ship.Crew(MemberIndex).Name) & " for" &
Positive'Image(Cost) & " " & To_String(Money_Name) & ".",
TradeMessage);
GiveOrders(Player_Ship, MemberIndex, Rest, 0, False);
else
Give_Rest_Order_Loop :
for I in Player_Ship.Crew.Iterate loop
if Player_Ship.Crew(I).Health < 100 then
Player_Ship.Crew(I).Health := 100;
GiveOrders
(Player_Ship, Crew_Container.To_Index(I), Rest, 0, False);
end if;
end loop Give_Rest_Order_Loop;
AddMessage
("You paid for healing for all wounded crew members for" &
Positive'Image(Cost) & " " & To_String(Money_Name) & ".",
TradeMessage);
end if;
UpdateCargo
(Ship => Player_Ship, CargoIndex => MoneyIndex2, Amount => -(Cost));
Update_Base_Cargo(Money_Index, Cost);
GainExp(1, Talking_Skill, TraderIndex);
Gain_Rep(BaseIndex, 1);
Update_Game(Time);
end HealWounded;
procedure HealCost
(Cost, Time: in out Natural;
MemberIndex: Crew_Container.Extended_Index) is
BaseIndex: constant Bases_Range :=
SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).BaseIndex;
begin
if MemberIndex > 0 then
Time := 5 * (100 - Player_Ship.Crew(MemberIndex).Health);
Cost :=
(5 * (100 - Player_Ship.Crew(MemberIndex).Health)) *
Get_Price
(To_Unbounded_String("0"),
FindProtoItem
(ItemType =>
Factions_List(Player_Ship.Crew(MemberIndex).Faction)
.HealingTools));
else
Count_Heal_Cost_Loop :
for Member of Player_Ship.Crew loop
if Member.Health < 100 then
Time := Time + (5 * (100 - Member.Health));
Cost :=
Cost +
((5 * (100 - Member.Health)) *
Items_List
(FindProtoItem
(ItemType =>
Factions_List(Member.Faction).HealingTools))
.Price);
end if;
end loop Count_Heal_Cost_Loop;
end if;
Cost := Natural(Float(Cost) * Float(New_Game_Settings.Prices_Bonus));
if Cost = 0 then
Cost := 1;
end if;
Count_Price(Cost, FindMember(Talk));
if Time = 0 then
Time := 1;
end if;
if Bases_Types_List(Sky_Bases(BaseIndex).Base_Type).Flags.Contains
(To_Unbounded_String("temple")) then
Cost := Cost / 2;
if Cost = 0 then
Cost := 1;
end if;
end if;
end HealCost;
function TrainCost
(MemberIndex: Crew_Container.Extended_Index;
SkillIndex: Skills_Container.Extended_Index) return Natural is
Cost: Natural := Natural(100.0 * New_Game_Settings.Prices_Bonus);
begin
Count_Train_Cost_Loop :
for Skill of Player_Ship.Crew(MemberIndex).Skills loop
if Skill.Index = SkillIndex then
if Skill.Level = 100 then
return 0;
end if;
Cost :=
Natural
(Float((Skill.Level + 1) * 100) *
Float(New_Game_Settings.Prices_Bonus));
if Cost = 0 then
Cost := 1;
end if;
exit Count_Train_Cost_Loop;
end if;
end loop Count_Train_Cost_Loop;
Count_Price(Cost, FindMember(Talk));
return Cost;
end TrainCost;
procedure TrainSkill
(MemberIndex: Crew_Container.Extended_Index;
SkillIndex: Skills_Container.Extended_Index; Amount: Positive;
Is_Amount: Boolean := True) is
use Tiny_String;
Cost: Natural;
MoneyIndex2: Inventory_Container.Extended_Index;
GainedExp: Positive;
BaseIndex: constant Bases_Range :=
SkyMap(Player_Ship.Sky_X, Player_Ship.Sky_Y).BaseIndex;
TraderIndex: Crew_Container.Extended_Index;
Sessions, OverallCost: Natural := 0;
MaxAmount: Integer := Amount;
begin
GiveOrders(Player_Ship, MemberIndex, Rest, 0, False);
Train_Skill_Loop :
while MaxAmount > 0 loop
Cost := TrainCost(MemberIndex, SkillIndex);
MoneyIndex2 := FindItem(Player_Ship.Cargo, Money_Index);
exit Train_Skill_Loop when Cost = 0 or
Player_Ship.Cargo(MoneyIndex2).Amount < Cost or
(not Is_Amount and MaxAmount < Cost);
GainedExp :=
Get_Random(10, 60) +
Player_Ship.Crew(MemberIndex).Attributes
(Positive
(SkillsData_Container.Element(Skills_List, SkillIndex)
.Attribute))
.Level;
if GainedExp > 100 then
GainedExp := 100;
end if;
GainExp(GainedExp, SkillIndex, MemberIndex);
UpdateCargo
(Ship => Player_Ship, CargoIndex => MoneyIndex2, Amount => -(Cost));
Update_Base_Cargo(Money_Index, Cost);
TraderIndex := FindMember(Talk);
if TraderIndex > 0 then
GainExp(5, Talking_Skill, TraderIndex);
end if;
Gain_Rep(BaseIndex, 5);
Update_Game(60);
Sessions := Sessions + 1;
OverallCost := OverallCost + Cost;
MaxAmount := MaxAmount - (if Is_Amount then 1 else Cost);
end loop Train_Skill_Loop;
if Sessions > 0 then
AddMessage
("You purchased" & Positive'Image(Sessions) &
" training session(s) in " &
To_String
(SkillsData_Container.Element(Skills_List, SkillIndex).Name) &
" for " & To_String(Player_Ship.Crew(MemberIndex).Name) & " for" &
Positive'Image(OverallCost) & " " & To_String(Money_Name) & ".",
TradeMessage);
end if;
end TrainSkill;
end Bases.Trade;
|
with Ada.IO_Exceptions;
with System.Address_To_Access_Conversions;
with C.libxml.tree;
with C.libxml.xmlIO;
package body XML.Streams is
use type C.libxml.tree.xmlOutputBufferPtr;
use type C.libxml.xmlreader.xmlTextReaderPtr;
use type C.libxml.xmlwriter.xmlTextWriterPtr;
procedure memcpy (dst, src : System.Address; n : C.size_t)
with Import, Convention => Intrinsic, External_Name => "__builtin_memcpy";
-- reader
function Read_Handler (
context : C.void_ptr;
buffer : access C.char;
len : C.signed_int)
return C.signed_int
with Convention => C;
function Read_Handler (
context : C.void_ptr;
buffer : access C.char;
len : C.signed_int)
return C.signed_int
is
package Conv is
new System.Address_To_Access_Conversions (Ada.Streams.Root_Stream_Type'Class);
Stream : constant Conv.Object_Pointer :=
Conv.To_Pointer (System.Address (context));
Item :
Ada.Streams.Stream_Element_Array (
1 .. Ada.Streams.Stream_Element_Offset (len));
for Item'Address use buffer.all'Address;
Last : Ada.Streams.Stream_Element_Offset;
begin
begin
Ada.Streams.Read (Stream.all, Item, Last);
exception
when Ada.IO_Exceptions.End_Error =>
Last := 0;
end;
return C.signed_int (Last);
end Read_Handler;
-- implementation of reader
function Create (
Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Encoding : Encoding_Type := No_Encoding;
URI : String := "")
return Reader
is
package Conv is
new System.Address_To_Access_Conversions (Ada.Streams.Root_Stream_Type'Class);
begin
Check_Version;
declare
P_Encoding : C.char_const_ptr := null;
P_URI : access constant C.char := null;
URI_Length : constant C.size_t := URI'Length;
C_URI : aliased C.char_array (0 .. URI_Length); -- NUL
begin
if Encoding /= null then
P_Encoding := C.char_const_ptr (Encoding.name);
end if;
if URI'Length > 0 then
memcpy (C_URI'Address, URI'Address, URI_Length);
C_URI (URI_Length) := C.char'Val (0);
P_URI := C_URI (C_URI'First)'Access;
end if;
return Result : aliased Reader do
declare
NC_Result : Non_Controlled_Reader
renames Controlled_Readers.Reference (Result).all;
begin
NC_Result.Raw :=
C.libxml.xmlreader.xmlReaderForIO (
Read_Handler'Access,
null,
C.void_ptr (Conv.To_Address (Conv.Object_Pointer (Stream))),
P_URI,
P_Encoding,
0);
if NC_Result.Raw = null then
raise Use_Error;
end if;
Install_Error_Handler (NC_Result);
end;
end return;
end;
end Create;
-- writer
function Write_Handler (
context : C.void_ptr;
buffer : access constant C.char;
len : C.signed_int)
return C.signed_int
with Convention => C;
function Write_Handler (
context : C.void_ptr;
buffer : access constant C.char;
len : C.signed_int)
return C.signed_int
is
package Conv is
new System.Address_To_Access_Conversions (Ada.Streams.Root_Stream_Type'Class);
Stream : constant Conv.Object_Pointer :=
Conv.To_Pointer (System.Address (context));
Item :
Ada.Streams.Stream_Element_Array (
1 .. Ada.Streams.Stream_Element_Offset (len));
for Item'Address use buffer.all'Address;
begin
Ada.Streams.Write (Stream.all, Item);
return len;
end Write_Handler;
-- implementation of writer
function Create (
Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Encoding : Encoding_Type := No_Encoding)
return Writer
is
package Conv is
new System.Address_To_Access_Conversions (Ada.Streams.Root_Stream_Type'Class);
begin
Check_Version;
declare
Buffer : constant C.libxml.tree.xmlOutputBufferPtr :=
C.libxml.xmlIO.xmlOutputBufferCreateIO (
Write_Handler'Access,
null,
C.void_ptr (Conv.To_Address (Conv.Object_Pointer (Stream))),
Encoding);
begin
if Buffer = null then
raise Use_Error;
end if;
return Result : Writer do
declare
procedure Process (NC_Result : in out Non_Controlled_Writer) is
begin
NC_Result.Raw := C.libxml.xmlwriter.xmlNewTextWriter (Buffer);
if NC_Result.Raw = null then
declare
Dummy : C.signed_int;
begin
Dummy := C.libxml.xmlIO.xmlOutputBufferClose (Buffer);
end;
raise Use_Error;
end if;
end Process;
procedure Do_Create is new Controlled_Writers.Update (Process);
begin
Do_Create (Result);
end;
end return;
end;
end Create;
end XML.Streams;
|
pragma License (Unrestricted);
-- Ada 2005
with Ada.Iterator_Interfaces;
private with Ada.Containers.Copy_On_Write;
private with Ada.Containers.Naked_Doubly_Linked_Lists;
private with Ada.Finalization;
private with Ada.Streams;
generic
type Element_Type (<>) is private;
with function "=" (Left, Right : Element_Type) return Boolean is <>;
package Ada.Containers.Indefinite_Doubly_Linked_Lists is
pragma Preelaborate;
pragma Remote_Types;
type List is tagged private
with
Constant_Indexing => Constant_Reference,
Variable_Indexing => Reference,
Default_Iterator => Iterate,
Iterator_Element => Element_Type;
pragma Preelaborable_Initialization (List);
type Cursor is private;
pragma Preelaborable_Initialization (Cursor);
-- modified
-- Empty_List : constant List;
function Empty_List return List;
No_Element : constant Cursor;
function Has_Element (Position : Cursor) return Boolean;
package List_Iterator_Interfaces is
new Iterator_Interfaces (Cursor, Has_Element);
overriding function "=" (Left, Right : List) return Boolean;
function Length (Container : List) return Count_Type;
function Is_Empty (Container : List) return Boolean;
procedure Clear (Container : in out List);
function Element (Position : Cursor) return Element_Type;
procedure Replace_Element (
Container : in out List;
Position : Cursor;
New_Item : Element_Type);
procedure Query_Element (
Position : Cursor;
Process : not null access procedure (Element : Element_Type));
-- modified
procedure Update_Element (
Container : in out List'Class; -- not primitive
Position : Cursor;
Process : not null access procedure (Element : in out Element_Type));
type Constant_Reference_Type (
Element : not null access constant Element_Type) is private
with Implicit_Dereference => Element;
type Reference_Type (Element : not null access Element_Type) is private
with Implicit_Dereference => Element;
function Constant_Reference (Container : aliased List; Position : Cursor)
return Constant_Reference_Type;
function Reference (Container : aliased in out List; Position : Cursor)
return Reference_Type;
procedure Assign (Target : in out List; Source : List);
function Copy (Source : List) return List;
procedure Move (Target : in out List; Source : in out List);
procedure Insert (
Container : in out List;
Before : Cursor;
New_Item : Element_Type;
Count : Count_Type := 1);
procedure Insert (
Container : in out List;
Before : Cursor;
New_Item : Element_Type;
Position : out Cursor;
Count : Count_Type := 1);
-- diff (Insert)
--
--
--
--
procedure Prepend (
Container : in out List;
New_Item : Element_Type;
Count : Count_Type := 1);
procedure Append (
Container : in out List;
New_Item : Element_Type;
Count : Count_Type := 1);
procedure Delete (
Container : in out List;
Position : in out Cursor;
Count : Count_Type := 1);
-- modified
procedure Delete_First (
Container : in out List'Class; -- not primitive
Count : Count_Type := 1);
-- modified
procedure Delete_Last (
Container : in out List'Class; -- not primitive
Count : Count_Type := 1);
procedure Reverse_Elements (Container : in out List);
procedure Swap (Container : in out List; I, J : Cursor);
procedure Swap_Links (Container : in out List; I, J : Cursor);
procedure Splice (
Target : in out List;
Before : Cursor;
Source : in out List);
procedure Splice (
Target : in out List;
Before : Cursor;
Source : in out List;
Position : in out Cursor);
procedure Splice (
Container : in out List;
Before : Cursor;
Position : Cursor);
function First (Container : List) return Cursor;
-- modified
function First_Element (Container : List'Class) -- not primitive
return Element_Type;
function Last (Container : List) return Cursor;
-- modified
function Last_Element (Container : List'Class) -- not primitive
return Element_Type;
function Next (Position : Cursor) return Cursor;
function Previous (Position : Cursor) return Cursor;
procedure Next (Position : in out Cursor);
procedure Previous (Position : in out Cursor);
-- modified
-- function Find (
-- Container : List;
-- Item : Element_Type;
-- Position : Cursor := No_Element)
-- return Cursor;
function Find (
Container : List;
Item : Element_Type)
return Cursor;
function Find (
Container : List;
Item : Element_Type;
Position : Cursor)
return Cursor;
-- modified
-- function Reverse_Find (
-- Container : List;
-- Item : Element_Type;
-- Position : Cursor := No_Element)
-- return Cursor;
function Reverse_Find (
Container : List;
Item : Element_Type)
return Cursor;
function Reverse_Find (
Container : List;
Item : Element_Type;
Position : Cursor)
return Cursor;
function Contains (Container : List; Item : Element_Type) return Boolean;
-- extended
function "<" (Left, Right : Cursor) return Boolean;
-- modified
procedure Iterate (
Container : List'Class; -- not primitive
Process : not null access procedure (Position : Cursor));
-- modified
procedure Reverse_Iterate (
Container : List'Class; -- not primitive
Process : not null access procedure (Position : Cursor));
-- modified
function Iterate (Container : List'Class) -- not primitive
return List_Iterator_Interfaces.Reversible_Iterator'Class;
-- function Iterate (Container : List; Start : Cursor)
-- return List_Iterator_Interfaces.Reversible_Iterator'Class;
-- extended
function Iterate (Container : List'Class; First, Last : Cursor)
return List_Iterator_Interfaces.Reversible_Iterator'Class;
generic
with function "<" (Left, Right : Element_Type) return Boolean is <>;
package Generic_Sorting is
function Is_Sorted (Container : List) return Boolean;
procedure Sort (Container : in out List);
procedure Merge (Target : in out List; Source : in out List);
end Generic_Sorting;
-- diff (Equivalents)
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
private
package Base renames Naked_Doubly_Linked_Lists;
type Element_Access is access Element_Type;
type Node is limited record
Super : aliased Base.Node;
Element : Element_Access;
end record;
-- place Super at first whether Element_Type is controlled-type
for Node use record
Super at 0 range 0 .. Base.Node_Size - 1;
end record;
type Data is limited record
Super : aliased Copy_On_Write.Data;
First : Base.Node_Access := null;
Last : Base.Node_Access := null;
Length : Count_Type := 0;
end record;
type Data_Access is access Data;
type List is new Finalization.Controlled with record
Super : aliased Copy_On_Write.Container;
-- diff
-- diff
end record;
overriding procedure Adjust (Object : in out List);
overriding procedure Finalize (Object : in out List)
renames Clear;
type Cursor is access Node;
type Constant_Reference_Type (
Element : not null access constant Element_Type) is null record;
type Reference_Type (Element : not null access Element_Type) is null record;
type List_Iterator is
new List_Iterator_Interfaces.Reversible_Iterator with
record
First : Cursor;
Last : Cursor;
end record;
overriding function First (Object : List_Iterator) return Cursor;
overriding function Next (Object : List_Iterator; Position : Cursor)
return Cursor;
overriding function Last (Object : List_Iterator) return Cursor;
overriding function Previous (Object : List_Iterator; Position : Cursor)
return Cursor;
package Streaming is
procedure Read (
Stream : not null access Streams.Root_Stream_Type'Class;
Item : out List);
procedure Write (
Stream : not null access Streams.Root_Stream_Type'Class;
Item : List);
procedure Missing_Read (
Stream : access Streams.Root_Stream_Type'Class;
Item : out Cursor)
with Import,
Convention => Ada, External_Name => "__drake_program_error";
procedure Missing_Write (
Stream : access Streams.Root_Stream_Type'Class;
Item : Cursor)
with Import,
Convention => Ada, External_Name => "__drake_program_error";
procedure Missing_Read (
Stream : access Streams.Root_Stream_Type'Class;
Item : out Constant_Reference_Type)
with Import,
Convention => Ada, External_Name => "__drake_program_error";
procedure Missing_Write (
Stream : access Streams.Root_Stream_Type'Class;
Item : Constant_Reference_Type)
with Import,
Convention => Ada, External_Name => "__drake_program_error";
procedure Missing_Read (
Stream : access Streams.Root_Stream_Type'Class;
Item : out Reference_Type)
with Import,
Convention => Ada, External_Name => "__drake_program_error";
procedure Missing_Write (
Stream : access Streams.Root_Stream_Type'Class;
Item : Reference_Type)
with Import,
Convention => Ada, External_Name => "__drake_program_error";
end Streaming;
for List'Read use Streaming.Read;
for List'Write use Streaming.Write;
for Cursor'Read use Streaming.Missing_Read;
for Cursor'Write use Streaming.Missing_Write;
for Constant_Reference_Type'Read use Streaming.Missing_Read;
for Constant_Reference_Type'Write use Streaming.Missing_Write;
for Reference_Type'Read use Streaming.Missing_Read;
for Reference_Type'Write use Streaming.Missing_Write;
No_Element : constant Cursor := null;
end Ada.Containers.Indefinite_Doubly_Linked_Lists;
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . A _ O S I N T --
-- --
-- B o d y --
-- --
-- Copyright (c) 1995-1999, Free Software Foundation, Inc. --
-- --
-- ASIS-for-GNAT is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 2, or (at your option) any later --
-- version. ASIS-for-GNAT is distributed in the hope that it will be use- --
-- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- --
-- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with ASIS-for-GNAT; see file --
-- COPYING. If not, write to the Free Software Foundation, 59 Temple Place --
-- - Suite 330, Boston, MA 02111-1307, USA. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the --
-- Software Engineering Laboratory of the Swiss Federal Institute of --
-- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the --
-- Scientific Research Computer Center of Moscow State University (SRCC --
-- MSU), Russia, with funding partially provided by grants from the Swiss --
-- National Science Foundation and the Swiss Academy of Engineering --
-- Sciences. ASIS-for-GNAT is now maintained by Ada Core Technologies Inc --
-- (http://www.gnat.com). --
-- --
------------------------------------------------------------------------------
with Unchecked_Deallocation;
package body A4G.A_Osint is
-----------------------
-- Local subprograms --
-----------------------
procedure Free_String is new Unchecked_Deallocation (String, String_Access);
procedure Free_List is new Unchecked_Deallocation
(Argument_List, Argument_List_Access);
------------------------
-- Free_Argument_List --
------------------------
procedure Free_Argument_List (List : in out Argument_List_Access) is
begin
if List = null then
return;
end if;
for J in List'Range loop
Free_String (List (J));
end loop;
Free_List (List);
end Free_Argument_List;
------------------------------
-- Get_Max_File_Name_Length --
------------------------------
function Get_Max_File_Name_Length return Int is
function Get_Maximum_File_Name_Length return Int;
pragma Import (C, Get_Maximum_File_Name_Length,
"__gnat_get_maximum_file_name_length");
-- This function does what we want, but it returns -1 when there
-- is no restriction on the file name length
--
-- The implementation has been "stolen" from the body of GNAT
-- Osint.Initialize
begin
if Get_Maximum_File_Name_Length = -1 then
return Int'Last;
else
return Get_Maximum_File_Name_Length;
end if;
end Get_Max_File_Name_Length;
------------------------------
-- Normalize_Directory_Name --
------------------------------
function Normalize_Directory_Name
(Directory : String)
return String
is
begin
-- For now this just insures that the string is terminated with
-- the directory separator character. Add more later?
if Directory (Directory'Last) = Directory_Separator then
return Directory;
elsif Directory'Length = 0 then
-- now we do not need this, but it is no harm to keep it
return '.' & Directory_Separator;
else
return Directory & Directory_Separator;
end if;
end Normalize_Directory_Name;
end A4G.A_Osint;
|
Pragma Ada_2012;
Pragma Wide_Character_Encoding( UTF8 );
with
Risi_Script.Types.Patterns,
Risi_Script.Types.Identifier,
Risi_Script.Types.Identifier.Scope,
Risi_Script.Types.Implementation,
Risi_Script.Interfaces;
Package Risi_Script.Interpreter is
Use Risi_Script.Interfaces;
Type Virtual_Machine is tagged -- new VM and Stack_Interface with
null record;
End Risi_Script.Interpreter;
|
-- -----------------------------------------------------------------------------
-- smk, the smart make (http://lionel.draghi.free.fr/smk/)
-- © 2018, 2019 Lionel Draghi <lionel.draghi@free.fr>
-- SPDX-License-Identifier: APSL-2.0
-- -----------------------------------------------------------------------------
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
-- http://www.apache.org/licenses/LICENSE-2.0
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- -----------------------------------------------------------------------------
with Ada.Text_IO; use Ada.Text_IO;
separate (Smk.Main)
-- -----------------------------------------------------------------------------
procedure Put_Help is
begin
New_Line;
Put_Line ("Usage : smk [Options]* Command [Smkfile][:target]");
New_Line;
Put_Line ("Use example :");
Put_Line (" when run the first time : smk MyBuild.txt");
Put_Line (" and then,to rebuild, just : smk");
Put_Line (" to run a specific target : smk MyBuild.txt:target");
Put_Line (" or just : smk :target");
New_Line;
Put_Line ("Commands :");
Put_Line (" build : run the build");
Put_Line (" status | st : shows what smk knows about the previous");
Put_Line (" runs (commands, sources and targets)");
Put_Line (" read-smkfile | rs : shows smk understanding of a Smkfile");
Put_Line (" whatsnew | wn : list changes since last run");
Put_Line (" add : add the rest of the command line to");
Put_Line (" default.smk");
Put_Line (" run : equivalent to `add` followed by `build`");
Put_Line (" clean : remove all targets files");
Put_Line (" reset : remove all local Smk files");
Put_Line (" (equivalent to rm .smk.*)");
Put_Line (" version : put Smk version");
Put_Line (" help : this message");
Put_Line (" dump : list all smk known info on files,");
Put_Line (" including unused and dir");
Put_Line (" list-runs | lr : list runfiles in current directory");
Put_Line (" list-sources | ls : list sources, except system files");
Put_Line (" list-targets | lt : list targets, except system files");
Put_Line (" list-unused | lu : list files not involved in build");
New_Line;
Put_Line (" NB : when no command is given, build is assumed");
New_Line;
Put_Line ("Options :");
Put_Line (" -mt | --missing-targets : build if missing targets");
Put_Line (" (default is to build only if");
Put_Line (" sources are updated)");
Put_Line (" -a | --always-make : unconditionally make all targets");
Put_Line (" -e | --explain : explain why each target is made");
Put_Line (" -n | --dry-run : print the commands that would be");
Put_Line (" executed, but do not execute them");
Put_Line (" -sa | --show-all-files : show also system files");
Put_Line (" -ds | --dont-shorten : print files with full path");
Put_Line (" -i | --ignore-errors : ignore all errors in commands");
Put_Line (" executed to remake files");
Put_Line (" -l | --long-listing : use a long listing format when");
Put_Line (" listing files");
Put_Line (" -k | --keep-going : Do as much work as possible");
Put_Line (" -We | --Warnings=error : treat warnings as errors");
Put_Line (" -v | --verbose");
Put_Line (" -q | --quiet : no message unless error,");
Put_Line (" Warning are also ignored");
Put_Line (" -h | --help : this message");
New_Line;
Put_Line ("http://lionel.draghi.free.fr/smk/");
New_Line;
end Put_Help;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . B B . B O A R D _ S U P P O R T --
-- --
-- B o d y --
-- --
-- Copyright (C) 1999-2002 Universidad Politecnica de Madrid --
-- Copyright (C) 2003-2006 The European Space Agency --
-- Copyright (C) 2003-2016, AdaCore --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNARL was developed by the GNARL team at Florida State University. --
-- Extensive contributions were provided by Ada Core Technologies, Inc. --
-- --
-- The port of GNARL to bare board targets was initially developed by the --
-- Real-Time Systems Group at the Technical University of Madrid. --
-- --
------------------------------------------------------------------------------
-- There are page numbers in the comments below, please provide the reference
-- to the document (here in this header) to which these references apply ???
pragma Restrictions (No_Elaboration_Code);
with System.BB.Board_Support.ERC32;
with System.BB.Parameters;
package body System.BB.Board_Support is
use type ERC32.Scaler_8;
use type ERC32.Timers_Counter;
use CPU_Primitives;
package Registers renames ERC32;
-----------------------
-- Local Definitions --
-----------------------
Periodic_Scaler : constant := 0;
-- In order to obtain the highest granularity of the clock we set the
-- scaler to 0.
Alarm_Scaler : constant := 0;
-- In order to obtain the highest resolution of the alarm timer we set
-- the scaler to 0.
Periodic_Count : constant := Registers.Timers_Counter'Last - 1;
-- Value to be loaded in the clock counter to accomplish the
-- Clock_Interrupt_Period.
--
-- One is subtracted from Timers_Counter'Last because when the Scaler is
-- set to 0, the timeout period will be the counter reload value plus 1.
-- Constants defining the external interrupts
General_Purpose_Timer : constant System.BB.Interrupts.Interrupt_ID := 12;
Timer_Control_Mirror : Registers.Timer_Control_Register;
pragma Volatile (Timer_Control_Mirror);
-- Timer_Control register cannot be read. So the following object holds a
-- copy of the Timer_Control register value.
----------------------
-- Local Procedures --
----------------------
procedure Stop_Watch_Dog;
pragma Inline (Stop_Watch_Dog);
-- Stop the watch dog timer
procedure Initialize_Memory;
pragma Inline (Initialize_Memory);
-- Initialize the memory on the board
procedure Initialize_Clock;
-- Perform all the initialization related to the clock
------------------------
-- Alarm_Interrupt_ID --
------------------------
function Alarm_Interrupt_ID return Interrupts.Interrupt_ID is
begin
return General_Purpose_Timer;
end Alarm_Interrupt_ID;
---------------------------
-- Clear_Alarm_Interrupt --
---------------------------
procedure Clear_Alarm_Interrupt is
begin
-- From MEC Specification Document (MCD/SPC/0009/SE) page 35
-- The MEC includes a specific register called Interrupt Pending
-- Register, which reflects the pending interrupts.
-- The interrupts in the IPR are cleared automatically when the
-- interrupt is acknowledged. The MEC will sample the trap address in
-- order to know which bit to clear. Therefore, this procedure has a
-- null body for this target.
null;
end Clear_Alarm_Interrupt;
-----------------------------
-- Clear_Interrupt_Request --
-----------------------------
procedure Clear_Interrupt_Request
(Interrupt : System.BB.Interrupts.Interrupt_ID)
is
begin
-- Nothing to do for the IPIC
null;
end Clear_Interrupt_Request;
--------------------------
-- Clear_Poke_Interrupt --
--------------------------
procedure Clear_Poke_Interrupt is
begin
-- No Poke interrupt available for ERC32
raise Program_Error;
end Clear_Poke_Interrupt;
---------------------------
-- Priority_Of_Interrupt --
---------------------------
function Priority_Of_Interrupt
(Interrupt : System.BB.Interrupts.Interrupt_ID) return System.Any_Priority
is
begin
-- Assert that it is a real interrupt
pragma Assert (Interrupt /= System.BB.Interrupts.No_Interrupt);
return (Any_Priority (Interrupt) + Interrupt_Priority'First - 1);
end Priority_Of_Interrupt;
----------------------
-- Initialize_Board --
----------------------
procedure Initialize_Board is
begin
-- The initialization of the ERC32 board consists on stopping the watch
-- dog timer, initializing the memory, and initializing the clock in
-- order to have the desired granularity and range.
Stop_Watch_Dog;
Initialize_Memory;
Initialize_Clock;
end Initialize_Board;
----------------------
-- Initialize_Clock --
----------------------
procedure Initialize_Clock is
Real_Time_Clock_Scaler_Aux : Registers.Real_Time_Clock_Scaler_Register;
begin
-- Set the scaler for the clock
Real_Time_Clock_Scaler_Aux := Registers.Real_Time_Clock_Scaler;
Real_Time_Clock_Scaler_Aux.RTCS := Periodic_Scaler;
Registers.Real_Time_Clock_Scaler := Real_Time_Clock_Scaler_Aux;
-- Load the counter for the clock
Registers.Real_Time_Clock_Counter := Periodic_Count;
-- Set the proper bits in mirrored Timer Control Register. The timer
-- used for the clock is programmed in periodic mode.
-- From MEC Specification Document (MCD/SPC/0009/SE) page 50
-- NOTE: All reserved bits have to be written with zeros in order to
-- avoid parity error resulting in a MEC internal error.
Timer_Control_Mirror.Reserved4 := (others => False);
Timer_Control_Mirror.Reserved20 := (others => False);
Timer_Control_Mirror.RTCCR := True;
Timer_Control_Mirror.RTCCL := True;
Timer_Control_Mirror.RTCSL := True;
Timer_Control_Mirror.RTCSE := True;
-- Do not modify General Purpose Timer downcounter
Timer_Control_Mirror.GCL := False;
Timer_Control_Mirror.GSL := False;
-- Write MEC Timer Control Register
Registers.Timer_Control := Timer_Control_Mirror;
end Initialize_Clock;
-----------------------
-- Initialize_Memory --
-----------------------
procedure Initialize_Memory is
begin
-- Nothing to be done for the ERC32
null;
end Initialize_Memory;
------------------------
-- Max_Timer_Interval --
------------------------
function Max_Timer_Interval return Timer_Interval is
begin
return Timer_Interval'Last;
end Max_Timer_Interval;
-----------------------
-- Poke_Interrupt_ID --
-----------------------
function Poke_Interrupt_ID return Interrupts.Interrupt_ID is
begin
-- No Poke interrupt available for ERC32
raise Program_Error;
-- Unreachable code
return Interrupts.Interrupt_ID'First;
end Poke_Interrupt_ID;
---------------------------
-- Get_Interrupt_Request --
---------------------------
function Get_Interrupt_Request
(Vector : CPU_Primitives.Vector_Id)
return System.BB.Interrupts.Interrupt_ID
is
begin
-- The range corresponding to asynchronous traps is in 16#11# .. 16#1F#
pragma Assert (Vector in 16#11# .. 16#1F#);
return System.BB.Interrupts.Interrupt_ID (Vector - 16#10#);
end Get_Interrupt_Request;
-------------------------------
-- Install_Interrupt_Handler --
-------------------------------
procedure Install_Interrupt_Handler
(Handler : Address;
Interrupt : Interrupts.Interrupt_ID;
Prio : Interrupt_Priority)
is
pragma Unreferenced (Prio);
begin
CPU_Primitives.Install_Trap_Handler
(Handler, CPU_Primitives.Vector_Id (Interrupt + 16#10#));
end Install_Interrupt_Handler;
----------------
-- Read_Clock --
----------------
function Read_Clock return Timer_Interval is
begin
return
Timer_Interval (Periodic_Count - Registers.Real_Time_Clock_Counter);
end Read_Clock;
---------------
-- Set_Alarm --
---------------
procedure Set_Alarm (Ticks : Timer_Interval) is
General_Purpose_Timer_Scaler_Aux :
Registers.General_Purpose_Timer_Scaler_Register;
Interrupt_Mask_Aux : Registers.Interrupt_Mask_Register;
begin
-- Alarm Clock downcount will reach 0 in Ticks. The granularity of
-- time intervals is equal to Clock Period.
-- Set the scaler
General_Purpose_Timer_Scaler_Aux :=
Registers.General_Purpose_Timer_Scaler;
General_Purpose_Timer_Scaler_Aux.GPTS := Alarm_Scaler;
Registers.General_Purpose_Timer_Scaler :=
General_Purpose_Timer_Scaler_Aux;
-- Load the counter
Registers.General_Purpose_Timer_Counter :=
Registers.Timers_Counter (Ticks);
-- Set the proper bits in mirrored Timer Control Register.
-- General Purpose Timer is used in one-shot mode.
Timer_Control_Mirror.GCR := False;
Timer_Control_Mirror.GCL := True;
Timer_Control_Mirror.GSE := True;
Timer_Control_Mirror.GSL := True;
-- Do not modify Timer downcount
Timer_Control_Mirror.RTCCL := False;
Timer_Control_Mirror.RTCSL := False;
-- From MEC Specification Document (MCD/SPC/0009/SE) page 50
-- NOTE: All reserved bits have to be written with zeros in order to
-- avoid parity error resulting in a MEC internal error.
Timer_Control_Mirror.Reserved4 := (others => False);
Timer_Control_Mirror.Reserved20 := (others => False);
-- Write MEC Timer Control Register
Registers.Timer_Control := Timer_Control_Mirror;
-- Enable GPT Interrupts
Interrupt_Mask_Aux := Registers.Interrupt_Mask;
Interrupt_Mask_Aux.General_Purpose_Timer := False;
Registers.Interrupt_Mask := Interrupt_Mask_Aux;
end Set_Alarm;
--------------------------
-- Set_Current_Priority --
--------------------------
procedure Set_Current_Priority (Priority : Integer) is
begin
null; -- No board-specific actions necessary
end Set_Current_Priority;
--------------------
-- Stop_Watch_Dog --
--------------------
procedure Stop_Watch_Dog is
begin
-- From MEC Specification Document (MCD/SPC/0009/SE) page 39
-- After system reset or processor reset, the watch dog timer is enabled
-- and starts running. By writing to the Trap Door Set after system
-- reset, the timer can be disabled.
Registers.Watchdog_Trap_Door_Set := 0;
end Stop_Watch_Dog;
----------------------
-- Ticks_Per_Second --
----------------------
function Ticks_Per_Second return Natural is
begin
-- The prescaler is clocked by the system clock. When it underflows, it
-- is reloaded from the prescaler reload register and a timer tick is
-- generated. The effective division rate is therefore equal to the
-- prescaler reload register value plus 1.
return Parameters.Clock_Frequency / (Periodic_Scaler + 1);
end Ticks_Per_Second;
end System.BB.Board_Support;
|
-- PR middle-end/36554
-- Origin: Laurent Guerby <laurent@guerby.net>
-- { dg-do compile }
-- { dg-options "-O2" }
package body Boolean_Expr1 is
function Long_Float_Is_Valid (X : in Long_Float) return Boolean is
Is_Nan : constant Boolean := X /= X;
Is_P_Inf : constant Boolean := X > Long_Float'Last;
Is_M_Inf : constant Boolean := X < Long_Float'First;
Is_Invalid : constant Boolean := Is_Nan or Is_P_Inf or Is_M_Inf;
begin
return not Is_Invalid;
end Long_Float_Is_Valid;
function S (V : in Long_Float) return String is
begin
if not Long_Float_Is_Valid (V) then
return "INVALID";
else
return "OK";
end if;
exception
when others =>
return "ERROR";
end S;
end Boolean_Expr1;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M _ E L A B --
-- --
-- B o d y --
-- --
-- $Revision$
-- --
-- Copyright (C) 1997-2001 Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Atree; use Atree;
with Checks; use Checks;
with Debug; use Debug;
with Einfo; use Einfo;
with Elists; use Elists;
with Errout; use Errout;
with Exp_Util; use Exp_Util;
with Expander; use Expander;
with Fname; use Fname;
with Lib; use Lib;
with Lib.Load; use Lib.Load;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Output; use Output;
with Restrict; use Restrict;
with Sem; use Sem;
with Sem_Cat; use Sem_Cat;
with Sem_Ch7; use Sem_Ch7;
with Sem_Ch8; use Sem_Ch8;
with Sem_Res; use Sem_Res;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
with Snames; use Snames;
with Stand; use Stand;
with Table;
with Tbuild; use Tbuild;
with Uname; use Uname;
package body Sem_Elab is
-- The following table records the recursive call chain for output
-- in the Output routine. Each entry records the call node and the
-- entity of the called routine. The number of entries in the table
-- (i.e. the value of Elab_Call.Last) indicates the current depth
-- of recursion and is used to identify the outer level.
type Elab_Call_Entry is record
Cloc : Source_Ptr;
Ent : Entity_Id;
end record;
package Elab_Call is new Table.Table (
Table_Component_Type => Elab_Call_Entry,
Table_Index_Type => Int,
Table_Low_Bound => 1,
Table_Initial => 50,
Table_Increment => 100,
Table_Name => "Elab_Call");
-- This table is initialized at the start of each outer level call.
-- It holds the entities for all subprograms that have been examined
-- for this particular outer level call, and is used to prevent both
-- infinite recursion, and useless reanalysis of bodies already seen
package Elab_Visited is new Table.Table (
Table_Component_Type => Entity_Id,
Table_Index_Type => Int,
Table_Low_Bound => 1,
Table_Initial => 200,
Table_Increment => 100,
Table_Name => "Elab_Visited");
-- This table stores calls to Check_Internal_Call that are delayed
-- until all generics are instantiated, and in particular that all
-- generic bodies have been inserted. We need to delay, because we
-- need to be able to look through the inserted bodies.
type Delay_Element is record
N : Node_Id;
-- The parameter N from the call to Check_Internal_Call. Note that
-- this node may get rewritten over the delay period by expansion
-- in the call case (but not in the instantiation case).
E : Entity_Id;
-- The parameter E from the call to Check_Internal_Call
Orig_Ent : Entity_Id;
-- The parameter Orig_Ent from the call to Check_Internal_Call
Curscop : Entity_Id;
-- The current scope of the call. This is restored when we complete
-- the delayed call, so that we do this in the right scope.
From_Elab_Code : Boolean;
-- Save indication of whether this call is from elaboration code
Outer_Scope : Entity_Id;
-- Save scope of outer level call
end record;
package Delay_Check is new Table.Table (
Table_Component_Type => Delay_Element,
Table_Index_Type => Int,
Table_Low_Bound => 1,
Table_Initial => 1000,
Table_Increment => 100,
Table_Name => "Delay_Check");
C_Scope : Entity_Id;
-- Top level scope of current scope. We need to compute this only
-- once at the outer level, i.e. for a call to Check_Elab_Call from
-- outside this unit.
Outer_Level_Sloc : Source_Ptr;
-- Save Sloc value for outer level call node for comparisons of source
-- locations. A body is too late if it appears after the *outer* level
-- call, not the particular call that is being analyzed.
From_Elab_Code : Boolean;
-- This flag shows whether the outer level call currently being examined
-- is or is not in elaboration code. We are only interested in calls to
-- routines in other units if this flag is True.
In_Task_Activation : Boolean := False;
-- This flag indicates whether we are performing elaboration checks on
-- task procedures, at the point of activation. If true, we do not trace
-- internal calls in these procedures, because all local bodies are known
-- to be elaborated.
Delaying_Elab_Checks : Boolean := True;
-- This is set True till the compilation is complete, including the
-- insertion of all instance bodies. Then when Check_Elab_Calls is
-- called, the delay table is used to make the delayed calls and
-- this flag is reset to False, so that the calls are processed
-----------------------
-- Local Subprograms --
-----------------------
-- Note: Outer_Scope in all these calls represents the scope of
-- interest of the outer level call. If it is set to Standard_Standard,
-- then it means the outer level call was at elaboration level, and that
-- thus all calls are of interest. If it was set to some other scope,
-- then the original call was an inner call, and we are not interested
-- in calls that go outside this scope.
procedure Check_A_Call
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Inter_Unit_Only : Boolean;
Generate_Warnings : Boolean := True);
-- This is the internal recursive routine that is called to check for
-- a possible elaboration error. The argument N is a subprogram call
-- or generic instantiation to be checked, and E is the entity of
-- the called subprogram, or instantiated generic unit. The flag
-- Outer_Scope is the outer level scope for the original call.
-- Inter_Unit_Only is set if the call is only to be checked in the
-- case where it is to another unit (and skipped if within a unit).
-- Generate_Warnings is set to True to suppress warning messages
-- about missing pragma Elaborate_All's. These messages are not
-- wanted for inner calls in the dynamic model.
procedure Check_Bad_Instantiation (N : Node_Id);
-- N is a node for an instantiation (if called with any other node kind,
-- Check_Bad_Instantiation ignores the call). This subprogram checks for
-- the special case of a generic instantiation of a generic spec in the
-- same declarative part as the instantiation where a body is present and
-- has not yet been seen. This is an obvious error, but needs to be checked
-- specially at the time of the instantiation, since it is a case where we
-- cannot insert the body anywhere. If this case is detected, warnings are
-- generated, and a raise of Program_Error is inserted. In addition any
-- subprograms in the generic spec are stubbed, and the Bad_Instantiation
-- flag is set on the instantiation node. The caller in Sem_Ch12 uses this
-- flag as an indication that no attempt should be made to insert an
-- instance body.
procedure Check_Internal_Call
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Orig_Ent : Entity_Id);
-- N is a function call or procedure statement call node and E is
-- the entity of the called function, which is within the current
-- compilation unit (where subunits count as part of the parent).
-- This call checks if this call, or any call within any accessed
-- body could cause an ABE, and if so, outputs a warning. Orig_Ent
-- differs from E only in the case of renamings, and points to the
-- original name of the entity. This is used for error messages.
-- Outer_Scope is the outer level scope for the original call.
procedure Check_Internal_Call_Continue
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Orig_Ent : Entity_Id);
-- The processing for Check_Internal_Call is divided up into two phases,
-- and this represents the second phase. The second phase is delayed if
-- Delaying_Elab_Calls is set to True. In this delayed case, the first
-- phase makes an entry in the Delay_Check table, which is processed
-- when Check_Elab_Calls is called. N, E and Orig_Ent are as for the call
-- to Check_Internal_Call. Outer_Scope is the outer level scope for
-- the original call.
function Has_Generic_Body (N : Node_Id) return Boolean;
-- N is a generic package instantiation node, and this routine determines
-- if this package spec does in fact have a generic body. If so, then
-- True is returned, otherwise False. Note that this is not at all the
-- same as checking if the unit requires a body, since it deals with
-- the case of optional bodies accurately (i.e. if a body is optional,
-- then it looks to see if a body is actually present). Note: this
-- function can only do a fully correct job if in generating code mode
-- where all bodies have to be present. If we are operating in semantics
-- check only mode, then in some cases of optional bodies, a result of
-- False may incorrectly be given. In practice this simply means that
-- some cases of warnings for incorrect order of elaboration will only
-- be given when generating code, which is not a big problem (and is
-- inevitable, given the optional body semantics of Ada).
procedure Insert_Elab_Check (N : Node_Id; C : Node_Id := Empty);
-- Given code for an elaboration check (or unconditional raise if
-- the check is not needed), inserts the code in the appropriate
-- place. N is the call or instantiation node for which the check
-- code is required. C is the test whose failure triggers the raise.
procedure Output_Calls (N : Node_Id);
-- Outputs chain of calls stored in the Elab_Call table. The caller
-- has already generated the main warning message, so the warnings
-- generated are all continuation messages. The argument is the
-- call node at which the messages are to be placed.
function Same_Elaboration_Scope (Scop1, Scop2 : Entity_Id) return Boolean;
-- Given two scopes, determine whether they are the same scope from an
-- elaboration point of view, i.e. packages and blocks are ignored.
procedure Set_C_Scope;
-- On entry C_Scope is set to some scope. On return, C_Scope is reset
-- to be the enclosing compilation unit of this scope.
function Spec_Entity (E : Entity_Id) return Entity_Id;
-- Given a compilation unit entity, if it is a spec entity, it is
-- returned unchanged. If it is a body entity, then the spec for
-- the corresponding spec is returned
procedure Supply_Bodies (N : Node_Id);
-- Given a node, N, that is either a subprogram declaration or a package
-- declaration, this procedure supplies dummy bodies for the subprogram
-- or for all subprograms in the package. If the given node is not one
-- of these two possibilities, then Supply_Bodies does nothing. The
-- dummy body is supplied by setting the subprogram to be Imported with
-- convention Stubbed.
procedure Supply_Bodies (L : List_Id);
-- Calls Supply_Bodies for all elements of the given list L.
function Within (E1, E2 : Entity_Id) return Boolean;
-- Given two scopes E1 and E2, returns True if E1 is equal to E2, or
-- is one of its contained scopes, False otherwise.
------------------
-- Check_A_Call --
------------------
procedure Check_A_Call
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Inter_Unit_Only : Boolean;
Generate_Warnings : Boolean := True)
is
Loc : constant Source_Ptr := Sloc (N);
Ent : Entity_Id;
Decl : Node_Id;
E_Scope : Entity_Id;
-- Top level scope of entity for called subprogram
Body_Acts_As_Spec : Boolean;
-- Set to true if call is to body acting as spec (no separate spec)
Inst_Case : constant Boolean := Nkind (N) in N_Generic_Instantiation;
-- Indicates if we have instantiation case
Caller_Unit_Internal : Boolean;
Callee_Unit_Internal : Boolean;
Inst_Caller : Source_Ptr;
Inst_Callee : Source_Ptr;
Unit_Caller : Unit_Number_Type;
Unit_Callee : Unit_Number_Type;
Cunit_SW : Boolean := False;
-- Set to suppress warnings for case of external reference where
-- one of the enclosing scopes has the Suppress_Elaboration_Warnings
-- flag set. For the internal case, we ignore this flag.
Cunit_SC : Boolean := False;
-- Set to suppress dynamic elaboration checks where one of the
-- enclosing scopes has Suppress_Elaboration_Checks set. For
-- the internal case, we ignore this flag.
begin
-- Go to parent for derived subprogram, or to original subprogram
-- in the case of a renaming (Alias covers both these cases)
Ent := E;
loop
if Suppress_Elaboration_Warnings (Ent) then
return;
end if;
-- Nothing to do for imported entities,
if Is_Imported (Ent) then
return;
end if;
exit when Inst_Case or else No (Alias (Ent));
Ent := Alias (Ent);
end loop;
Decl := Unit_Declaration_Node (Ent);
if Nkind (Decl) = N_Subprogram_Body then
Body_Acts_As_Spec := True;
elsif Nkind (Decl) = N_Subprogram_Declaration
or else Nkind (Decl) = N_Subprogram_Body_Stub
or else Inst_Case
then
Body_Acts_As_Spec := False;
-- If we have none of an instantiation, subprogram body or
-- subprogram declaration, then it is not a case that we want
-- to check. (One case is a call to a generic formal subprogram,
-- where we do not want the check in the template).
else
return;
end if;
E_Scope := Ent;
loop
if Suppress_Elaboration_Warnings (E_Scope) then
Cunit_SW := True;
end if;
if Suppress_Elaboration_Checks (E_Scope) then
Cunit_SC := True;
end if;
-- Exit when we get to compilation unit, not counting subunits
exit when Is_Compilation_Unit (E_Scope)
and then (Is_Child_Unit (E_Scope)
or else Scope (E_Scope) = Standard_Standard);
-- If we did not find a compilation unit, other than standard,
-- then nothing to check (happens in some instantiation cases)
if E_Scope = Standard_Standard then
return;
-- Otherwise move up a scope looking for compilation unit
else
E_Scope := Scope (E_Scope);
end if;
end loop;
-- No checks needed for pure or preelaborated compilation units
if Is_Pure (E_Scope)
or else Is_Preelaborated (E_Scope)
then
return;
end if;
-- If the generic entity is within a deeper instance than we are, then
-- either the instantiation to which we refer itself caused an ABE, in
-- which case that will be handled separately. Otherwise, we know that
-- the body we need appears as needed at the point of the instantiation.
-- However, this assumption is only valid if we are in static mode.
if not Dynamic_Elaboration_Checks
and then Instantiation_Depth (Sloc (Ent)) >
Instantiation_Depth (Sloc (N))
then
return;
end if;
-- Do not give a warning for a package with no body
if Ekind (Ent) = E_Generic_Package
and then not Has_Generic_Body (N)
then
return;
end if;
-- Case of entity is not in current unit (i.e. with'ed unit case)
if E_Scope /= C_Scope then
-- We are only interested in such calls if the outer call was from
-- elaboration code, or if we are in Dynamic_Elaboration_Checks mode.
if not From_Elab_Code and then not Dynamic_Elaboration_Checks then
return;
end if;
-- Nothing to do if some scope said to ignore warnings
if Cunit_SW then
return;
end if;
-- Nothing to do for a generic instance, because in this case
-- the checking was at the point of instantiation of the generic
-- However, this shortcut is only applicable in static mode.
if Is_Generic_Instance (Ent) and not Dynamic_Elaboration_Checks then
return;
end if;
-- Nothing to do if subprogram with no separate spec
if Body_Acts_As_Spec then
return;
end if;
-- Check cases of internal units
Callee_Unit_Internal :=
Is_Internal_File_Name
(Unit_File_Name (Get_Source_Unit (E_Scope)));
-- Do not give a warning if the with'ed unit is internal
-- and this is the generic instantiation case (this saves a
-- lot of hassle dealing with the Text_IO special child units)
if Callee_Unit_Internal and Inst_Case then
return;
end if;
if C_Scope = Standard_Standard then
Caller_Unit_Internal := False;
else
Caller_Unit_Internal :=
Is_Internal_File_Name
(Unit_File_Name (Get_Source_Unit (C_Scope)));
end if;
-- Do not give a warning if the with'ed unit is internal
-- and the caller is not internal (since the binder always
-- elaborates internal units first).
if Callee_Unit_Internal and (not Caller_Unit_Internal) then
return;
end if;
-- For now, if debug flag -gnatdE is not set, do no checking for
-- one internal unit withing another. This fixes the problem with
-- the sgi build and storage errors. To be resolved later ???
if (Callee_Unit_Internal and Caller_Unit_Internal)
and then not Debug_Flag_EE
then
return;
end if;
Ent := E;
-- If the call is in an instance, and the called entity is not
-- defined in the same instance, then the elaboration issue
-- focuses around the unit containing the template, it is
-- this unit which requires an Elaborate_All.
-- However, if we are doing dynamic elaboration, we need to
-- chase the call in the usual manner.
-- We do not handle the case of calling a generic formal correctly
-- in the static case. See test 4703-004 to explore this gap ???
Inst_Caller := Instantiation (Get_Source_File_Index (Sloc (N)));
Inst_Callee := Instantiation (Get_Source_File_Index (Sloc (Ent)));
if Inst_Caller = No_Location then
Unit_Caller := No_Unit;
else
Unit_Caller := Get_Source_Unit (N);
end if;
if Inst_Callee = No_Location then
Unit_Callee := No_Unit;
else
Unit_Callee := Get_Source_Unit (Ent);
end if;
if Unit_Caller /= No_Unit
and then Unit_Callee /= Unit_Caller
and then Unit_Callee /= No_Unit
and then not Dynamic_Elaboration_Checks
then
E_Scope := Spec_Entity (Cunit_Entity (Unit_Caller));
-- If we don't get a spec entity, just ignore call. Not
-- quite clear why this check is necessary.
if No (E_Scope) then
return;
end if;
-- Otherwise step to enclosing compilation unit
while not Is_Compilation_Unit (E_Scope) loop
E_Scope := Scope (E_Scope);
end loop;
-- For the case of not in an instance, or call within instance
-- We recompute E_Scope for the error message, since we
-- do NOT want to go to the unit which has the ultimate
-- declaration in the case of renaming and derivation and
-- we also want to go to the generic unit in the case of
-- an instance, and no further.
else
-- Loop to carefully follow renamings and derivations
-- one step outside the current unit, but not further.
if not Inst_Case
and then Present (Alias (Ent))
then
E_Scope := Alias (Ent);
else
E_Scope := Ent;
end if;
loop
while not Is_Compilation_Unit (E_Scope) loop
E_Scope := Scope (E_Scope);
end loop;
-- If E_Scope is the same as C_Scope, it means that there
-- definitely was a local renaming or derivation, and we
-- are not yet out of the current unit.
exit when E_Scope /= C_Scope;
Ent := Alias (Ent);
E_Scope := Ent;
end loop;
end if;
if not Suppress_Elaboration_Warnings (Ent)
and then not Suppress_Elaboration_Warnings (E_Scope)
and then Elab_Warnings
and then Generate_Warnings
then
Warn_On_Instance := True;
if Inst_Case then
Error_Msg_NE
("instantiation of& may raise Program_Error?", N, Ent);
else
Error_Msg_NE
("call to & may raise Program_Error?", N, Ent);
end if;
Error_Msg_Qual_Level := Nat'Last;
Error_Msg_NE
("\missing pragma Elaborate_All for&?", N, E_Scope);
Error_Msg_Qual_Level := 0;
Output_Calls (N);
Warn_On_Instance := False;
-- Set flag to prevent further warnings for same unit
-- unless in All_Errors_Mode.
if not All_Errors_Mode and not Dynamic_Elaboration_Checks then
Set_Suppress_Elaboration_Warnings (E_Scope);
end if;
end if;
-- Check for runtime elaboration check required
if Dynamic_Elaboration_Checks then
if not Elaboration_Checks_Suppressed (Ent)
and then not Suppress_Elaboration_Checks (E_Scope)
and then not Cunit_SC
then
-- Runtime elaboration check required. generate check of the
-- elaboration Boolean for the unit containing the entity.
Insert_Elab_Check (N,
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Elaborated,
Prefix =>
New_Occurrence_Of
(Spec_Entity (E_Scope), Loc)));
end if;
-- If no dynamic check required, then ask binder to guarantee
-- that the necessary elaborations will be done properly!
else
if not Suppress_Elaboration_Warnings (E)
and then not Suppress_Elaboration_Warnings (E_Scope)
and then Elab_Warnings
and then Generate_Warnings
and then not Inst_Case
then
Error_Msg_Node_2 := E_Scope;
Error_Msg_NE ("call to& in elaboration code " &
"requires pragma Elaborate_All on&?", N, E);
end if;
Set_Elaborate_All_Desirable (E_Scope);
Set_Suppress_Elaboration_Warnings (E_Scope);
end if;
-- Case of entity is in same unit as call or instantiation
elsif not Inter_Unit_Only then
Check_Internal_Call (N, Ent, Outer_Scope, E);
end if;
end Check_A_Call;
-----------------------------
-- Check_Bad_Instantiation --
-----------------------------
procedure Check_Bad_Instantiation (N : Node_Id) is
Nam : Node_Id;
Ent : Entity_Id;
begin
-- Nothing to do if we do not have an instantiation (happens in some
-- error cases, and also in the formal package declaration case)
if Nkind (N) not in N_Generic_Instantiation then
return;
-- Nothing to do if errors already detected (avoid cascaded errors)
elsif Errors_Detected /= 0 then
return;
-- Nothing to do if not in full analysis mode
elsif not Full_Analysis then
return;
-- Nothing to do if inside a generic template
elsif Inside_A_Generic then
return;
-- Nothing to do if a library level instantiation
elsif Nkind (Parent (N)) = N_Compilation_Unit then
return;
-- Nothing to do if we are compiling a proper body for semantic
-- purposes only. The generic body may be in another proper body.
elsif
Nkind (Parent (Unit_Declaration_Node (Main_Unit_Entity))) = N_Subunit
then
return;
end if;
Nam := Name (N);
Ent := Entity (Nam);
-- The case we are interested in is when the generic spec is in the
-- current declarative part
if not Same_Elaboration_Scope (Current_Scope, Scope (Ent))
or else not In_Same_Extended_Unit (Sloc (N), Sloc (Ent))
then
return;
end if;
-- If the generic entity is within a deeper instance than we are, then
-- either the instantiation to which we refer itself caused an ABE, in
-- which case that will be handled separately. Otherwise, we know that
-- the body we need appears as needed at the point of the instantiation.
-- If they are both at the same level but not within the same instance
-- then the body of the generic will be in the earlier instance.
declare
D1 : constant Int := Instantiation_Depth (Sloc (Ent));
D2 : constant Int := Instantiation_Depth (Sloc (N));
begin
if D1 > D2 then
return;
elsif D1 = D2
and then Is_Generic_Instance (Scope (Ent))
and then not In_Open_Scopes (Scope (Ent))
then
return;
end if;
end;
-- Now we can proceed, if the entity being called has a completion,
-- then we are definitely OK, since we have already seen the body.
if Has_Completion (Ent) then
return;
end if;
-- If there is no body, then nothing to do
if not Has_Generic_Body (N) then
return;
end if;
-- Here we definitely have a bad instantiation
Error_Msg_NE
("?cannot instantiate& before body seen", N, Ent);
if Present (Instance_Spec (N)) then
Supply_Bodies (Instance_Spec (N));
end if;
Error_Msg_N
("\?Program_Error will be raised at run time", N);
Insert_Elab_Check (N);
Set_ABE_Is_Certain (N);
end Check_Bad_Instantiation;
---------------------
-- Check_Elab_Call --
---------------------
procedure Check_Elab_Call
(N : Node_Id;
Outer_Scope : Entity_Id := Empty)
is
Nam : Node_Id;
Ent : Entity_Id;
P : Node_Id;
begin
-- For an entry call, check relevant restriction
if Nkind (N) = N_Entry_Call_Statement
and then not In_Subprogram_Or_Concurrent_Unit
then
Check_Restriction (No_Entry_Calls_In_Elaboration_Code, N);
-- Nothing to do if this is not a call (happens in some error
-- conditions, and in some cases where rewriting occurs).
elsif Nkind (N) /= N_Function_Call
and then Nkind (N) /= N_Procedure_Call_Statement
then
return;
-- Nothing to do if this is a call already rewritten for elab checking.
elsif Nkind (Parent (N)) = N_Conditional_Expression then
return;
-- Nothing to do if inside a generic template
elsif Inside_A_Generic
and then not Present (Enclosing_Generic_Body (N))
then
return;
end if;
-- Here we have a call at elaboration time which must be checked
if Debug_Flag_LL then
Write_Str (" Check_Elab_Call: ");
if No (Name (N))
or else not Is_Entity_Name (Name (N))
then
Write_Str ("<<not entity name>> ");
else
Write_Name (Chars (Entity (Name (N))));
end if;
Write_Str (" call at ");
Write_Location (Sloc (N));
Write_Eol;
end if;
-- Climb up the tree to make sure we are not inside a
-- default expression of a parameter specification or
-- a record component, since in both these cases, we
-- will be doing the actual call later, not now, and it
-- is at the time of the actual call (statically speaking)
-- that we must do our static check, not at the time of
-- its initial analysis).
P := Parent (N);
while Present (P) loop
if Nkind (P) = N_Parameter_Specification
or else
Nkind (P) = N_Component_Declaration
then
return;
else
P := Parent (P);
end if;
end loop;
-- Stuff that happens only at the outer level
if No (Outer_Scope) then
Elab_Visited.Set_Last (0);
-- Nothing to do if current scope is Standard (this is a bit
-- odd, but it happens in the case of generic instantiations).
C_Scope := Current_Scope;
if C_Scope = Standard_Standard then
return;
end if;
-- First case, we are in elaboration code
From_Elab_Code := not In_Subprogram_Or_Concurrent_Unit;
if From_Elab_Code then
-- Complain if call that comes from source in preelaborated
-- unit and we are not inside a subprogram (i.e. we are in
-- elab code)
if Comes_From_Source (N)
and then In_Preelaborated_Unit
then
Error_Msg_N
("non-static call not allowed in preelaborated unit", N);
return;
end if;
-- Second case, we are inside a subprogram or concurrent unit
-- i.e, we are not in elaboration code.
else
-- In this case, the issue is whether we are inside the
-- declarative part of the unit in which we live, or inside
-- its statements. In the latter case, there is no issue of
-- ABE calls at this level (a call from outside to the unit
-- in which we live might cause an ABE, but that will be
-- detected when we analyze that outer level call, as it
-- recurses into the called unit).
-- Climb up the tree, doing this test, and also testing
-- for being inside a default expression, which, as
-- discussed above, is not checked at this stage.
declare
P : Node_Id;
L : List_Id;
begin
P := N;
loop
-- If we find a parentless subtree, it seems safe to
-- assume that we are not in a declarative part and
-- that no checking is required.
if No (P) then
return;
end if;
if Is_List_Member (P) then
L := List_Containing (P);
P := Parent (L);
else
L := No_List;
P := Parent (P);
end if;
exit when Nkind (P) = N_Subunit;
-- Filter out case of default expressions, where
-- we do not do the check at this stage.
if Nkind (P) = N_Parameter_Specification
or else
Nkind (P) = N_Component_Declaration
then
return;
end if;
if Nkind (P) = N_Subprogram_Body
or else
Nkind (P) = N_Protected_Body
or else
Nkind (P) = N_Task_Body
or else
Nkind (P) = N_Block_Statement
then
if L = Declarations (P) then
exit;
-- We are not in elaboration code, but we are doing
-- dynamic elaboration checks, in this case, we still
-- need to do the call, since the subprogram we are in
-- could be called from another unit, also in dynamic
-- elaboration check mode, at elaboration time.
elsif Dynamic_Elaboration_Checks then
-- This is a rather new check, going into version
-- 3.14a1 for the first time (V1.80 of this unit),
-- so we provide a debug flag to enable it. That
-- way we have an easy work around for regressions
-- that are caused by this new check. This debug
-- flag can be removed later.
if Debug_Flag_DD then
return;
end if;
-- Do the check in this case
exit;
-- Static model, call is not in elaboration code, we
-- never need to worry, because in the static model
-- the top level caller always takes care of things.
else
return;
end if;
end if;
end loop;
end;
end if;
end if;
-- Retrieve called entity. If this is a call to a protected subprogram,
-- the entity is a selected component.
-- The callable entity may be absent, in which case there is nothing
-- to do. This happens with non-analyzed calls in nested generics.
Nam := Name (N);
if No (Nam) then
return;
elsif Nkind (Nam) = N_Selected_Component then
Ent := Entity (Selector_Name (Nam));
elsif not Is_Entity_Name (Nam) then
return;
else
Ent := Entity (Nam);
end if;
if No (Ent) then
return;
end if;
-- Nothing to do if this is a recursive call (i.e. a call to
-- an entity that is already in the Elab_Call stack)
for J in 1 .. Elab_Visited.Last loop
if Ent = Elab_Visited.Table (J) then
return;
end if;
end loop;
-- See if we need to analyze this call. We analyze it if either of
-- the following conditions is met:
-- It is an inner level call (since in this case it was triggered
-- by an outer level call from elaboration code), but only if the
-- call is within the scope of the original outer level call.
-- It is an outer level call from elaboration code, or the called
-- entity is in the same elaboration scope.
-- And in these cases, we will check both inter-unit calls and
-- intra-unit (within a single unit) calls.
C_Scope := Current_Scope;
-- If not outer level call, then we follow it if it is within
-- the original scope of the outer call.
if Present (Outer_Scope)
and then Within (Scope (Ent), Outer_Scope)
then
Set_C_Scope;
Check_A_Call (N, Ent, Outer_Scope, Inter_Unit_Only => False);
elsif Elaboration_Checks_Suppressed (Current_Scope) then
null;
elsif From_Elab_Code then
Set_C_Scope;
Check_A_Call (N, Ent, Standard_Standard, Inter_Unit_Only => False);
elsif Same_Elaboration_Scope (C_Scope, Scope (Ent)) then
Set_C_Scope;
Check_A_Call (N, Ent, Scope (Ent), Inter_Unit_Only => False);
-- If none of those cases holds, but Dynamic_Elaboration_Checks mode
-- is set, then we will do the check, but only in the inter-unit case
-- (this is to accommodate unguarded elaboration calls from other units
-- in which this same mode is set). We don't want warnings in this case,
-- it would generate warnings having nothing to do with elaboration.
elsif Dynamic_Elaboration_Checks then
Set_C_Scope;
Check_A_Call
(N,
Ent,
Standard_Standard,
Inter_Unit_Only => True,
Generate_Warnings => False);
else
return;
end if;
end Check_Elab_Call;
----------------------
-- Check_Elab_Calls --
----------------------
procedure Check_Elab_Calls is
begin
-- If expansion is disabled, do not generate any checks. Also
-- skip checks if any subunits are missing because in either
-- case we lack the full information that we need, and no object
-- file will be created in any case.
if not Expander_Active or else Subunits_Missing then
return;
end if;
-- Skip delayed calls if we had any errors
if Errors_Detected = 0 then
Delaying_Elab_Checks := False;
Expander_Mode_Save_And_Set (True);
for J in Delay_Check.First .. Delay_Check.Last loop
New_Scope (Delay_Check.Table (J).Curscop);
From_Elab_Code := Delay_Check.Table (J).From_Elab_Code;
Check_Internal_Call_Continue (
N => Delay_Check.Table (J).N,
E => Delay_Check.Table (J).E,
Outer_Scope => Delay_Check.Table (J).Outer_Scope,
Orig_Ent => Delay_Check.Table (J).Orig_Ent);
Pop_Scope;
end loop;
-- Set Delaying_Elab_Checks back on for next main compilation
Expander_Mode_Restore;
Delaying_Elab_Checks := True;
end if;
end Check_Elab_Calls;
------------------------------
-- Check_Elab_Instantiation --
------------------------------
procedure Check_Elab_Instantiation
(N : Node_Id;
Outer_Scope : Entity_Id := Empty)
is
Nam : Node_Id;
Ent : Entity_Id;
begin
-- Check for and deal with bad instantiation case. There is some
-- duplicated code here, but we will worry about this later ???
Check_Bad_Instantiation (N);
if ABE_Is_Certain (N) then
return;
end if;
-- Nothing to do if we do not have an instantiation (happens in some
-- error cases, and also in the formal package declaration case)
if Nkind (N) not in N_Generic_Instantiation then
return;
end if;
-- Nothing to do if inside a generic template
if Inside_A_Generic then
return;
end if;
Nam := Name (N);
Ent := Entity (Nam);
From_Elab_Code := not In_Subprogram_Or_Concurrent_Unit;
-- See if we need to analyze this instantiation. We analyze it if
-- either of the following conditions is met:
-- It is an inner level instantiation (since in this case it was
-- triggered by an outer level call from elaboration code), but
-- only if the instantiation is within the scope of the original
-- outer level call.
-- It is an outer level instantiation from elaboration code, or the
-- instantiated entity is in the same elaboratoin scope.
-- And in these cases, we will check both the inter-unit case and
-- the intra-unit (within a single unit) case.
C_Scope := Current_Scope;
if Present (Outer_Scope)
and then Within (Scope (Ent), Outer_Scope)
then
Set_C_Scope;
Check_A_Call (N, Ent, Outer_Scope, Inter_Unit_Only => False);
elsif From_Elab_Code then
Set_C_Scope;
Check_A_Call (N, Ent, Standard_Standard, Inter_Unit_Only => False);
elsif Same_Elaboration_Scope (C_Scope, Scope (Ent)) then
Set_C_Scope;
Check_A_Call (N, Ent, Scope (Ent), Inter_Unit_Only => False);
-- If none of those cases holds, but Dynamic_Elaboration_Checks mode
-- is set, then we will do the check, but only in the inter-unit case
-- (this is to accommodate unguarded elaboration calls from other units
-- in which this same mode is set). We inhibit warnings in this case,
-- since this instantiation is not occurring in elaboration code.
elsif Dynamic_Elaboration_Checks then
Set_C_Scope;
Check_A_Call
(N,
Ent,
Standard_Standard,
Inter_Unit_Only => True,
Generate_Warnings => False);
else
return;
end if;
end Check_Elab_Instantiation;
-------------------------
-- Check_Internal_Call --
-------------------------
procedure Check_Internal_Call
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Orig_Ent : Entity_Id)
is
Inst_Case : constant Boolean := Nkind (N) in N_Generic_Instantiation;
begin
-- If not function or procedure call or instantiation, then ignore
-- call (this happens in some error case and rewriting cases)
if Nkind (N) /= N_Function_Call
and then
Nkind (N) /= N_Procedure_Call_Statement
and then
not Inst_Case
then
return;
-- Nothing to do if this is a call or instantiation that has
-- already been found to be a sure ABE
elsif ABE_Is_Certain (N) then
return;
-- Nothing to do if errors already detected (avoid cascaded errors)
elsif Errors_Detected /= 0 then
return;
-- Nothing to do if not in full analysis mode
elsif not Full_Analysis then
return;
-- Nothing to do if within a default expression, since the call
-- is not actualy being made at this time.
elsif In_Default_Expression then
return;
-- Nothing to do for call to intrinsic subprogram
elsif Is_Intrinsic_Subprogram (E) then
return;
-- No need to trace local calls if checking task activation, because
-- other local bodies are elaborated already.
elsif In_Task_Activation then
return;
end if;
-- Delay this call if we are still delaying calls
if Delaying_Elab_Checks then
Delay_Check.Increment_Last;
Delay_Check.Table (Delay_Check.Last) :=
(N => N,
E => E,
Orig_Ent => Orig_Ent,
Curscop => Current_Scope,
Outer_Scope => Outer_Scope,
From_Elab_Code => From_Elab_Code);
return;
-- Otherwise, call phase 2 continuation right now
else
Check_Internal_Call_Continue (N, E, Outer_Scope, Orig_Ent);
end if;
end Check_Internal_Call;
----------------------------------
-- Check_Internal_Call_Continue --
----------------------------------
procedure Check_Internal_Call_Continue
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Orig_Ent : Entity_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Inst_Case : constant Boolean := Is_Generic_Unit (E);
Sbody : Node_Id;
Ebody : Entity_Id;
function Process (N : Node_Id) return Traverse_Result;
-- Function applied to each node as we traverse the body.
-- Checks for call that needs checking, and if so checks
-- it. Always returns OK, so entire tree is traversed.
function Process (N : Node_Id) return Traverse_Result is
begin
-- If user has specified that there are no entry calls in elaboration
-- code, do not trace past an accept statement, because the rendez-
-- vous will happen after elaboration.
if (Nkind (Original_Node (N)) = N_Accept_Statement
or else Nkind (Original_Node (N)) = N_Selective_Accept)
and then Restrictions (No_Entry_Calls_In_Elaboration_Code)
then
return Abandon;
-- If we have a subprogram call, check it
elsif Nkind (N) = N_Function_Call
or else Nkind (N) = N_Procedure_Call_Statement
then
Check_Elab_Call (N, Outer_Scope);
return OK;
-- If we have a generic instantiation, check it
elsif Nkind (N) in N_Generic_Instantiation then
Check_Elab_Instantiation (N, Outer_Scope);
return OK;
-- Skip subprogram bodies that come from source (wait for
-- call to analyze these). The reason for the come from
-- source test is to avoid catching task bodies.
-- For task bodies, we should really avoid these too, waiting
-- for the task activation, but that's too much trouble to
-- catch for now, so we go in unconditionally. This is not
-- so terrible, it means the error backtrace is not quite
-- complete, and we are too eager to scan bodies of tasks
-- that are unused, but this is hardly very significant!
elsif Nkind (N) = N_Subprogram_Body
and then Comes_From_Source (N)
then
return Skip;
else
return OK;
end if;
end Process;
procedure Traverse is new Atree.Traverse_Proc;
-- Traverse procedure using above Process function
-- Start of processing for Check_Internal_Call_Continue
begin
-- Save outer level call if at outer level
if Elab_Call.Last = 0 then
Outer_Level_Sloc := Loc;
end if;
Elab_Visited.Increment_Last;
Elab_Visited.Table (Elab_Visited.Last) := E;
-- If the call is to a function that renames a literal, no check
-- is needed.
if Ekind (E) = E_Enumeration_Literal then
return;
end if;
Sbody := Unit_Declaration_Node (E);
if Nkind (Sbody) /= N_Subprogram_Body
and then
Nkind (Sbody) /= N_Package_Body
then
Ebody := Corresponding_Body (Sbody);
if No (Ebody) then
return;
else
Sbody := Unit_Declaration_Node (Ebody);
end if;
end if;
-- If the body appears after the outer level call or
-- instantiation then we have an error case handled below.
if Earlier_In_Extended_Unit (Outer_Level_Sloc, Sloc (Sbody))
and then not In_Task_Activation
then
null;
-- If we have the instantiation case we are done, since we now
-- know that the body of the generic appeared earlier.
elsif Inst_Case then
return;
-- Otherwise we have a call, so we trace through the called
-- body to see if it has any problems ..
else
pragma Assert (Nkind (Sbody) = N_Subprogram_Body);
Elab_Call.Increment_Last;
Elab_Call.Table (Elab_Call.Last).Cloc := Loc;
Elab_Call.Table (Elab_Call.Last).Ent := E;
if Debug_Flag_LL then
Write_Str ("Elab_Call.Last = ");
Write_Int (Int (Elab_Call.Last));
Write_Str (" Ent = ");
Write_Name (Chars (E));
Write_Str (" at ");
Write_Location (Sloc (N));
Write_Eol;
end if;
-- Now traverse declarations and statements of subprogram body.
-- Note that we cannot simply Traverse (Sbody), since traverse
-- does not normally visit subprogram bodies.
declare
Decl : Node_Id := First (Declarations (Sbody));
begin
while Present (Decl) loop
Traverse (Decl);
Next (Decl);
end loop;
end;
Traverse (Handled_Statement_Sequence (Sbody));
Elab_Call.Decrement_Last;
return;
end if;
-- Here is the case of calling a subprogram where the body has
-- not yet been encountered, a warning message is needed.
Warn_On_Instance := True;
-- If we have nothing in the call stack, then this is at the
-- outer level, and the ABE is bound to occur.
if Elab_Call.Last = 0 then
if Inst_Case then
Error_Msg_NE
("?cannot instantiate& before body seen", N, Orig_Ent);
else
Error_Msg_NE
("?cannot call& before body seen", N, Orig_Ent);
end if;
Error_Msg_N
("\?Program_Error will be raised at run time", N);
Insert_Elab_Check (N);
-- Call is not at outer level
else
-- Deal with dynamic elaboration check
if not Elaboration_Checks_Suppressed (E) then
Set_Elaboration_Entity_Required (E);
-- Case of no elaboration entity allocated yet
if No (Elaboration_Entity (E)) then
-- Create object declaration for elaboration entity, and put it
-- just in front of the spec of the subprogram or generic unit,
-- in the same scope as this unit.
declare
Loce : constant Source_Ptr := Sloc (E);
Ent : constant Entity_Id :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Chars (E), 'E'));
begin
Set_Elaboration_Entity (E, Ent);
New_Scope (Scope (E));
Insert_Action (Declaration_Node (E),
Make_Object_Declaration (Loce,
Defining_Identifier => Ent,
Object_Definition =>
New_Occurrence_Of (Standard_Boolean, Loce),
Expression => New_Occurrence_Of (Standard_False, Loce)));
-- Set elaboration flag at the point of the body
Set_Elaboration_Flag (Sbody, E);
Pop_Scope;
end;
end if;
-- Generate check of the elaboration Boolean
Insert_Elab_Check (N,
New_Occurrence_Of (Elaboration_Entity (E), Loc));
end if;
-- Generate the warning
if not Suppress_Elaboration_Warnings (E) then
if Inst_Case then
Error_Msg_NE
("instantiation of& may occur before body is seen?",
N, Orig_Ent);
else
Error_Msg_NE
("call to& may occur before body is seen?", N, Orig_Ent);
end if;
Error_Msg_N
("\Program_Error may be raised at run time?", N);
Output_Calls (N);
end if;
end if;
Warn_On_Instance := False;
-- Set flag to suppress further warnings on same subprogram
-- unless in all errors mode
if not All_Errors_Mode then
Set_Suppress_Elaboration_Warnings (E);
end if;
end Check_Internal_Call_Continue;
----------------------------
-- Check_Task_Activation --
----------------------------
procedure Check_Task_Activation (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Ent : Entity_Id;
P : Entity_Id;
Task_Scope : Entity_Id;
Cunit_SC : Boolean := False;
Decl : Node_Id;
Elmt : Elmt_Id;
Inter_Procs : Elist_Id := New_Elmt_List;
Intra_Procs : Elist_Id := New_Elmt_List;
Enclosing : Entity_Id;
procedure Add_Task_Proc (Typ : Entity_Id);
-- Add to Task_Procs the task body procedure(s) of task types in Typ.
-- For record types, this procedure recurses over component types.
procedure Collect_Tasks (Decls : List_Id);
-- Collect the types of the tasks that are to be activated in the given
-- list of declarations, in order to perform elaboration checks on the
-- corresponding task procedures which are called implicitly here.
function Outer_Unit (E : Entity_Id) return Entity_Id;
-- find enclosing compilation unit of Entity, ignoring subunits, or
-- else enclosing subprogram. If E is not a package, there is no need
-- for inter-unit elaboration checks.
-------------------
-- Add_Task_Proc --
-------------------
procedure Add_Task_Proc (Typ : Entity_Id) is
Comp : Entity_Id;
Proc : Entity_Id := Empty;
begin
if Is_Task_Type (Typ) then
Proc := Get_Task_Body_Procedure (Typ);
elsif Is_Array_Type (Typ)
and then Has_Task (Base_Type (Typ))
then
Add_Task_Proc (Component_Type (Typ));
elsif Is_Record_Type (Typ)
and then Has_Task (Base_Type (Typ))
then
Comp := First_Component (Typ);
while Present (Comp) loop
Add_Task_Proc (Etype (Comp));
Comp := Next_Component (Comp);
end loop;
end if;
-- If the task type is another unit, we will perform the usual
-- elaboration check on its enclosing unit. If the type is in the
-- same unit, we can trace the task body as for an internal call,
-- but we only need to examine other external calls, because at
-- the point the task is activated, internal subprogram bodies
-- will have been elaborated already. We keep separate lists for
-- each kind of task.
if Present (Proc) then
if Outer_Unit (Scope (Proc)) = Enclosing then
if No (Corresponding_Body (Unit_Declaration_Node (Proc)))
and then
(not Is_Generic_Instance (Scope (Proc))
or else
Scope (Proc) = Scope (Defining_Identifier (Decl)))
then
Error_Msg_N
("task will be activated before elaboration of its body?",
Decl);
Error_Msg_N
("Program_Error will be raised at run-time?", Decl);
elsif
Present (Corresponding_Body (Unit_Declaration_Node (Proc)))
then
Append_Elmt (Proc, Intra_Procs);
end if;
else
Elmt := First_Elmt (Inter_Procs);
-- No need for multiple entries of the same type.
while Present (Elmt) loop
if Node (Elmt) = Proc then
return;
end if;
Next_Elmt (Elmt);
end loop;
Append_Elmt (Proc, Inter_Procs);
end if;
end if;
end Add_Task_Proc;
-------------------
-- Collect_Tasks --
-------------------
procedure Collect_Tasks (Decls : List_Id) is
begin
if Present (Decls) then
Decl := First (Decls);
while Present (Decl) loop
if Nkind (Decl) = N_Object_Declaration
and then Has_Task (Etype (Defining_Identifier (Decl)))
then
Add_Task_Proc (Etype (Defining_Identifier (Decl)));
end if;
Next (Decl);
end loop;
end if;
end Collect_Tasks;
----------------
-- Outer_Unit --
----------------
function Outer_Unit (E : Entity_Id) return Entity_Id is
Outer : Entity_Id := E;
begin
while Present (Outer) loop
if Suppress_Elaboration_Checks (Outer) then
Cunit_SC := True;
end if;
exit when Is_Child_Unit (Outer)
or else Scope (Outer) = Standard_Standard
or else Ekind (Outer) /= E_Package;
Outer := Scope (Outer);
end loop;
return Outer;
end Outer_Unit;
-- Start of processing for Check_Task_Activation
begin
Enclosing := Outer_Unit (Current_Scope);
-- Find all tasks declared in the current unit.
if Nkind (N) = N_Package_Body then
P := Unit_Declaration_Node (Corresponding_Spec (N));
Collect_Tasks (Declarations (N));
Collect_Tasks (Visible_Declarations (Specification (P)));
Collect_Tasks (Private_Declarations (Specification (P)));
elsif Nkind (N) = N_Package_Declaration then
Collect_Tasks (Visible_Declarations (Specification (N)));
Collect_Tasks (Private_Declarations (Specification (N)));
else
Collect_Tasks (Declarations (N));
end if;
-- We only perform detailed checks in all tasks are library level
-- entities. If the master is a subprogram or task, activation will
-- depend on the activation of the master itself.
-- Should dynamic checks be added in the more general case???
if Ekind (Enclosing) /= E_Package then
return;
end if;
-- For task types defined in other units, we want the unit containing
-- the task body to be elaborated before the current one.
Elmt := First_Elmt (Inter_Procs);
while Present (Elmt) loop
Ent := Node (Elmt);
Task_Scope := Outer_Unit (Scope (Ent));
if not Is_Compilation_Unit (Task_Scope) then
null;
elsif Suppress_Elaboration_Warnings (Task_Scope) then
null;
elsif Dynamic_Elaboration_Checks then
if not Elaboration_Checks_Suppressed (Ent)
and then not Cunit_SC
and then not Restrictions (No_Entry_Calls_In_Elaboration_Code)
then
-- Runtime elaboration check required. generate check of the
-- elaboration Boolean for the unit containing the entity.
Insert_Elab_Check (N,
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Elaborated,
Prefix =>
New_Occurrence_Of
(Spec_Entity (Task_Scope), Loc)));
end if;
else
-- Force the binder to elaborate other unit first.
if not Suppress_Elaboration_Warnings (Ent)
and then Elab_Warnings
and then not Suppress_Elaboration_Warnings (Task_Scope)
then
Error_Msg_Node_2 := Task_Scope;
Error_Msg_NE ("activation of an instance of task type&" &
" requires pragma Elaborate_All on &?", N, Ent);
end if;
Set_Elaborate_All_Desirable (Task_Scope);
Set_Suppress_Elaboration_Warnings (Task_Scope);
end if;
Next_Elmt (Elmt);
end loop;
-- For tasks declared in the current unit, trace other calls within
-- the task procedure bodies, which are available.
In_Task_Activation := True;
Elmt := First_Elmt (Intra_Procs);
while Present (Elmt) loop
Ent := Node (Elmt);
Check_Internal_Call_Continue (N, Ent, Enclosing, Ent);
Next_Elmt (Elmt);
end loop;
In_Task_Activation := False;
end Check_Task_Activation;
----------------------
-- Has_Generic_Body --
----------------------
function Has_Generic_Body (N : Node_Id) return Boolean is
Ent : constant Entity_Id := Entity (Name (N));
Decl : constant Node_Id := Unit_Declaration_Node (Ent);
Scop : Entity_Id;
function Find_Body_In (E : Entity_Id; N : Node_Id) return Node_Id;
-- Determine if the list of nodes headed by N and linked by Next
-- contains a package body for the package spec entity E, and if
-- so return the package body. If not, then returns Empty.
function Load_Package_Body (Nam : Unit_Name_Type) return Node_Id;
-- This procedure is called load the unit whose name is given by Nam.
-- This unit is being loaded to see whether it contains an optional
-- generic body. The returned value is the loaded unit, which is
-- always a package body (only package bodies can contain other
-- entities in the sense in which Has_Generic_Body is interested).
-- We only attempt to load bodies if we are generating code. If we
-- are in semantics check only mode, then it would be wrong to load
-- bodies that are not required from a semantic point of view, so
-- in this case we return Empty. The result is that the caller may
-- incorrectly decide that a generic spec does not have a body when
-- in fact it does, but the only harm in this is that some warnings
-- on elaboration problems may be lost in semantic checks only mode,
-- which is not big loss. We also return Empty if we go for a body
-- and it is not there.
function Locate_Corresponding_Body (PE : Entity_Id) return Node_Id;
-- PE is the entity for a package spec. This function locates the
-- corresponding package body, returning Empty if none is found.
-- The package body returned is fully parsed but may not yet be
-- analyzed, so only syntactic fields should be referenced.
------------------
-- Find_Body_In --
------------------
function Find_Body_In (E : Entity_Id; N : Node_Id) return Node_Id is
Nod : Node_Id;
begin
Nod := N;
while Present (Nod) loop
-- If we found the package body we are looking for, return it
if Nkind (Nod) = N_Package_Body
and then Chars (Defining_Unit_Name (Nod)) = Chars (E)
then
return Nod;
-- If we found the stub for the body, go after the subunit,
-- loading it if necessary.
elsif Nkind (Nod) = N_Package_Body_Stub
and then Chars (Defining_Identifier (Nod)) = Chars (E)
then
if Present (Library_Unit (Nod)) then
return Unit (Library_Unit (Nod));
else
return Load_Package_Body (Get_Unit_Name (Nod));
end if;
-- If neither package body nor stub, keep looking on chain
else
Next (Nod);
end if;
end loop;
return Empty;
end Find_Body_In;
-----------------------
-- Load_Package_Body --
-----------------------
function Load_Package_Body (Nam : Unit_Name_Type) return Node_Id is
U : Unit_Number_Type;
begin
if Operating_Mode /= Generate_Code then
return Empty;
else
U :=
Load_Unit
(Load_Name => Nam,
Required => False,
Subunit => False,
Error_Node => N);
if U = No_Unit then
return Empty;
else
return Unit (Cunit (U));
end if;
end if;
end Load_Package_Body;
-------------------------------
-- Locate_Corresponding_Body --
-------------------------------
function Locate_Corresponding_Body (PE : Entity_Id) return Node_Id is
Spec : constant Node_Id := Declaration_Node (PE);
Decl : constant Node_Id := Parent (Spec);
Scop : constant Entity_Id := Scope (PE);
PBody : Node_Id;
begin
if Is_Library_Level_Entity (PE) then
-- If package is a library unit that requires a body, we have
-- no choice but to go after that body because it might contain
-- an optional body for the original generic package.
if Unit_Requires_Body (PE) then
-- Load the body. Note that we are a little careful here to
-- use Spec to get the unit number, rather than PE or Decl,
-- since in the case where the package is itself a library
-- level instantiation, Spec will properly reference the
-- generic template, which is what we really want.
return
Load_Package_Body
(Get_Body_Name (Unit_Name (Get_Source_Unit (Spec))));
-- But if the package is a library unit that does NOT require
-- a body, then no body is permitted, so we are sure that there
-- is no body for the original generic package.
else
return Empty;
end if;
-- Otherwise look and see if we are embedded in a further package
elsif Is_Package (Scop) then
-- If so, get the body of the enclosing package, and look in
-- its package body for the package body we are looking for.
PBody := Locate_Corresponding_Body (Scop);
if No (PBody) then
return Empty;
else
return Find_Body_In (PE, First (Declarations (PBody)));
end if;
-- If we are not embedded in a further package, then the body
-- must be in the same declarative part as we are.
else
return Find_Body_In (PE, Next (Decl));
end if;
end Locate_Corresponding_Body;
-- Start of processing for Has_Generic_Body
begin
if Present (Corresponding_Body (Decl)) then
return True;
elsif Unit_Requires_Body (Ent) then
return True;
-- Compilation units cannot have optional bodies
elsif Is_Compilation_Unit (Ent) then
return False;
-- Otherwise look at what scope we are in
else
Scop := Scope (Ent);
-- Case of entity is in other than a package spec, in this case
-- the body, if present, must be in the same declarative part.
if not Is_Package (Scop) then
declare
P : Node_Id;
begin
P := Declaration_Node (Ent);
-- Declaration node may get us a spec, so if so, go to
-- the parent declaration.
while not Is_List_Member (P) loop
P := Parent (P);
end loop;
return Present (Find_Body_In (Ent, Next (P)));
end;
-- If the entity is in a package spec, then we have to locate
-- the corresponding package body, and look there.
else
declare
PBody : constant Node_Id := Locate_Corresponding_Body (Scop);
begin
if No (PBody) then
return False;
else
return
Present
(Find_Body_In (Ent, (First (Declarations (PBody)))));
end if;
end;
end if;
end if;
end Has_Generic_Body;
-----------------------
-- Insert_Elab_Check --
-----------------------
procedure Insert_Elab_Check (N : Node_Id; C : Node_Id := Empty) is
Nod : Node_Id;
Loc : constant Source_Ptr := Sloc (N);
begin
-- If expansion is disabled, do not generate any checks. Also
-- skip checks if any subunits are missing because in either
-- case we lack the full information that we need, and no object
-- file will be created in any case.
if not Expander_Active or else Subunits_Missing then
return;
end if;
-- If we have a generic instantiation, where Instance_Spec is set,
-- then this field points to a generic instance spec that has
-- been inserted before the instantiation node itself, so that
-- is where we want to insert a check.
if Nkind (N) in N_Generic_Instantiation
and then Present (Instance_Spec (N))
then
Nod := Instance_Spec (N);
else
Nod := N;
end if;
-- If we are inserting at the top level, insert in Aux_Decls
if Nkind (Parent (Nod)) = N_Compilation_Unit then
declare
ADN : constant Node_Id := Aux_Decls_Node (Parent (Nod));
R : Node_Id;
begin
if No (C) then
R := Make_Raise_Program_Error (Loc);
else
R := Make_Raise_Program_Error (Loc, Make_Op_Not (Loc, C));
end if;
if No (Declarations (ADN)) then
Set_Declarations (ADN, New_List (R));
else
Append_To (Declarations (ADN), R);
end if;
Analyze (R);
end;
-- Otherwise just insert before the node in question. However, if
-- the context of the call has already been analyzed, an insertion
-- will not work if it depends on subsequent expansion (e.g. a call in
-- a branch of a short-circuit). In that case we replace the call with
-- a conditional expression, or with a Raise if it is unconditional.
-- Unfortunately this does not work if the call has a dynamic size,
-- because gigi regards it as a dynamic-sized temporary. If such a call
-- appears in a short-circuit expression, the elaboration check will be
-- missed (rare enough ???).
else
if Nkind (N) = N_Function_Call
and then Analyzed (Parent (N))
and then Size_Known_At_Compile_Time (Etype (N))
then
declare
Typ : constant Entity_Id := Etype (N);
R : constant Node_Id := Make_Raise_Program_Error (Loc);
Chk : constant Boolean := Do_Range_Check (N);
begin
Set_Etype (R, Typ);
if No (C) then
Rewrite (N, R);
else
Rewrite (N,
Make_Conditional_Expression (Loc,
Expressions => New_List (C, Relocate_Node (N), R)));
end if;
Analyze_And_Resolve (N, Typ);
-- If the original call requires a range check, so does the
-- conditional expression.
if Chk then
Enable_Range_Check (N);
else
Set_Do_Range_Check (N, False);
end if;
end;
else
if No (C) then
Insert_Action (Nod,
Make_Raise_Program_Error (Loc));
else
Insert_Action (Nod,
Make_Raise_Program_Error (Loc,
Condition =>
Make_Op_Not (Loc,
Right_Opnd => C)));
end if;
end if;
end if;
end Insert_Elab_Check;
------------------
-- Output_Calls --
------------------
procedure Output_Calls (N : Node_Id) is
Ent : Entity_Id;
function Is_Printable_Error_Name (Nm : Name_Id) return Boolean;
-- An internal function, used to determine if a name, Nm, is either
-- a non-internal name, or is an internal name that is printable
-- by the error message circuits (i.e. it has a single upper
-- case letter at the end).
function Is_Printable_Error_Name (Nm : Name_Id) return Boolean is
begin
if not Is_Internal_Name (Nm) then
return True;
elsif Name_Len = 1 then
return False;
else
Name_Len := Name_Len - 1;
return not Is_Internal_Name;
end if;
end Is_Printable_Error_Name;
-- Start of processing for Output_Calls
begin
for J in reverse 1 .. Elab_Call.Last loop
Error_Msg_Sloc := Elab_Call.Table (J).Cloc;
Ent := Elab_Call.Table (J).Ent;
if Is_Generic_Unit (Ent) then
Error_Msg_NE ("\?& instantiated #", N, Ent);
elsif Chars (Ent) = Name_uInit_Proc then
Error_Msg_N ("\?initialization procedure called #", N);
elsif Is_Printable_Error_Name (Chars (Ent)) then
Error_Msg_NE ("\?& called #", N, Ent);
else
Error_Msg_N ("\? called #", N);
end if;
end loop;
end Output_Calls;
----------------------------
-- Same_Elaboration_Scope --
----------------------------
function Same_Elaboration_Scope (Scop1, Scop2 : Entity_Id) return Boolean is
S1 : Entity_Id := Scop1;
S2 : Entity_Id := Scop2;
begin
while S1 /= Standard_Standard
and then (Ekind (S1) = E_Package
or else
Ekind (S1) = E_Block)
loop
S1 := Scope (S1);
end loop;
while S2 /= Standard_Standard
and then (Ekind (S2) = E_Package
or else
Ekind (S2) = E_Protected_Type
or else
Ekind (S2) = E_Block)
loop
S2 := Scope (S2);
end loop;
return S1 = S2;
end Same_Elaboration_Scope;
-----------------
-- Set_C_Scope --
-----------------
procedure Set_C_Scope is
begin
while not Is_Compilation_Unit (C_Scope) loop
C_Scope := Scope (C_Scope);
end loop;
end Set_C_Scope;
-----------------
-- Spec_Entity --
-----------------
function Spec_Entity (E : Entity_Id) return Entity_Id is
Decl : Node_Id;
begin
-- Check for case of body entity
-- Why is the check for E_Void needed???
if Ekind (E) = E_Void
or else Ekind (E) = E_Subprogram_Body
or else Ekind (E) = E_Package_Body
then
Decl := E;
loop
Decl := Parent (Decl);
exit when Nkind (Decl) in N_Proper_Body;
end loop;
return Corresponding_Spec (Decl);
else
return E;
end if;
end Spec_Entity;
-------------------
-- Supply_Bodies --
-------------------
procedure Supply_Bodies (N : Node_Id) is
begin
if Nkind (N) = N_Subprogram_Declaration then
declare
Ent : constant Entity_Id := Defining_Unit_Name (Specification (N));
begin
Set_Is_Imported (Ent);
Set_Convention (Ent, Convention_Stubbed);
end;
elsif Nkind (N) = N_Package_Declaration then
declare
Spec : constant Node_Id := Specification (N);
begin
New_Scope (Defining_Unit_Name (Spec));
Supply_Bodies (Visible_Declarations (Spec));
Supply_Bodies (Private_Declarations (Spec));
Pop_Scope;
end;
end if;
end Supply_Bodies;
procedure Supply_Bodies (L : List_Id) is
Elmt : Node_Id;
begin
if Present (L) then
Elmt := First (L);
while Present (Elmt) loop
Supply_Bodies (Elmt);
Next (Elmt);
end loop;
end if;
end Supply_Bodies;
------------
-- Within --
------------
function Within (E1, E2 : Entity_Id) return Boolean is
Scop : Entity_Id;
begin
Scop := E1;
loop
if Scop = E2 then
return True;
elsif Scop = Standard_Standard then
return False;
else
Scop := Scope (Scop);
end if;
end loop;
raise Program_Error;
end Within;
end Sem_Elab;
|
with Big_Integers; use Big_Integers;
with Conversion; use Conversion;
with Types; use Types;
package Multiply_Proof with
SPARK_Mode,
Ghost
is
pragma Annotate (GNATprove, Terminating, Multiply_Proof);
-------------------------------
-- Partial_Product functions --
-------------------------------
-- These functions will be used to follow the value of Product
-- within the loop.
function Partial_Product_Rec
(X, Y : Integer_255;
J, K : Index_Type)
return Long_Long_Integer
is
(if K = 9 or else J = 0
then (if J mod 2 = 1 and then K mod 2 = 1 then 2 else 1) * X (J) * Y (K)
else Partial_Product_Rec (X, Y, J - 1, K + 1)
+ (if J mod 2 = 1 and then K mod 2 = 1 then 2 else 1) * X (J) * Y (K))
with
Pre => All_In_Range (X, Y, Min_Multiply, Max_Multiply),
Post =>
Partial_Product_Rec'Result in
(-2) * Long_Long_Integer (J + 1) * (2**27 - 1)**2
..
2 * Long_Long_Integer (J + 1) * (2**27 - 1)**2;
-- Function used to represent Product (J + K) within the loop.
-- Product (J + K) = Partial_Product_Rec (X, Y, J, K) is a loop
-- invariant.
function Partial_Product
(X, Y : Integer_255;
J, K : Index_Type)
return Long_Long_Integer
is
(Partial_Product_Rec (X, Y, J, K))
with
Pre => All_In_Range (X, Y, Min_Multiply, Max_Multiply),
Post =>
Partial_Product'Result in
(-2) * Long_Long_Integer (J + 1) * (2**27 - 1)**2
..
2 * Long_Long_Integer (J + 1) * (2**27 - 1)**2;
-- Wrapper for recursive function Partial_Product_Rec
function Partial_Product
(X, Y : Integer_255;
L : Product_Index_Type)
return Long_Long_Integer
is
(Partial_Product
(X, Y, Index_Type'Min (L, 9), Index_Type'Max (0, L - 9)))
with
Pre => All_In_Range (X, Y, Min_Multiply, Max_Multiply),
Post =>
Partial_Product'Result in
(-20) * (2**27 - 1)**2
..
20 * (2**27 - 1)**2;
-- Value of Product (L) at the end of the two loops
procedure Partial_Product_Def
(X, Y : Integer_255;
J, K : Index_Type)
with
Pre => All_In_Range (X, Y, Min_Multiply, Max_Multiply),
Post =>
(if K = 9 or else J = 0
then Partial_Product (X, Y, J, K)
= (if J mod 2 = 1 and then K mod 2 = 1 then 2 else 1)
* X (J) * Y (K)
else Partial_Product (X, Y, J, K)
= Partial_Product (X, Y, J - 1, K + 1)
+ X (J) * Y (K)
* (if J mod 2 = 1 and then K mod 2 = 1 then 2 else 1));
procedure Partial_Product_Def
(X, Y : Integer_255;
J, K : Index_Type)
is null;
-- This procedure is sometimes needed to remind the expression of
-- Partial_Product to solvers.
-----------------------------------------------
-- Array_Step_J functions and related lemmas --
-----------------------------------------------
function Array_Step_J
(X, Y : Integer_255;
J : Index_Type)
return Integer_Curve25519
with
Pre => All_In_Range (X, Y, Min_Multiply, Max_Multiply),
Post =>
Array_Step_J'Result'First = 0
and then Array_Step_J'Result'Last = J + 9
and then (for all K in 0 .. J =>
Array_Step_J'Result (K) = Partial_Product (X, Y, K))
and then (for all K in J + 1 .. J + 9 =>
Array_Step_J'Result (K) = Partial_Product (X, Y, J, K - J));
-- Array_Step_J is equal to Product at the end of loo
-------------------------------------
-- Diff_Step_J and other functions --
-------------------------------------
function Diff_Step_J
(X, Y : Integer_255;
J, K : Index_Type)
return Big_Integer
is
(if K = 0
then (+X (J) * Y (K)) * Conversion_Array (J + K)
else Diff_Step_J (X, Y, J, K - 1)
+ (+(if J mod 2 = 1 and then K mod 2 = 1 then 2 else 1))
* (+X (J) * Y (K))
* Conversion_Array (J + K));
-- Diff_Step_J_Rec is equal to
-- Partial_Conversion (Array_Step_J (X, Y, J), J + K)
-- - Partial_Conversion (Array_Step_J (X, Y, J - 1), J + K),
-- i.e it is equal to the big integer added to Product in loop J
procedure Diff_Step_J_Def (X, Y : Integer_255; J, K : Index_Type) with
Post =>
Diff_Step_J (X, Y, J, K)
= (if K = 0
then (+X (J) * Y (K)) * Conversion_Array (J + K)
else Diff_Step_J (X, Y, J, K - 1)
+ (+(if J mod 2 = 1 and then K mod 2 = 1 then 2 else 1))
* (+X (J) * Y (K))
* Conversion_Array (J + K));
procedure Diff_Step_J_Def (X, Y : Integer_255; J, K : Index_Type) is null;
-- This procedure is sometimes needed to remind the expression of
-- Diff_Step_J to solvers.
function Add_Factor
(Product : Big_Integer;
X, Y : Integer_255;
J, K : Index_Type)
return Big_Integer
is
(Product + (+X (J))
* (+Y (K))
* (+(if J mod 2 = 1 and then K mod 2 = 1 then 2 else 1))
* Conversion_Array (J + K));
-- Add_Factor adds the J-K factor to a big integer
procedure Array_Step_J_To_Next
(Product_Conversion : Big_Integer;
X, Y : Integer_255;
J : Index_Type)
with
Pre =>
All_In_Range (X, Y, Min_Multiply, Max_Multiply)
and then
Product_Conversion
= (if J = 0 then Zero else Partial_Conversion (Array_Step_J (X, Y, J - 1), J + 8))
+ Diff_Step_J (X, Y, J, 9),
Post => Product_Conversion = Partial_Conversion (Array_Step_J (X, Y, J), J + 9);
-- Array_Step_J_To_Next is the definition of Diff_Step_J, that allows to
-- obtain Partial_Conversion (Array_Step_J (X, Y, J), J + 9) from
-- Partial_Conversion (Array_Step_J (X, Y, J - 1), J + 8) and
-- Diff_Step_J (X, Y, J, 9).
procedure Array_Diff_Lemma
(Previous, Conversion : Big_Integer;
X, Y : Integer_255;
J, K : Index_Type)
with
Pre =>
All_In_Range (X, Y, Min_Multiply, Max_Multiply)
and then J > 0
and then
Previous
= Partial_Conversion (Array_Step_J (X, Y, J - 1), J + K - 1)
+ (if K = 0 then Zero else Diff_Step_J (X, Y, J, K - 1))
and then
Conversion
= Previous
+ (+Array_Step_J (X, Y, J) (J + K)) * Conversion_Array (J + K),
Contract_Cases =>
(K < 9 =>
Conversion
= Partial_Conversion (Array_Step_J (X, Y, J - 1), J + K)
+ Diff_Step_J (X, Y, J, K),
K = 9 =>
Conversion
= Partial_Conversion (Array_Step_J (X, Y, J - 1), J + 8)
+ Diff_Step_J (X, Y, J, 9));
-- Array_Diff_Lemma establishes a link between Array_Step_J (X, Y, J - 1)
-- and Array_Step_J (X, Y, J) via Partial_Conversion and Diff_Step_J.
----------------------
-- Other procedures --
----------------------
procedure Split_Product
(Old_Product, Old_X, Product_Conversion : Big_Integer;
X, Y : Integer_255;
J, K : Index_Type)
with
Pre =>
(if K = 0
then Old_Product = Old_X * (+Y)
else Old_Product
= Old_X * (+Y)
+ (+X (J)) * Conversion_Array (J) * Partial_Conversion (Y, K - 1))
and then
Product_Conversion
= Old_Product
+ (+X (J)) * (+Y (K))
* (+(if J mod 2 = 1 and then K mod 2 = 1 then 2 else 1))
* Conversion_Array (J + K),
Post =>
Product_Conversion
= Old_X * (+Y)
+ (+X (J)) * Conversion_Array (J)
* Partial_Conversion (Y, K);
-- This function splits the conversion of factor J-K into conversion
-- of factor J and K in X and Y respectively.
procedure Prove_Multiply
(X, Y : Integer_255;
Product : Product_Integer)
with
Pre =>
All_In_Range (X, Y, Min_Multiply, Max_Multiply)
and then Product = Array_Step_J (X, Y, 9),
Post => (+Product) = (+X) * (+Y);
-- Proves the property of Multiply for Final_Array
end Multiply_Proof;
|
with Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package body Bag is
package TIO renames Ada.Text_IO;
function "<" (Left, Right : Bag_Combo) return Boolean is
begin
return Left.Color < Right.Color;
end "<";
function test_data return Bag_Maps.Map is
d : constant Bag_Maps.Map := parse_rules("test1.txt");
begin
return d;
end test_data;
function input_data return Bag_Maps.Map is
d : constant Bag_Maps.Map := parse_rules("input.txt");
begin
return d;
end input_data;
function extract_color(line : in String; rest : out Unbounded_String) return Bag_Color is
first_space : constant Natural := index(line, " ");
second_space : constant Natural := index(line(first_space+1 .. line'last), " ");
first_word : constant String := line(line'first .. first_space-1);
second_word : constant String := line(first_space+1 .. second_space-1);
ident : constant String := first_word & "_" & second_word;
c : constant Bag_Color := Bag_Color'Value(ident);
begin
rest := to_unbounded_string(line(second_space+1..line'last));
return c;
end extract_color;
procedure drop_one(line : in String; rest : out Unbounded_String) is
first_space : constant Natural := index(line, " ");
begin
rest := to_unbounded_string(line(first_space+1..line'last));
end drop_one;
function get_next(uline : in out Unbounded_String) return Bag_Combo is
line : constant String := to_string(uline);
first_space : constant Natural := index(line, " ");
num : constant Natural := Natural'Value(line(line'first .. first_space-1));
s : constant String := line(first_space+1 .. line'last);
color : constant Bag_Color := extract_color(s, uline);
begin
return Bag_Combo'(Color => color, Count => num);
end get_next;
function build_set(line : in String) return Bag_Sets.Set is
s : Bag_Sets.Set := Empty_Set;
rest : Unbounded_String := to_unbounded_string(line);
begin
if 'n' = line(line'first) then
return s;
end if;
loop
declare
combo : constant Bag_Combo := get_next(rest);
begin
s.insert(combo);
if 0 = index(to_string(rest), " ") then
exit;
end if;
drop_one(to_string(rest), rest);
end;
end loop;
return s;
end build_set;
-- procedure print(m : in Bag_Maps.Map) is
-- begin
-- for c in m.Iterate loop
-- TIO.put_line(Bag_Color'Image(key(c)));
-- for s of element(c) loop
-- TIO.put_line(" " & Bag_Color'Image(s.Color) & ":" & Natural'Image(s.Count));
-- end loop;
-- end loop;
-- end print;
procedure parse_line(line : in String; m : in out Bag_Maps.Map) is
rest : Unbounded_String;
c : constant Bag_Color := extract_color(line, rest);
s : Bag_Sets.Set;
begin
drop_one(to_string(rest), rest);
drop_one(to_string(rest), rest);
s := build_set(to_string(rest));
m.insert(c, s);
end parse_line;
--
function parse_rules(f : in String) return Bag_Maps.Map is
file : TIO.File_Type;
d : Bag_Maps.Map := Empty_Map;
begin
TIO.open(File => file, Mode => TIO.In_File, Name => f);
while not TIO.end_of_file(file) loop
parse_line(TIO.get_line(file), d);
end loop;
TIO.close(file);
-- print(d);
return d;
end parse_rules;
end Bag;
|
package body Epoch_Support is
Init_Time : constant Time := Clock + Milliseconds (1000);
-----------
-- Epoch --
-----------
function Epoch return Time is (Init_Time);
end Epoch_Support;
|
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2017, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with Interfaces; use Interfaces;
with Bitmap.Memory_Mapped; use Bitmap.Memory_Mapped;
with System;
package body Bitmap.File_IO is
type Header (As_Array : Boolean := True) is record
case As_Array is
when True =>
Arr : UInt8_Array (1 .. 14);
when False =>
Signature : Integer_16;
Size : Integer_32; -- File size
Reserved1 : Integer_16;
Reserved2 : Integer_16;
Offset : Integer_32; -- Data offset
end case;
end record with Unchecked_Union, Pack, Size => 14 * 8;
type Info (As_Array : Boolean := True) is record
case As_Array is
when True =>
Arr : UInt8_Array (1 .. 40);
when False =>
Struct_Size : Integer_32;
Width : Integer_32; -- Image width in pixels
Height : Integer_32; -- Image hieght in pixels
Planes : Integer_16;
Pixel_Size : Integer_16; -- Bits per pixel
Compression : Integer_32; -- Zero means no compression
Image_Size : Integer_32; -- Size of the image data in UInt8s
PPMX : Integer_32; -- Pixels per meter in x led
PPMY : Integer_32; -- Pixels per meter in y led
Palette_Size : Integer_32; -- Number of colors
Important : Integer_32;
end case;
end record with Unchecked_Union, Pack, Size => 40 * 8;
-------------------
-- Read_BMP_File --
-------------------
function Read_BMP_File (File : File_Type) return not null Any_Bitmap_Buffer
is
function Allocate_Pixel_Data return System.Address;
procedure Read_Pixel_Data;
Input_Stream : Ada.Streams.Stream_IO.Stream_Access;
Hdr : Header;
Inf : Info;
Width : Integer;
Height : Integer;
BM : constant Any_Memory_Mapped_Bitmap_Buffer := new Memory_Mapped_Bitmap_Buffer;
RGB_Pix : Bitmap_Color;
Pix_In : UInt8_Array (1 .. 3);
-------------------------
-- Allocate_Pixel_Data --
-------------------------
function Allocate_Pixel_Data return System.Address is
type Pixel_Data is new Bitmap.UInt16_Array (1 .. Width * Height) with Pack;
type Pixel_Data_Access is access Pixel_Data;
Data : constant Pixel_Data_Access := new Pixel_Data;
begin
return Data.all'Address;
end Allocate_Pixel_Data;
---------------------
-- Read_Pixel_Data --
---------------------
procedure Read_Pixel_Data is
Row_Size : constant Integer_32 := Integer_32 (Width * 24);
Row_Padding : constant Integer_32 := (32 - (Row_Size mod 32)) mod 32 / 8;
Padding : UInt8_Array (1 .. Integer (Row_Padding));
begin
for Y in reverse 0 .. Height - 1 loop
for X in 0 .. Width - 1 loop
UInt8_Array'Read (Input_Stream, Pix_In);
RGB_Pix.Blue := Pix_In (1);
RGB_Pix.Green := Pix_In (2);
RGB_Pix.Red := Pix_In (3);
BM.Set_Pixel ((X, Y), RGB_Pix);
end loop;
UInt8_Array'Read (Input_Stream, Padding);
end loop;
end Read_Pixel_Data;
begin
Input_Stream := Ada.Streams.Stream_IO.Stream (File);
UInt8_Array'Read (Input_Stream, Hdr.Arr);
UInt8_Array'Read (Input_Stream, Inf.Arr);
Width := Integer (Inf.Width);
Height := Integer (Inf.Height);
BM.Actual_Width := Width;
BM.Actual_Height := Height;
BM.Actual_Color_Mode := RGB_565;
BM.Currently_Swapped := False;
BM.Addr := Allocate_Pixel_Data;
Set_Index (File, Positive_Count (Hdr.Offset + 1));
Read_Pixel_Data;
return Any_Bitmap_Buffer (BM);
end Read_BMP_File;
--------------------
-- Write_BMP_File --
--------------------
procedure Write_BMP_File (File : File_Type;
Bitmap : Bitmap_Buffer'Class)
is
Hdr : Header;
Inf : Info;
Row_Size : constant Integer_32 := Integer_32 (Bitmap.Width * 24);
Row_Padding : constant Integer_32 := (32 - (Row_Size mod 32)) mod 32 / 8;
Data_Size : constant Integer_32 := (Row_Size + Row_Padding) * Integer_32 (Bitmap.Height);
RGB_Pix : Bitmap_Color;
Pix_Out : UInt8_Array (1 .. 3);
Padding : constant UInt8_Array (1 .. Integer (Row_Padding)) := (others => 0);
Output_Stream : Ada.Streams.Stream_IO.Stream_Access;
begin
Hdr.Signature := 16#4D42#;
Hdr.Size := (Data_Size + 54) / 4;
Hdr.Reserved1 := 0;
Hdr.Reserved2 := 0;
Hdr.Offset := 54;
Inf.Struct_Size := 40;
Inf.Width := Integer_32 (Bitmap.Width);
Inf.Height := Integer_32 (Bitmap.Height);
Inf.Planes := 1;
Inf.Pixel_Size := 24;
Inf.Compression := 0;
Inf.Image_Size := Data_Size / 4;
Inf.PPMX := 2835;
Inf.PPMY := 2835;
Inf.Palette_Size := 0;
Inf.Important := 0;
Output_Stream := Ada.Streams.Stream_IO.Stream (File);
UInt8_Array'Write (Output_Stream, Hdr.Arr);
UInt8_Array'Write (Output_Stream, Inf.Arr);
for Y in reverse 0 .. Bitmap.Height - 1 loop
for X in 0 .. Bitmap.Width - 1 loop
RGB_Pix := Bitmap.Pixel ((X, Y));
Pix_Out (1) := RGB_Pix.Blue;
Pix_Out (2) := RGB_Pix.Green;
Pix_Out (3) := RGB_Pix.Red;
UInt8_Array'Write (Output_Stream, Pix_Out);
end loop;
UInt8_Array'Write (Output_Stream, Padding);
end loop;
end Write_BMP_File;
end Bitmap.File_IO;
|
-----------------------------------------------------------------------
-- css-commands-analyze -- List command for CSS tools
-- Copyright (C) 2018, 2020 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with CSS.Analysis.Duplicates;
with CSS.Analysis.Rules.Main;
package body CSS.Commands.Analyze is
-- ------------------------------
-- Execute the command with the arguments.
-- ------------------------------
overriding
procedure Execute (Cmd : in out Command;
Name : in String;
Args : in Argument_List'Class;
Context : in out CSS.Commands.Context_Type) is
pragma Unreferenced (Cmd, Name);
begin
CSS.Commands.Load (Args, Context);
CSS.Analysis.Duplicates.Analyze (Context.Doc.Rules, Context.Err_Handler,
Context.Dup_Rules);
CSS.Analysis.Rules.Main.Analyze (Context.Doc, Context.Err_Handler);
-- Err_Handler.Iterate (Print_Message'Access);
CSS.Analysis.Classes.Analyze (Context.Doc, Context.Class_Map,
Context.Err_Handler);
end Execute;
-- ------------------------------
-- Write the help associated with the command.
-- ------------------------------
overriding
procedure Help (Cmd : in out Command;
Name : in String;
Context : in out CSS.Commands.Context_Type) is
pragma Unreferenced (Cmd, Name);
Console : constant CSS.Commands.Console_Access := Context.Console;
begin
Console.Notice (N_HELP, "analyze: analyze the CSS files");
end Help;
end CSS.Commands.Analyze;
|
package body util is
function toHexString(r : in Unsigned_32) return HexString32 is
ret : HexString32 := "0xDEADBEEF";
begin
ret(1) := '0';
ret(2) := 'x';
ret(3) := hexdigits(HexDigitRange(Shift_Right((r and 16#F000_0000#), 28)));
ret(4) := hexdigits(HexDigitRange(Shift_Right((r and 16#0F00_0000#), 24)));
ret(5) := hexdigits(HexDigitRange(Shift_Right((r and 16#00F0_0000#), 20)));
ret(6) := hexdigits(HexDigitRange(Shift_Right((r and 16#000F_0000#), 16)));
ret(7) := hexdigits(HexDigitRange(Shift_Right((r and 16#0000_F000#), 12)));
ret(8) := hexdigits(HexDigitRange(Shift_Right((r and 16#0000_0F00#), 8)));
ret(9) := hexdigits(HexDigitRange(Shift_Right((r and 16#0000_00F0#), 4)));
ret(10) := hexdigits(HexDigitRange(r and 16#0000_000F#));
return ret;
end toHexString;
-- Convert Unsigned_64 integer to a hex string
function toHexString(r : in Unsigned_64) return HexString64 is
ret : HexString64 := "0xDEADBEEFDEADBEEF";
begin
ret(1) := '0';
ret(2) := 'x';
ret(3) := hexdigits(HexDigitRange(Shift_Right((r and 16#F000_0000_0000_0000#), 60)));
ret(4) := hexdigits(HexDigitRange(Shift_Right((r and 16#0F00_0000_0000_0000#), 56)));
ret(5) := hexdigits(HexDigitRange(Shift_Right((r and 16#00F0_0000_0000_0000#), 52)));
ret(6) := hexdigits(HexDigitRange(Shift_Right((r and 16#000F_0000_0000_0000#), 48)));
ret(7) := hexdigits(HexDigitRange(Shift_Right((r and 16#0000_F000_0000_0000#), 44)));
ret(8) := hexdigits(HexDigitRange(Shift_Right((r and 16#0000_0F00_0000_0000#), 40)));
ret(9) := hexdigits(HexDigitRange(Shift_Right((r and 16#0000_00F0_0000_0000#), 36)));
ret(10) := hexdigits(HexDigitRange(Shift_Right((r and 16#0000_000F_0000_0000#), 32)));
ret(11) := hexdigits(HexDigitRange(Shift_Right((r and 16#0000_0000_F000_0000#), 28)));
ret(12) := hexdigits(HexDigitRange(Shift_Right((r and 16#0000_0000_0F00_0000#), 24)));
ret(13) := hexdigits(HexDigitRange(Shift_Right((r and 16#0000_0000_00F0_0000#), 20)));
ret(14) := hexdigits(HexDigitRange(Shift_Right((r and 16#0000_0000_000F_0000#), 16)));
ret(15) := hexdigits(HexDigitRange(Shift_Right((r and 16#0000_0000_0000_F000#), 12)));
ret(16) := hexdigits(HexDigitRange(Shift_Right((r and 16#0000_0000_0000_0F00#), 8)));
ret(17) := hexdigits(HexDigitRange(Shift_Right((r and 16#0000_0000_0000_00F0#), 4)));
ret(18) := hexdigits(HexDigitRange(r and 16#0000_0000_0000_000F#));
return ret;
end toHexString;
-- convenience procedure for setting specific bytes in a 64-bit word
procedure setByte(byte : in byteOffset; val : in Unsigned_8; word : in out Unsigned_64) is
mask : Unsigned_64 := not (Shift_Left(16#FF#, byte * 8)); -- make a "hole" in the word
shiftedByte : Unsigned_64;
begin
--Ada.Text_IO.Put_Line("setByte mask: " & toHexString(mask));
--Ada.Text_IO.Put_Line("setByte word in: " & toHexString(word));
-- zero out that byte
word := word and mask;
--Ada.Text_IO.Put_Line("setByte word and mask: " & toHexString(word));
shiftedByte := Shift_Left(Unsigned_64(val), byte * 8);
word := word or shiftedByte;
--Ada.Text_IO.Put_Line("setByte word'Result: " & toHexString(word));
end setByte;
procedure setLoWord(val : in Unsigned_32; word : in out Unsigned_64) is
begin
word := word and Unsigned_64(16#FFFF_FFFF_0000_0000#);
word := word or Unsigned_64(val);
end setLoWord;
procedure setHiWord(val : in Unsigned_32; word : in out Unsigned_64) is
begin
word := word and Unsigned_64(16#0000_0000_FFFF_FFFF#);
word := word or Shift_Left(Unsigned_64(val), 32);
end setHiWord;
function getHiWord(word : in Unsigned_64) return Unsigned_32 is
begin
return Unsigned_32(Shift_Right(word, 32));
end getHiWord;
---------------
-- getLoWord --
---------------
function getLoWord (word : in Unsigned_64) return Unsigned_32 is
begin
return Unsigned_32(word and Unsigned_64(16#0000_0000_FFFF_FFFF#));
end getLoWord;
-- convenience procedure for getting a specific byte in a 64-bit opcode
function getByte(byte : in byteOffset; word : in Unsigned_64) return Unsigned_8 is
mask : Unsigned_64 := Shift_Left(16#FF#, byte * 8); -- zero everything except our byte
tmp : Unsigned_64;
begin
-- zero out that byte
-- Ada.Text_IO.Put_Line("getByte: word: " & toHexString(word));
-- Ada.Text_IO.Put_Line("getByte: mask: " & toHexString(mask));
tmp := word and mask;
-- Ada.Text_IO.Put_Line("getByte: word and mask: " & toHexString(tmp));
tmp := (Shift_Right(tmp, byte * 8));
return Unsigned_8(tmp);
end getByte;
end util;
|
with Ada.Assertions; use Ada.Assertions;
...
Assert (A = 42, "Oops!");
|
package UxAS.Comms.Transport.Network_Name is
ZmqExternalLmcpTcpNetwork : constant String := "zmqExternalLmcpTcpNetwork";
ZmqLmcpNetwork : constant String := "zmqLmcpNetwork";
ZmqStringNetwork : constant String := "zmqStringNetwork";
end UxAS.Comms.Transport.Network_Name;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- G N A T . G R A P H S --
-- --
-- B o d y --
-- --
-- Copyright (C) 2018-2020, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.Unchecked_Deallocation;
package body GNAT.Graphs is
-----------------------
-- Local subprograms --
-----------------------
function Sequence_Next_Component return Component_Id;
-- Produce the next handle for a component. The handle is guaranteed to be
-- unique across all graphs.
--------------------
-- Directed_Graph --
--------------------
package body Directed_Graphs is
-----------------------
-- Local subprograms --
-----------------------
procedure Add_Component
(G : Directed_Graph;
Comp : Component_Id;
Vertices : Vertex_List.Doubly_Linked_List);
pragma Inline (Add_Component);
-- Add component Comp which houses vertices Vertices to graph G
procedure Ensure_Created (G : Directed_Graph);
pragma Inline (Ensure_Created);
-- Verify that graph G is created. Raise Not_Created if this is not the
-- case.
procedure Ensure_Not_Present
(G : Directed_Graph;
E : Edge_Id);
pragma Inline (Ensure_Not_Present);
-- Verify that graph G lacks edge E. Raise Duplicate_Edge if this is not
-- the case.
procedure Ensure_Not_Present
(G : Directed_Graph;
V : Vertex_Id);
pragma Inline (Ensure_Not_Present);
-- Verify that graph G lacks vertex V. Raise Duplicate_Vertex if this is
-- not the case.
procedure Ensure_Present
(G : Directed_Graph;
Comp : Component_Id);
pragma Inline (Ensure_Present);
-- Verify that component Comp exists in graph G. Raise Missing_Component
-- if this is not the case.
procedure Ensure_Present
(G : Directed_Graph;
E : Edge_Id);
pragma Inline (Ensure_Present);
-- Verify that edge E is present in graph G. Raise Missing_Edge if this
-- is not the case.
procedure Ensure_Present
(G : Directed_Graph;
V : Vertex_Id);
pragma Inline (Ensure_Present);
-- Verify that vertex V is present in graph G. Raise Missing_Vertex if
-- this is not the case.
procedure Free is
new Ada.Unchecked_Deallocation
(Directed_Graph_Attributes, Directed_Graph);
function Get_Component_Attributes
(G : Directed_Graph;
Comp : Component_Id) return Component_Attributes;
pragma Inline (Get_Component_Attributes);
-- Obtain the attributes of component Comp of graph G
function Get_Edge_Attributes
(G : Directed_Graph;
E : Edge_Id) return Edge_Attributes;
pragma Inline (Get_Edge_Attributes);
-- Obtain the attributes of edge E of graph G
function Get_Vertex_Attributes
(G : Directed_Graph;
V : Vertex_Id) return Vertex_Attributes;
pragma Inline (Get_Vertex_Attributes);
-- Obtain the attributes of vertex V of graph G
function Get_Outgoing_Edges
(G : Directed_Graph;
V : Vertex_Id) return Edge_Set.Membership_Set;
pragma Inline (Get_Outgoing_Edges);
-- Obtain the Outgoing_Edges attribute of vertex V of graph G
function Get_Vertices
(G : Directed_Graph;
Comp : Component_Id) return Vertex_List.Doubly_Linked_List;
pragma Inline (Get_Vertices);
-- Obtain the Vertices attribute of component Comp of graph G
procedure Set_Component
(G : Directed_Graph;
V : Vertex_Id;
Val : Component_Id);
pragma Inline (Set_Component);
-- Set attribute Component of vertex V of graph G to value Val
procedure Set_Outgoing_Edges
(G : Directed_Graph;
V : Vertex_Id;
Val : Edge_Set.Membership_Set);
pragma Inline (Set_Outgoing_Edges);
-- Set attribute Outgoing_Edges of vertex V of graph G to value Val
procedure Set_Vertex_Attributes
(G : Directed_Graph;
V : Vertex_Id;
Val : Vertex_Attributes);
pragma Inline (Set_Vertex_Attributes);
-- Set the attributes of vertex V of graph G to value Val
-------------------
-- Add_Component --
-------------------
procedure Add_Component
(G : Directed_Graph;
Comp : Component_Id;
Vertices : Vertex_List.Doubly_Linked_List)
is
begin
pragma Assert (Present (G));
-- Add the component to the set of all components in the graph
Component_Map.Put
(T => G.Components,
Key => Comp,
Value => (Vertices => Vertices));
end Add_Component;
--------------
-- Add_Edge --
--------------
procedure Add_Edge
(G : Directed_Graph;
E : Edge_Id;
Source : Vertex_Id;
Destination : Vertex_Id)
is
begin
Ensure_Created (G);
Ensure_Not_Present (G, E);
Ensure_Present (G, Source);
Ensure_Present (G, Destination);
-- Add the edge to the set of all edges in the graph
Edge_Map.Put
(T => G.All_Edges,
Key => E,
Value =>
(Destination => Destination,
Source => Source));
-- Associate the edge with its source vertex which effectively "owns"
-- the edge.
Edge_Set.Insert
(S => Get_Outgoing_Edges (G, Source),
Elem => E);
end Add_Edge;
----------------
-- Add_Vertex --
----------------
procedure Add_Vertex
(G : Directed_Graph;
V : Vertex_Id)
is
begin
Ensure_Created (G);
Ensure_Not_Present (G, V);
-- Add the vertex to the set of all vertices in the graph
Vertex_Map.Put
(T => G.All_Vertices,
Key => V,
Value =>
(Component => No_Component,
Outgoing_Edges => Edge_Set.Nil));
-- It is assumed that the vertex will have at least one outgoing
-- edge. It is important not to create the set of edges above as
-- the call to Put may fail in case the vertices are iterated.
-- This would lead to a memory leak because the set would not be
-- reclaimed.
Set_Outgoing_Edges (G, V, Edge_Set.Create (1));
end Add_Vertex;
---------------
-- Component --
---------------
function Component
(G : Directed_Graph;
V : Vertex_Id) return Component_Id
is
begin
Ensure_Created (G);
Ensure_Present (G, V);
return Get_Vertex_Attributes (G, V).Component;
end Component;
------------------------
-- Contains_Component --
------------------------
function Contains_Component
(G : Directed_Graph;
Comp : Component_Id) return Boolean
is
begin
Ensure_Created (G);
return Component_Map.Contains (G.Components, Comp);
end Contains_Component;
-------------------
-- Contains_Edge --
-------------------
function Contains_Edge
(G : Directed_Graph;
E : Edge_Id) return Boolean
is
begin
Ensure_Created (G);
return Edge_Map.Contains (G.All_Edges, E);
end Contains_Edge;
---------------------
-- Contains_Vertex --
---------------------
function Contains_Vertex
(G : Directed_Graph;
V : Vertex_Id) return Boolean
is
begin
Ensure_Created (G);
return Vertex_Map.Contains (G.All_Vertices, V);
end Contains_Vertex;
------------
-- Create --
------------
function Create
(Initial_Vertices : Positive;
Initial_Edges : Positive) return Directed_Graph
is
G : constant Directed_Graph := new Directed_Graph_Attributes;
begin
G.All_Edges := Edge_Map.Create (Initial_Edges);
G.All_Vertices := Vertex_Map.Create (Initial_Vertices);
G.Components := Component_Map.Create (Initial_Vertices);
return G;
end Create;
-----------------
-- Delete_Edge --
-----------------
procedure Delete_Edge
(G : Directed_Graph;
E : Edge_Id)
is
Source : Vertex_Id;
begin
Ensure_Created (G);
Ensure_Present (G, E);
Source := Source_Vertex (G, E);
Ensure_Present (G, Source);
-- Delete the edge from its source vertex which effectively "owns"
-- the edge.
Edge_Set.Delete (Get_Outgoing_Edges (G, Source), E);
-- Delete the edge from the set of all edges
Edge_Map.Delete (G.All_Edges, E);
end Delete_Edge;
------------------------
-- Destination_Vertex --
------------------------
function Destination_Vertex
(G : Directed_Graph;
E : Edge_Id) return Vertex_Id
is
begin
Ensure_Created (G);
Ensure_Present (G, E);
return Get_Edge_Attributes (G, E).Destination;
end Destination_Vertex;
-------------
-- Destroy --
-------------
procedure Destroy (G : in out Directed_Graph) is
begin
Ensure_Created (G);
Edge_Map.Destroy (G.All_Edges);
Vertex_Map.Destroy (G.All_Vertices);
Component_Map.Destroy (G.Components);
Free (G);
end Destroy;
----------------------------------
-- Destroy_Component_Attributes --
----------------------------------
procedure Destroy_Component_Attributes
(Attrs : in out Component_Attributes)
is
begin
Vertex_List.Destroy (Attrs.Vertices);
end Destroy_Component_Attributes;
-----------------------------
-- Destroy_Edge_Attributes --
-----------------------------
procedure Destroy_Edge_Attributes (Attrs : in out Edge_Attributes) is
pragma Unreferenced (Attrs);
begin
null;
end Destroy_Edge_Attributes;
--------------------
-- Destroy_Vertex --
--------------------
procedure Destroy_Vertex (V : in out Vertex_Id) is
pragma Unreferenced (V);
begin
null;
end Destroy_Vertex;
-------------------------------
-- Destroy_Vertex_Attributes --
-------------------------------
procedure Destroy_Vertex_Attributes (Attrs : in out Vertex_Attributes) is
begin
Edge_Set.Destroy (Attrs.Outgoing_Edges);
end Destroy_Vertex_Attributes;
--------------------
-- Ensure_Created --
--------------------
procedure Ensure_Created (G : Directed_Graph) is
begin
if not Present (G) then
raise Not_Created;
end if;
end Ensure_Created;
------------------------
-- Ensure_Not_Present --
------------------------
procedure Ensure_Not_Present
(G : Directed_Graph;
E : Edge_Id)
is
begin
if Contains_Edge (G, E) then
raise Duplicate_Edge;
end if;
end Ensure_Not_Present;
------------------------
-- Ensure_Not_Present --
------------------------
procedure Ensure_Not_Present
(G : Directed_Graph;
V : Vertex_Id)
is
begin
if Contains_Vertex (G, V) then
raise Duplicate_Vertex;
end if;
end Ensure_Not_Present;
--------------------
-- Ensure_Present --
--------------------
procedure Ensure_Present
(G : Directed_Graph;
Comp : Component_Id)
is
begin
if not Contains_Component (G, Comp) then
raise Missing_Component;
end if;
end Ensure_Present;
--------------------
-- Ensure_Present --
--------------------
procedure Ensure_Present
(G : Directed_Graph;
E : Edge_Id)
is
begin
if not Contains_Edge (G, E) then
raise Missing_Edge;
end if;
end Ensure_Present;
--------------------
-- Ensure_Present --
--------------------
procedure Ensure_Present
(G : Directed_Graph;
V : Vertex_Id)
is
begin
if not Contains_Vertex (G, V) then
raise Missing_Vertex;
end if;
end Ensure_Present;
---------------------
-- Find_Components --
---------------------
procedure Find_Components (G : Directed_Graph) is
-- The components of graph G are discovered using Tarjan's strongly
-- connected component algorithm. Do not modify this code unless you
-- intimately understand the algorithm.
----------------
-- Tarjan_Map --
----------------
type Visitation_Number is new Natural;
No_Visitation_Number : constant Visitation_Number :=
Visitation_Number'First;
First_Visitation_Number : constant Visitation_Number :=
No_Visitation_Number + 1;
type Tarjan_Attributes is record
Index : Visitation_Number := No_Visitation_Number;
-- Visitation number
Low_Link : Visitation_Number := No_Visitation_Number;
-- Lowest visitation number
On_Stack : Boolean := False;
-- Set when the corresponding vertex appears on the Stack
end record;
No_Tarjan_Attributes : constant Tarjan_Attributes :=
(Index => No_Visitation_Number,
Low_Link => No_Visitation_Number,
On_Stack => False);
procedure Destroy_Tarjan_Attributes
(Attrs : in out Tarjan_Attributes);
-- Destroy the contents of attributes Attrs
package Tarjan_Map is new Dynamic_Hash_Tables
(Key_Type => Vertex_Id,
Value_Type => Tarjan_Attributes,
No_Value => No_Tarjan_Attributes,
Expansion_Threshold => 1.5,
Expansion_Factor => 2,
Compression_Threshold => 0.3,
Compression_Factor => 2,
"=" => Same_Vertex,
Destroy_Value => Destroy_Tarjan_Attributes,
Hash => Hash_Vertex);
------------------
-- Tarjan_Stack --
------------------
package Tarjan_Stack is new Doubly_Linked_Lists
(Element_Type => Vertex_Id,
"=" => Same_Vertex,
Destroy_Element => Destroy_Vertex);
-----------------
-- Global data --
-----------------
Attrs : Tarjan_Map.Dynamic_Hash_Table := Tarjan_Map.Nil;
Stack : Tarjan_Stack.Doubly_Linked_List := Tarjan_Stack.Nil;
-----------------------
-- Local subprograms --
-----------------------
procedure Associate_All_Vertices;
pragma Inline (Associate_All_Vertices);
-- Associate all vertices in the graph with the corresponding
-- components that house them.
procedure Associate_Vertices (Comp : Component_Id);
pragma Inline (Associate_Vertices);
-- Associate all vertices of component Comp with the component
procedure Create_Component (V : Vertex_Id);
pragma Inline (Create_Component);
-- Create a new component with root vertex V
function Get_Tarjan_Attributes
(V : Vertex_Id) return Tarjan_Attributes;
pragma Inline (Get_Tarjan_Attributes);
-- Obtain the Tarjan attributes of vertex V
function Index (V : Vertex_Id) return Visitation_Number;
pragma Inline (Index);
-- Obtain the Index attribute of vertex V
procedure Initialize_Components;
pragma Inline (Initialize_Components);
-- Initialize or reinitialize the components of the graph
function Is_Visited (V : Vertex_Id) return Boolean;
pragma Inline (Is_Visited);
-- Determine whether vertex V has been visited
function Low_Link (V : Vertex_Id) return Visitation_Number;
pragma Inline (Low_Link);
-- Obtain the Low_Link attribute of vertex V
function On_Stack (V : Vertex_Id) return Boolean;
pragma Inline (On_Stack);
-- Obtain the On_Stack attribute of vertex V
function Pop return Vertex_Id;
pragma Inline (Pop);
-- Pop a vertex off Stack
procedure Push (V : Vertex_Id);
pragma Inline (Push);
-- Push vertex V on Stack
procedure Record_Visit (V : Vertex_Id);
pragma Inline (Record_Visit);
-- Save the visitation of vertex V by setting relevant attributes
function Sequence_Next_Index return Visitation_Number;
pragma Inline (Sequence_Next_Index);
-- Procedure the next visitation number of the DFS traversal
procedure Set_Index
(V : Vertex_Id;
Val : Visitation_Number);
pragma Inline (Set_Index);
-- Set attribute Index of vertex V to value Val
procedure Set_Low_Link
(V : Vertex_Id;
Val : Visitation_Number);
pragma Inline (Set_Low_Link);
-- Set attribute Low_Link of vertex V to value Val
procedure Set_On_Stack
(V : Vertex_Id;
Val : Boolean);
pragma Inline (Set_On_Stack);
-- Set attribute On_Stack of vertex V to value Val
procedure Set_Tarjan_Attributes
(V : Vertex_Id;
Val : Tarjan_Attributes);
pragma Inline (Set_Tarjan_Attributes);
-- Set the attributes of vertex V to value Val
procedure Visit_Successors (V : Vertex_Id);
pragma Inline (Visit_Successors);
-- Visit the successors of vertex V
procedure Visit_Vertex (V : Vertex_Id);
pragma Inline (Visit_Vertex);
-- Visit single vertex V
procedure Visit_Vertices;
pragma Inline (Visit_Vertices);
-- Visit all vertices in the graph
----------------------------
-- Associate_All_Vertices --
----------------------------
procedure Associate_All_Vertices is
Comp : Component_Id;
Iter : Component_Iterator;
begin
Iter := Iterate_Components (G);
while Has_Next (Iter) loop
Next (Iter, Comp);
Associate_Vertices (Comp);
end loop;
end Associate_All_Vertices;
------------------------
-- Associate_Vertices --
------------------------
procedure Associate_Vertices (Comp : Component_Id) is
Iter : Component_Vertex_Iterator;
V : Vertex_Id;
begin
Iter := Iterate_Component_Vertices (G, Comp);
while Has_Next (Iter) loop
Next (Iter, V);
Set_Component (G, V, Comp);
end loop;
end Associate_Vertices;
----------------------
-- Create_Component --
----------------------
procedure Create_Component (V : Vertex_Id) is
Curr_V : Vertex_Id;
Vertices : Vertex_List.Doubly_Linked_List;
begin
Vertices := Vertex_List.Create;
-- Collect all vertices that comprise the current component by
-- popping the stack until reaching the root vertex V.
loop
Curr_V := Pop;
Vertex_List.Append (Vertices, Curr_V);
exit when Same_Vertex (Curr_V, V);
end loop;
Add_Component
(G => G,
Comp => Sequence_Next_Component,
Vertices => Vertices);
end Create_Component;
-------------------------------
-- Destroy_Tarjan_Attributes --
-------------------------------
procedure Destroy_Tarjan_Attributes
(Attrs : in out Tarjan_Attributes)
is
pragma Unreferenced (Attrs);
begin
null;
end Destroy_Tarjan_Attributes;
---------------------------
-- Get_Tarjan_Attributes --
---------------------------
function Get_Tarjan_Attributes
(V : Vertex_Id) return Tarjan_Attributes
is
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
return Tarjan_Map.Get (Attrs, V);
end Get_Tarjan_Attributes;
-----------
-- Index --
-----------
function Index (V : Vertex_Id) return Visitation_Number is
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
return Get_Tarjan_Attributes (V).Index;
end Index;
---------------------------
-- Initialize_Components --
---------------------------
procedure Initialize_Components is
begin
pragma Assert (Present (G));
-- The graph already contains a set of components. Reinitialize
-- them in order to accommodate the new set of components about to
-- be computed.
if Number_Of_Components (G) > 0 then
Component_Map.Destroy (G.Components);
G.Components := Component_Map.Create (Number_Of_Vertices (G));
end if;
end Initialize_Components;
----------------
-- Is_Visited --
----------------
function Is_Visited (V : Vertex_Id) return Boolean is
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
return Index (V) /= No_Visitation_Number;
end Is_Visited;
--------------
-- Low_Link --
--------------
function Low_Link (V : Vertex_Id) return Visitation_Number is
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
return Get_Tarjan_Attributes (V).Low_Link;
end Low_Link;
--------------
-- On_Stack --
--------------
function On_Stack (V : Vertex_Id) return Boolean is
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
return Get_Tarjan_Attributes (V).On_Stack;
end On_Stack;
---------
-- Pop --
---------
function Pop return Vertex_Id is
V : Vertex_Id;
begin
V := Tarjan_Stack.Last (Stack);
Tarjan_Stack.Delete_Last (Stack);
Set_On_Stack (V, False);
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
return V;
end Pop;
----------
-- Push --
----------
procedure Push (V : Vertex_Id) is
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
Tarjan_Stack.Append (Stack, V);
Set_On_Stack (V, True);
end Push;
------------------
-- Record_Visit --
------------------
procedure Record_Visit (V : Vertex_Id) is
Index : constant Visitation_Number := Sequence_Next_Index;
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
Set_Index (V, Index);
Set_Low_Link (V, Index);
end Record_Visit;
-------------------------
-- Sequence_Next_Index --
-------------------------
Index_Sequencer : Visitation_Number := First_Visitation_Number;
-- The counter for visitation numbers. Do not directly manipulate its
-- value because this will destroy the Index and Low_Link invariants
-- of the algorithm.
function Sequence_Next_Index return Visitation_Number is
Index : constant Visitation_Number := Index_Sequencer;
begin
Index_Sequencer := Index_Sequencer + 1;
return Index;
end Sequence_Next_Index;
---------------
-- Set_Index --
---------------
procedure Set_Index
(V : Vertex_Id;
Val : Visitation_Number)
is
TA : Tarjan_Attributes;
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
TA := Get_Tarjan_Attributes (V);
TA.Index := Val;
Set_Tarjan_Attributes (V, TA);
end Set_Index;
------------------
-- Set_Low_Link --
------------------
procedure Set_Low_Link
(V : Vertex_Id;
Val : Visitation_Number)
is
TA : Tarjan_Attributes;
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
TA := Get_Tarjan_Attributes (V);
TA.Low_Link := Val;
Set_Tarjan_Attributes (V, TA);
end Set_Low_Link;
------------------
-- Set_On_Stack --
------------------
procedure Set_On_Stack
(V : Vertex_Id;
Val : Boolean)
is
TA : Tarjan_Attributes;
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
TA := Get_Tarjan_Attributes (V);
TA.On_Stack := Val;
Set_Tarjan_Attributes (V, TA);
end Set_On_Stack;
---------------------------
-- Set_Tarjan_Attributes --
---------------------------
procedure Set_Tarjan_Attributes
(V : Vertex_Id;
Val : Tarjan_Attributes)
is
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
Tarjan_Map.Put (Attrs, V, Val);
end Set_Tarjan_Attributes;
----------------------
-- Visit_Successors --
----------------------
procedure Visit_Successors (V : Vertex_Id) is
E : Edge_Id;
Iter : Outgoing_Edge_Iterator;
Succ : Vertex_Id;
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
Iter := Iterate_Outgoing_Edges (G, V);
while Has_Next (Iter) loop
Next (Iter, E);
Succ := Destination_Vertex (G, E);
pragma Assert (Contains_Vertex (G, Succ));
-- The current successor has not been visited yet. Extend the
-- DFS traversal into it.
if not Is_Visited (Succ) then
Visit_Vertex (Succ);
Set_Low_Link (V,
Visitation_Number'Min (Low_Link (V), Low_Link (Succ)));
-- The current successor has been visited, and still remains on
-- the stack which indicates that it does not participate in a
-- component yet.
elsif On_Stack (Succ) then
Set_Low_Link (V,
Visitation_Number'Min (Low_Link (V), Index (Succ)));
end if;
end loop;
end Visit_Successors;
------------------
-- Visit_Vertex --
------------------
procedure Visit_Vertex (V : Vertex_Id) is
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
if not Is_Visited (V) then
Record_Visit (V);
Push (V);
Visit_Successors (V);
-- The current vertex is the root of a component
if Low_Link (V) = Index (V) then
Create_Component (V);
end if;
end if;
end Visit_Vertex;
--------------------
-- Visit_Vertices --
--------------------
procedure Visit_Vertices is
Iter : All_Vertex_Iterator;
V : Vertex_Id;
begin
Iter := Iterate_All_Vertices (G);
while Has_Next (Iter) loop
Next (Iter, V);
Visit_Vertex (V);
end loop;
end Visit_Vertices;
-- Start of processing for Find_Components
begin
-- Initialize or reinitialize the components of the graph
Initialize_Components;
-- Prepare the extra attributes needed for each vertex, global
-- visitation number, and the stack where examined vertices are
-- placed.
Attrs := Tarjan_Map.Create (Number_Of_Vertices (G));
Stack := Tarjan_Stack.Create;
-- Start the DFS traversal of Tarjan's SCC algorithm
Visit_Vertices;
Tarjan_Map.Destroy (Attrs);
Tarjan_Stack.Destroy (Stack);
-- Associate each vertex with the component it belongs to
Associate_All_Vertices;
end Find_Components;
------------------------------
-- Get_Component_Attributes --
------------------------------
function Get_Component_Attributes
(G : Directed_Graph;
Comp : Component_Id) return Component_Attributes
is
begin
pragma Assert (Present (G));
pragma Assert (Contains_Component (G, Comp));
return Component_Map.Get (G.Components, Comp);
end Get_Component_Attributes;
-------------------------
-- Get_Edge_Attributes --
-------------------------
function Get_Edge_Attributes
(G : Directed_Graph;
E : Edge_Id) return Edge_Attributes
is
begin
pragma Assert (Present (G));
pragma Assert (Contains_Edge (G, E));
return Edge_Map.Get (G.All_Edges, E);
end Get_Edge_Attributes;
---------------------------
-- Get_Vertex_Attributes --
---------------------------
function Get_Vertex_Attributes
(G : Directed_Graph;
V : Vertex_Id) return Vertex_Attributes
is
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
return Vertex_Map.Get (G.All_Vertices, V);
end Get_Vertex_Attributes;
------------------------
-- Get_Outgoing_Edges --
------------------------
function Get_Outgoing_Edges
(G : Directed_Graph;
V : Vertex_Id) return Edge_Set.Membership_Set
is
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
return Get_Vertex_Attributes (G, V).Outgoing_Edges;
end Get_Outgoing_Edges;
------------------
-- Get_Vertices --
------------------
function Get_Vertices
(G : Directed_Graph;
Comp : Component_Id) return Vertex_List.Doubly_Linked_List
is
begin
pragma Assert (Present (G));
pragma Assert (Contains_Component (G, Comp));
return Get_Component_Attributes (G, Comp).Vertices;
end Get_Vertices;
--------------
-- Has_Next --
--------------
function Has_Next (Iter : All_Edge_Iterator) return Boolean is
begin
return Edge_Map.Has_Next (Edge_Map.Iterator (Iter));
end Has_Next;
--------------
-- Has_Next --
--------------
function Has_Next (Iter : All_Vertex_Iterator) return Boolean is
begin
return Vertex_Map.Has_Next (Vertex_Map.Iterator (Iter));
end Has_Next;
--------------
-- Has_Next --
--------------
function Has_Next (Iter : Component_Iterator) return Boolean is
begin
return Component_Map.Has_Next (Component_Map.Iterator (Iter));
end Has_Next;
--------------
-- Has_Next --
--------------
function Has_Next (Iter : Component_Vertex_Iterator) return Boolean is
begin
return Vertex_List.Has_Next (Vertex_List.Iterator (Iter));
end Has_Next;
--------------
-- Has_Next --
--------------
function Has_Next (Iter : Outgoing_Edge_Iterator) return Boolean is
begin
return Edge_Set.Has_Next (Edge_Set.Iterator (Iter));
end Has_Next;
--------------
-- Is_Empty --
--------------
function Is_Empty (G : Directed_Graph) return Boolean is
begin
Ensure_Created (G);
return
Edge_Map.Is_Empty (G.All_Edges)
and then Vertex_Map.Is_Empty (G.All_Vertices);
end Is_Empty;
-----------------------
-- Iterate_All_Edges --
-----------------------
function Iterate_All_Edges
(G : Directed_Graph) return All_Edge_Iterator
is
begin
Ensure_Created (G);
return All_Edge_Iterator (Edge_Map.Iterate (G.All_Edges));
end Iterate_All_Edges;
--------------------------
-- Iterate_All_Vertices --
--------------------------
function Iterate_All_Vertices
(G : Directed_Graph) return All_Vertex_Iterator
is
begin
Ensure_Created (G);
return All_Vertex_Iterator (Vertex_Map.Iterate (G.All_Vertices));
end Iterate_All_Vertices;
------------------------
-- Iterate_Components --
------------------------
function Iterate_Components
(G : Directed_Graph) return Component_Iterator
is
begin
Ensure_Created (G);
return Component_Iterator (Component_Map.Iterate (G.Components));
end Iterate_Components;
--------------------------------
-- Iterate_Component_Vertices --
--------------------------------
function Iterate_Component_Vertices
(G : Directed_Graph;
Comp : Component_Id) return Component_Vertex_Iterator
is
begin
Ensure_Created (G);
Ensure_Present (G, Comp);
return
Component_Vertex_Iterator
(Vertex_List.Iterate (Get_Vertices (G, Comp)));
end Iterate_Component_Vertices;
----------------------------
-- Iterate_Outgoing_Edges --
----------------------------
function Iterate_Outgoing_Edges
(G : Directed_Graph;
V : Vertex_Id) return Outgoing_Edge_Iterator
is
begin
Ensure_Created (G);
Ensure_Present (G, V);
return
Outgoing_Edge_Iterator
(Edge_Set.Iterate (Get_Outgoing_Edges (G, V)));
end Iterate_Outgoing_Edges;
----------
-- Next --
----------
procedure Next
(Iter : in out All_Edge_Iterator;
E : out Edge_Id)
is
begin
Edge_Map.Next (Edge_Map.Iterator (Iter), E);
end Next;
----------
-- Next --
----------
procedure Next
(Iter : in out All_Vertex_Iterator;
V : out Vertex_Id)
is
begin
Vertex_Map.Next (Vertex_Map.Iterator (Iter), V);
end Next;
----------
-- Next --
----------
procedure Next
(Iter : in out Component_Iterator;
Comp : out Component_Id)
is
begin
Component_Map.Next (Component_Map.Iterator (Iter), Comp);
end Next;
----------
-- Next --
----------
procedure Next
(Iter : in out Component_Vertex_Iterator;
V : out Vertex_Id)
is
begin
Vertex_List.Next (Vertex_List.Iterator (Iter), V);
end Next;
----------
-- Next --
----------
procedure Next
(Iter : in out Outgoing_Edge_Iterator;
E : out Edge_Id)
is
begin
Edge_Set.Next (Edge_Set.Iterator (Iter), E);
end Next;
----------------------------------
-- Number_Of_Component_Vertices --
----------------------------------
function Number_Of_Component_Vertices
(G : Directed_Graph;
Comp : Component_Id) return Natural
is
begin
Ensure_Created (G);
Ensure_Present (G, Comp);
return Vertex_List.Size (Get_Vertices (G, Comp));
end Number_Of_Component_Vertices;
--------------------------
-- Number_Of_Components --
--------------------------
function Number_Of_Components (G : Directed_Graph) return Natural is
begin
Ensure_Created (G);
return Component_Map.Size (G.Components);
end Number_Of_Components;
---------------------
-- Number_Of_Edges --
---------------------
function Number_Of_Edges (G : Directed_Graph) return Natural is
begin
Ensure_Created (G);
return Edge_Map.Size (G.All_Edges);
end Number_Of_Edges;
------------------------------
-- Number_Of_Outgoing_Edges --
------------------------------
function Number_Of_Outgoing_Edges
(G : Directed_Graph;
V : Vertex_Id) return Natural
is
begin
Ensure_Created (G);
Ensure_Present (G, V);
return Edge_Set.Size (Get_Outgoing_Edges (G, V));
end Number_Of_Outgoing_Edges;
------------------------
-- Number_Of_Vertices --
------------------------
function Number_Of_Vertices (G : Directed_Graph) return Natural is
begin
Ensure_Created (G);
return Vertex_Map.Size (G.All_Vertices);
end Number_Of_Vertices;
-------------
-- Present --
-------------
function Present (G : Directed_Graph) return Boolean is
begin
return G /= Nil;
end Present;
-------------------
-- Set_Component --
-------------------
procedure Set_Component
(G : Directed_Graph;
V : Vertex_Id;
Val : Component_Id)
is
VA : Vertex_Attributes;
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
VA := Get_Vertex_Attributes (G, V);
VA.Component := Val;
Set_Vertex_Attributes (G, V, VA);
end Set_Component;
------------------------
-- Set_Outgoing_Edges --
------------------------
procedure Set_Outgoing_Edges
(G : Directed_Graph;
V : Vertex_Id;
Val : Edge_Set.Membership_Set)
is
VA : Vertex_Attributes;
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
VA := Get_Vertex_Attributes (G, V);
VA.Outgoing_Edges := Val;
Set_Vertex_Attributes (G, V, VA);
end Set_Outgoing_Edges;
---------------------------
-- Set_Vertex_Attributes --
---------------------------
procedure Set_Vertex_Attributes
(G : Directed_Graph;
V : Vertex_Id;
Val : Vertex_Attributes)
is
begin
pragma Assert (Present (G));
pragma Assert (Contains_Vertex (G, V));
Vertex_Map.Put (G.All_Vertices, V, Val);
end Set_Vertex_Attributes;
-------------------
-- Source_Vertex --
-------------------
function Source_Vertex
(G : Directed_Graph;
E : Edge_Id) return Vertex_Id
is
begin
Ensure_Created (G);
Ensure_Present (G, E);
return Get_Edge_Attributes (G, E).Source;
end Source_Vertex;
end Directed_Graphs;
--------------------
-- Hash_Component --
--------------------
function Hash_Component (Comp : Component_Id) return Bucket_Range_Type is
begin
return Bucket_Range_Type (Comp);
end Hash_Component;
-------------
-- Present --
-------------
function Present (Comp : Component_Id) return Boolean is
begin
return Comp /= No_Component;
end Present;
-----------------------------
-- Sequence_Next_Component --
-----------------------------
Component_Sequencer : Component_Id := First_Component;
-- The counter for component handles. Do not directly manipulate its value
-- because this will destroy the invariant of the handles.
function Sequence_Next_Component return Component_Id is
Component : constant Component_Id := Component_Sequencer;
begin
Component_Sequencer := Component_Sequencer + 1;
return Component;
end Sequence_Next_Component;
end GNAT.Graphs;
|
pragma License (Unrestricted);
-- optional/overridable runtime unit
package System.Unwind.Backtrace is
-- This package will be linked when "__gl_exception_tracebacks" is used.
pragma Preelaborate;
-- filled by gnatbind (init.c)
Exception_Tracebacks : Integer := 0 -- -Ea or -Es
with Export,
Convention => C, External_Name => "__gl_exception_tracebacks";
Exception_Tracebacks_Symbolic : Integer := 0 -- -Es
with Export,
Convention => C,
External_Name => "__gl_exception_tracebacks_symbolic";
-- backtrace (a-excach.adb)
procedure Call_Chain (Current : in out Exception_Occurrence)
with Export, -- for weak linking
Convention => Ada, External_Name => "ada__exceptions__call_chain";
pragma No_Inline (Call_Chain);
-- equivalent to Append_Info_Basic_Exception_Traceback (a-exexda.adb)
procedure Backtrace_Information (
X : Exception_Occurrence;
Params : Address;
Put : not null access procedure (S : String; Params : Address);
New_Line : not null access procedure (Params : Address))
with Export, -- for weak linking
Convention => Ada, External_Name => "__drake_backtrace_information";
pragma No_Inline (Backtrace_Information);
end System.Unwind.Backtrace;
|
-- Copyright (c) 2010 - 2018, Nordic Semiconductor ASA
--
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without modification,
-- are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice, this
-- list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form, except as embedded into a Nordic
-- Semiconductor ASA integrated circuit in a product or a software update for
-- such product, must reproduce the above copyright notice, this list of
-- conditions and the following disclaimer in the documentation and/or other
-- materials provided with the distribution.
--
-- 3. Neither the name of Nordic Semiconductor ASA nor the names of its
-- contributors may be used to endorse or promote products derived from this
-- software without specific prior written permission.
--
-- 4. This software, with or without modification, must only be used with a
-- Nordic Semiconductor ASA integrated circuit.
--
-- 5. Any software provided in binary form under this license must not be reverse
-- engineered, decompiled, modified and/or disassembled.
--
-- THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
-- OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-- OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
-- DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
-- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--
-- This spec has been automatically generated from nrf52.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package NRF_SVD.UICR is
pragma Preelaborate;
---------------
-- Registers --
---------------
-- Description collection[0]: Reserved for Nordic firmware design
-- Description collection[0]: Reserved for Nordic firmware design
type NRFFW_Registers is array (0 .. 14) of HAL.UInt32;
-- Description collection[0]: Reserved for Nordic hardware design
-- Description collection[0]: Reserved for Nordic hardware design
type NRFHW_Registers is array (0 .. 11) of HAL.UInt32;
-- Description collection[0]: Reserved for customer
-- Description collection[0]: Reserved for customer
type CUSTOMER_Registers is array (0 .. 31) of HAL.UInt32;
subtype PSELRESET_PIN_Field is HAL.UInt6;
-- Connection
type PSELRESET_CONNECT_Field is
(-- Connect
Connected,
-- Disconnect
Disconnected)
with Size => 1;
for PSELRESET_CONNECT_Field use
(Connected => 0,
Disconnected => 1);
-- Description collection[0]: Mapping of the nRESET function (see POWER
-- chapter for details)
type PSELRESET_Register is record
-- GPIO number P0.n onto which Reset is exposed
PIN : PSELRESET_PIN_Field := 16#3F#;
-- unspecified
Reserved_6_30 : HAL.UInt25 := 16#1FFFFFF#;
-- Connection
CONNECT : PSELRESET_CONNECT_Field := NRF_SVD.UICR.Disconnected;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PSELRESET_Register use record
PIN at 0 range 0 .. 5;
Reserved_6_30 at 0 range 6 .. 30;
CONNECT at 0 range 31 .. 31;
end record;
-- Description collection[0]: Mapping of the nRESET function (see POWER
-- chapter for details)
type PSELRESET_Registers is array (0 .. 1) of PSELRESET_Register;
-- Enable or disable Access Port protection. Any other value than 0xFF
-- being written to this field will enable protection.
type APPROTECT_PALL_Field is
(-- Enable
Enabled,
-- Disable
Disabled)
with Size => 8;
for APPROTECT_PALL_Field use
(Enabled => 0,
Disabled => 255);
-- Access Port protection
type APPROTECT_Register is record
-- Enable or disable Access Port protection. Any other value than 0xFF
-- being written to this field will enable protection.
PALL : APPROTECT_PALL_Field := NRF_SVD.UICR.Disabled;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#FFFFFF#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for APPROTECT_Register use record
PALL at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
-- Setting of pins dedicated to NFC functionality
type NFCPINS_PROTECT_Field is
(-- Operation as GPIO pins. Same protection as normal GPIO pins
Disabled,
-- Operation as NFC antenna pins. Configures the protection for NFC operation
Nfc)
with Size => 1;
for NFCPINS_PROTECT_Field use
(Disabled => 0,
Nfc => 1);
-- Setting of pins dedicated to NFC functionality: NFC antenna or GPIO
type NFCPINS_Register is record
-- Setting of pins dedicated to NFC functionality
PROTECT : NFCPINS_PROTECT_Field := NRF_SVD.UICR.Nfc;
-- unspecified
Reserved_1_31 : HAL.UInt31 := 16#7FFFFFFF#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for NFCPINS_Register use record
PROTECT at 0 range 0 .. 0;
Reserved_1_31 at 0 range 1 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- User Information Configuration Registers
type UICR_Peripheral is record
-- Unspecified
UNUSED0 : aliased HAL.UInt32;
-- Unspecified
UNUSED1 : aliased HAL.UInt32;
-- Unspecified
UNUSED2 : aliased HAL.UInt32;
-- Unspecified
UNUSED3 : aliased HAL.UInt32;
-- Description collection[0]: Reserved for Nordic firmware design
NRFFW : aliased NRFFW_Registers;
-- Description collection[0]: Reserved for Nordic hardware design
NRFHW : aliased NRFHW_Registers;
-- Description collection[0]: Reserved for customer
CUSTOMER : aliased CUSTOMER_Registers;
-- Description collection[0]: Mapping of the nRESET function (see POWER
-- chapter for details)
PSELRESET : aliased PSELRESET_Registers;
-- Access Port protection
APPROTECT : aliased APPROTECT_Register;
-- Setting of pins dedicated to NFC functionality: NFC antenna or GPIO
NFCPINS : aliased NFCPINS_Register;
end record
with Volatile;
for UICR_Peripheral use record
UNUSED0 at 16#0# range 0 .. 31;
UNUSED1 at 16#4# range 0 .. 31;
UNUSED2 at 16#8# range 0 .. 31;
UNUSED3 at 16#10# range 0 .. 31;
NRFFW at 16#14# range 0 .. 479;
NRFHW at 16#50# range 0 .. 383;
CUSTOMER at 16#80# range 0 .. 1023;
PSELRESET at 16#200# range 0 .. 63;
APPROTECT at 16#208# range 0 .. 31;
NFCPINS at 16#20C# range 0 .. 31;
end record;
-- User Information Configuration Registers
UICR_Periph : aliased UICR_Peripheral
with Import, Address => UICR_Base;
end NRF_SVD.UICR;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . E X P O N R --
-- --
-- B o d y --
-- --
-- Copyright (C) 2021, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- Note that the reason for treating exponents in the range 0 .. 4 specially
-- is to ensure identical results with the static expansion in the case of a
-- compile-time known exponent in this range; similarly, the use 'Machine is
-- to avoid unwanted extra precision in the results.
-- For a negative exponent, we compute the result as per RM 4.5.6(11/3):
-- Left ** Right = 1.0 / (Left ** (-Right))
-- Note that the case of Left being zero is not special, it will simply result
-- in a division by zero at the end, yielding a correctly signed infinity, or
-- possibly raising an overflow exception.
-- Note on overflow: this coding assumes that the target generates infinities
-- with standard IEEE semantics. If this is not the case, then the code for
-- negative exponents may raise Constraint_Error, which is in keeping with the
-- implementation permission given in RM 4.5.6(12).
with System.Double_Real;
function System.Exponr (Left : Num; Right : Integer) return Num is
package Double_Real is new System.Double_Real (Num);
use type Double_Real.Double_T;
subtype Double_T is Double_Real.Double_T;
-- The double floating-point type
subtype Safe_Negative is Integer range Integer'First + 1 .. -1;
-- The range of safe negative exponents
function Expon (Left : Num; Right : Natural) return Num;
-- Routine used if Right is greater than 4
-----------
-- Expon --
-----------
function Expon (Left : Num; Right : Natural) return Num is
Result : Double_T := Double_Real.To_Double (1.0);
Factor : Double_T := Double_Real.To_Double (Left);
Exp : Natural := Right;
begin
-- We use the standard logarithmic approach, Exp gets shifted right
-- testing successive low order bits and Factor is the value of the
-- base raised to the next power of 2. If the low order bit or Exp
-- is set, multiply the result by this factor.
loop
if Exp rem 2 /= 0 then
Result := Result * Factor;
exit when Exp = 1;
end if;
Exp := Exp / 2;
Factor := Double_Real.Sqr (Factor);
end loop;
return Double_Real.To_Single (Result);
end Expon;
begin
case Right is
when 0 =>
return 1.0;
when 1 =>
return Left;
when 2 =>
return Num'Machine (Left * Left);
when 3 =>
return Num'Machine (Left * Left * Left);
when 4 =>
declare
Sqr : constant Num := Num'Machine (Left * Left);
begin
return Num'Machine (Sqr * Sqr);
end;
when Safe_Negative =>
return Num'Machine (1.0 / Exponr (Left, -Right));
when Integer'First =>
return Num'Machine (1.0 / (Exponr (Left, Integer'Last) * Left));
when others =>
return Num'Machine (Expon (Left, Right));
end case;
end System.Exponr;
|
with Ada.Characters.Latin_1;
with Ada.Strings.Unbounded;
with Trendy_Test.Assertions.Integer_Assertions;
package body SP.Strings.Tests is
package ASU renames Ada.Strings.Unbounded;
use Trendy_Test.Assertions;
use Trendy_Test.Assertions.Integer_Assertions;
function "+" (S : String) return ASU.Unbounded_String renames ASU.To_Unbounded_String;
procedure Test_String_Split (Op : in out Trendy_Test.Operation'Class) is
E : Exploded_Line;
begin
Op.Register;
E := Make (" this is an exploded line with--content ");
Assert_EQ (Op, Num_Words (E), 6);
Assert_EQ (Op, Get_Word (E, 1), "this");
Assert_EQ (Op, Get_Word (E, 2), "is");
Assert_EQ (Op, Get_Word (E, 3), "an");
Assert_EQ (Op, Get_Word (E, 4), "exploded");
Assert_EQ (Op, Get_Word (E, 5), "line");
Assert_EQ (Op, Get_Word (E, 6), "with--content");
end Test_String_Split;
procedure Test_Is_Quoted (Op : in out Trendy_Test.Operation'Class) is
use Ada.Characters.Latin_1;
begin
Op.Register;
Assert (Op, not Is_Quoted(""));
Assert (Op, not Is_Quoted ("not quoted"));
-- Unbalanced "
Assert (Op, not Is_Quoted (Quotation & "some text"));
Assert (Op, not Is_Quoted ("some text" & Quotation));
-- Unbalanced '
Assert (Op, not Is_Quoted (Apostrophe & "some text"));
Assert (Op, not Is_Quoted ("some text" & Apostrophe));
-- Mismatched ' and "
Assert (Op, not Is_Quoted (Quotation & "some text" & Apostrophe));
Assert (Op, not Is_Quoted (Apostrophe & "some text" & Quotation));
-- Matched " and '
Assert (Op, Is_Quoted (Apostrophe & "some text" & Apostrophe));
Assert (Op, Is_Quoted (Quotation & "some text" & Quotation));
-- Internal " or '
Assert (Op, Is_Quoted (Apostrophe & Quotation & "some text" & Quotation & Apostrophe));
Assert (Op, Is_Quoted (Apostrophe & Quotation & "some text" & Quotation & Apostrophe));
end Test_Is_Quoted;
procedure Test_Common_Prefix_Length (Op : in out Trendy_Test.Operation'Class) is
package Trendy_TestI renames Trendy_Test.Assertions.Integer_Assertions;
begin
Op.Register;
Trendy_TestI.Assert_EQ (Op, Common_Prefix_Length(+"", +"SP.Strings"), 0);
Assert_EQ (Op, Common_Prefix_Length(+"SP.Strings", +""), 0);
Assert_EQ (Op, Common_Prefix_Length(+"", +""), 0);
Assert_EQ (Op, Common_Prefix_Length(+"SP.Searches", +"SP.Strings"), 4);
Assert_EQ (Op, Common_Prefix_Length(+"SP.Strings", +"SP.Strings"), ASU.Length (+"SP.Strings"));
end Test_Common_Prefix_Length;
---------------------------------------------------------------------------
-- Test Registry
---------------------------------------------------------------------------
function All_Tests return Trendy_Test.Test_Group is (
Test_String_Split'Access,
Test_Is_Quoted'Access,
Test_Common_Prefix_Length'Access
);
end SP.Strings.Tests;
|
with Ada.Text_IO;
package package_renaming_declaration is
package IO renames Ada.Text_IO;
end package_renaming_declaration;
|
pragma Ada_2012;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with System;
package bits_sched_h is
SCHED_OTHER : constant := 0; -- /usr/include/bits/sched.h:28
SCHED_FIFO : constant := 1; -- /usr/include/bits/sched.h:29
SCHED_RR : constant := 2; -- /usr/include/bits/sched.h:30
SCHED_BATCH : constant := 3; -- /usr/include/bits/sched.h:32
SCHED_ISO : constant := 4; -- /usr/include/bits/sched.h:33
SCHED_IDLE : constant := 5; -- /usr/include/bits/sched.h:34
SCHED_DEADLINE : constant := 6; -- /usr/include/bits/sched.h:35
SCHED_RESET_ON_FORK : constant := 16#40000000#; -- /usr/include/bits/sched.h:37
CSIGNAL : constant := 16#000000ff#; -- /usr/include/bits/sched.h:42
CLONE_VM : constant := 16#00000100#; -- /usr/include/bits/sched.h:43
CLONE_FS : constant := 16#00000200#; -- /usr/include/bits/sched.h:44
CLONE_FILES : constant := 16#00000400#; -- /usr/include/bits/sched.h:45
CLONE_SIGHAND : constant := 16#00000800#; -- /usr/include/bits/sched.h:46
CLONE_PIDFD : constant := 16#00001000#; -- /usr/include/bits/sched.h:47
CLONE_PTRACE : constant := 16#00002000#; -- /usr/include/bits/sched.h:49
CLONE_VFORK : constant := 16#00004000#; -- /usr/include/bits/sched.h:50
CLONE_PARENT : constant := 16#00008000#; -- /usr/include/bits/sched.h:52
CLONE_THREAD : constant := 16#00010000#; -- /usr/include/bits/sched.h:54
CLONE_NEWNS : constant := 16#00020000#; -- /usr/include/bits/sched.h:55
CLONE_SYSVSEM : constant := 16#00040000#; -- /usr/include/bits/sched.h:56
CLONE_SETTLS : constant := 16#00080000#; -- /usr/include/bits/sched.h:57
CLONE_PARENT_SETTID : constant := 16#00100000#; -- /usr/include/bits/sched.h:58
CLONE_CHILD_CLEARTID : constant := 16#00200000#; -- /usr/include/bits/sched.h:60
CLONE_DETACHED : constant := 16#00400000#; -- /usr/include/bits/sched.h:62
CLONE_UNTRACED : constant := 16#00800000#; -- /usr/include/bits/sched.h:63
CLONE_CHILD_SETTID : constant := 16#01000000#; -- /usr/include/bits/sched.h:65
CLONE_NEWCGROUP : constant := 16#02000000#; -- /usr/include/bits/sched.h:67
CLONE_NEWUTS : constant := 16#04000000#; -- /usr/include/bits/sched.h:68
CLONE_NEWIPC : constant := 16#08000000#; -- /usr/include/bits/sched.h:69
CLONE_NEWUSER : constant := 16#10000000#; -- /usr/include/bits/sched.h:70
CLONE_NEWPID : constant := 16#20000000#; -- /usr/include/bits/sched.h:71
CLONE_NEWNET : constant := 16#40000000#; -- /usr/include/bits/sched.h:72
CLONE_IO : constant := 16#80000000#; -- /usr/include/bits/sched.h:73
-- Definitions of constants and data structure for POSIX 1003.1b-1993
-- scheduling interface.
-- Copyright (C) 1996-2021 Free Software Foundation, Inc.
-- This file is part of the GNU C Library.
-- The GNU C Library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
-- The GNU C Library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Lesser General Public License for more details.
-- You should have received a copy of the GNU Lesser General Public
-- License along with the GNU C Library; if not, see
-- <https://www.gnu.org/licenses/>.
-- Scheduling algorithms.
-- Cloning flags.
-- Clone current process.
function clone
(uu_fn : access function (arg1 : System.Address) return int;
uu_child_stack : System.Address;
uu_flags : int;
uu_arg : System.Address -- , ...
) return int -- /usr/include/bits/sched.h:82
with Import => True,
Convention => C,
External_Name => "clone";
-- Unshare the specified resources.
function unshare (uu_flags : int) return int -- /usr/include/bits/sched.h:86
with Import => True,
Convention => C,
External_Name => "unshare";
-- Get index of currently used CPU.
function sched_getcpu return int -- /usr/include/bits/sched.h:89
with Import => True,
Convention => C,
External_Name => "sched_getcpu";
-- Get currently used CPU and NUMA node.
function getcpu (arg1 : access unsigned; arg2 : access unsigned) return int -- /usr/include/bits/sched.h:92
with Import => True,
Convention => C,
External_Name => "getcpu";
-- Switch process to namespace of type NSTYPE indicated by FD.
function setns (uu_fd : int; uu_nstype : int) return int -- /usr/include/bits/sched.h:95
with Import => True,
Convention => C,
External_Name => "setns";
end bits_sched_h;
|
Package body Dbase.Login is
CIB : Direct_Cursor;
function If_Exists (Usrnme : Unbounded_String) return Boolean is
Stmt : Prepared_Statement;
SQLstatement : Unbounded_String;
begin
SQLstatement := "SELECT * FROM users WHERE username = '"& Usrnme & "'";
Add (Standard_Window,
Line => 1,
Column => 1,
Str => To_String(SQLstatement));
refresh;
Stmt:= Prepare (To_String(SQLstatement), Index_By => Field_Index'First);
CIB.Fetch (Dbase.DB, Stmt);
if CIB.Has_Row then
return True;
else
return False;
end if;
end If_Exists;
function Fld (CI : Direct_Cursor; FldNme : String) return Unbounded_String is
begin
for i in 0..CI.Field_Count-1 loop
if CI.Field_Name(i) = FldNme then
return To_Unbounded_String(CI.Value(i));
end if;
end loop;
Display_Warning.Warning("No Field " & FldNme);
return To_Unbounded_String(FldNme) & " Not Found";
end;
procedure Create_User is
UserName, FullName, Password, Password2, Fname : Unbounded_String;
NowDate : Time := Clock;
CreateDate, SQLstatement : Unbounded_String;
Width,Columns : Column_Position := 50;
Length,Lines : Line_Position := 8;
Display_Window : Window;
Stmt : Prepared_Statement;
begin
if Dbase.Scroller.OpenDb then
Get_Size(Number_Of_Lines => Lines,Number_Of_Columns => Columns);
Display_Window := Sub_Window(Win => Standard_Window,
Number_Of_Lines => Length,
Number_Of_Columns => Width,
First_Line_Position => (Lines - Length) / 2,
First_Column_Position => (Columns - Width) / 2);
Clear(Display_Window);
Box(Display_Window);
loop
Add (Display_Window,Line => 2,Column => 2,Str => "UserName : ");
Texaco.Line_Editor(Display_Window,
StartLine => 2,
StartColumn => 15,
Editlength => 16,
Edline => UserName,
MaxLength => 15,
SuppressSpaces => True);
Fname := To_Unbounded_String(Ada.Strings.Fixed.Translate(To_String(UserName),
Ada.Strings.Maps.Constants.Lower_Case_Map));
if If_Exists (FName) then
Display_Warning.Warning("That Username is already in use",Down => Integer(Length-1));
UserName := To_Unbounded_String("");
Redraw(Display_Window,0,Integer(Length)-1);
Refresh(Display_Window);
end if;
exit when UserName /= "";
end loop;
loop
Add (Display_Window,Line => 3,Column => 2,Str => "Full Name : ");
Texaco.Line_Editor(Display_Window,
StartLine => 3,
StartColumn => 15,
Editlength => 31,
Edline => FullName,
MaxLength => 30);
exit when FullName /= "";
end loop;
loop
Add (Display_Window,Line => 4,Column => 2,Str => "Password : ");
Texaco.Password_Editor(Display_Window,
StartLine => 4,
StartColumn => 15,
Edline => Password,
MaxLength => 15);
Add (Display_Window,Line => 5,Column => 2,Str => "Re-Type Password : ");
Texaco.Password_Editor(Display_Window,
StartLine => 5,
StartColumn => 21,
Edline => Password2,
MaxLength => 15);
if Password /= Password2 then
Display_Warning.Warning("Passwords Do Not Match",Down => Integer(Length-1));
Password := To_Unbounded_String("");
Password2 := To_Unbounded_String("");
end if;
exit when Password /= "";
end loop;
if Display_Warning.GetYN("Do You want to save this User Y/N",Down => Integer(Length-1)) then
CreateDate := To_Unbounded_String(Image (NowDate));
SQLstatement := SQLstatement & "INSERT INTO users (username,fullname,password) VALUES (";
SQLstatement := SQLstatement & "'"&Fname&"','"&FullName&"','"&Password&"')";
Add (Standard_Window,
Line => 1,
Column => 1,
Str => To_String(SQLstatement));
refresh;
Stmt:= Prepare (To_String(SQLstatement));
Dbase.DB.Execute(Stmt);
Dbase.DB.Commit;
if Dbase.DB.Success then
Display_Warning.Warning("New User Created");
else
Display_Warning.Warning("Create User Failed");
end if;
end if;
Dbase.Scroller.CloseDb;
else
Display_Warning.Warning("No Open Universe DB");
end if;
Clear(Display_Window);
Refresh(Display_Window);
Delete (Win => Display_Window);
end Create_User;
procedure Login_User is
InputUserName, InputPassword, Fname, UserName,FullName,Password : Unbounded_String;
Width,Columns : Column_Position := 50;
Length,Lines : Line_Position := 8;
Display_Window : Window;
begin
if Dbase.Scroller.OpenDb then
Get_Size(Number_Of_Lines => Lines,Number_Of_Columns => Columns);
Display_Window := Sub_Window(Win => Standard_Window,
Number_Of_Lines => Length,
Number_Of_Columns => Width,
First_Line_Position => (Lines - Length) / 2,
First_Column_Position => (Columns - Width) / 2);
Clear(Display_Window);
Box(Display_Window);
loop
Add (Display_Window,Line => 2,Column => 2,Str => "UserName : ");
Texaco.Line_Editor(Display_Window,
StartLine => 2,
StartColumn => 15,
Editlength => 16,
Edline => InputUserName,
MaxLength => 15,
SuppressSpaces => True);
exit when InputUserName /= "";
end loop;
loop
Add (Display_Window,Line => 3,Column => 2,Str => "Password : ");
Texaco.Password_Editor(Display_Window,
StartLine => 3,
StartColumn => 15,
Edline => InputPassword,
MaxLength => 15);
exit when InputPassword /= "";
end loop;
Fname := To_Unbounded_String(Ada.Strings.Fixed.Translate(To_String(InputUserName),
Ada.Strings.Maps.Constants.Lower_Case_Map));
if IF_Exists (FName) then
Password := Fld(CIB,"password");
if InputPassword = Password then
UserLoggedIn := True;
UserLoggedName := Fld(CIB,"username");
UserLoggedFullName := Fld(CIB,"fullname");
UserLoggedUserId := Fld(CIB,"user_id");
Display_Warning.Warning(To_String("Logged in "& UserLoggedName),Down => Integer(Length-1));
else
Display_Warning.Warning("Login Failed",Down => Integer(Length-1));
end if;
else
Display_Warning.Warning("Login Failed",Down => Integer(Length-1));
end if;
Dbase.Scroller.CloseDb;
end if;
Clear(Display_Window);
Refresh(Display_Window);
Delete (Win => Display_Window);
end Login_User;
end Dbase.Login;
|
--
-- Copyright 2018 The wookey project team <wookey@ssi.gouv.fr>
-- - Ryad Benadjila
-- - Arnauld Michelizza
-- - Mathieu Renard
-- - Philippe Thierry
-- - Philippe Trebuchet
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
--
with ewok.tasks_shared; use ewok.tasks_shared;
with ewok.devices_shared;
with config.applications; use config.applications; -- generated
package ewok.memory
with spark_mode => on
is
type t_mask is array (unsigned_8 range 1 .. 8) of bit
with pack, size => 8;
function to_unsigned_8 is new ada.unchecked_conversion
(t_mask, unsigned_8);
-- Initialize the memory backend
procedure init
(success : out boolean);
-- Zerofiy BSS section of given task in RAM.
procedure zeroify_bss
(id : in t_real_task_id)
with inline;
-- Map application data section from storage to RAM
procedure copy_data_to_ram
(id : in t_real_task_id)
with inline;
-- Map task's code and data sections
procedure map_code_and_data
(id : in t_real_task_id)
with inline;
-- Unmap the overall userspace content
procedure unmap_user_code_and_data
with inline;
-- Return true if there is enough space in memory
-- to map another element to the currently scheduled task
function device_can_be_mapped return boolean
with inline;
-- Map/unmap a device into memory
procedure map_device
(dev_id : in ewok.devices_shared.t_registered_device_id;
success : out boolean)
with inline;
procedure unmap_device
(dev_id : in ewok.devices_shared.t_registered_device_id)
with inline;
procedure unmap_all_devices
with inline;
-- Map the whole task (code, data and related devices) in memory
procedure map_task (id : in t_task_id)
with inline;
end ewok.memory;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure Test is
procedure t is begin new_line; end;
type T is record A: Integer; end record;
begin New_Line; end;
|
-- CD1009Z.ADA
-- Grant of Unlimited Rights
--
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
-- unlimited rights in the software and documentation contained herein.
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
-- this public release, the Government intends to confer upon all
-- recipients unlimited rights equal to those held by the Government.
-- These rights include rights to use, duplicate, release or disclose the
-- released technical data and computer software in whole or in part, in
-- any manner and for any purpose whatsoever, and to have or permit others
-- to do so.
--
-- DISCLAIMER
--
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
-- PARTICULAR PURPOSE OF SAID MATERIAL.
--*
-- OBJECTIVE:
-- CHECK THAT A RECORD REPRESENTATION CLAUSE MAY BE GIVEN IN THE
-- PRIVATE PART OF A PACKAGE FOR A LIMITED-PRIVATE TYPE, WHOSE
-- FULL TYPE DECLARATION IS A RECORD TYPE, DECLARED IN THE VISIBLE
-- PART OF THE SAME PACKAGE.
-- HISTORY:
-- VCL 10/09/87 CREATED ORIGINAL TEST.
-- BCB 03/20/89 CHANGED EXTENSION FROM '.ADA' TO '.DEP', CORRECTED
-- CHECKS FOR FAILURE.
WITH SYSTEM;
WITH REPORT; USE REPORT;
PROCEDURE CD1009Z IS
BEGIN
TEST ("CD1009Z", "A RECORD REPRESENTATION CLAUSE MAY BE GIVEN " &
"IN THE PRIVATE PART OF A PACKAGE FOR A " &
"LIMITED PRIVATE TYPE, WHOSE FULL TYPE " &
"DECLARATION IS A RECORD TYPE DECLARED IN THE " &
"VISIBLE PART OF THE SAME PACKAGE");
DECLARE
PACKAGE PACK IS
UNITS_PER_INTEGER : CONSTANT :=
(INTEGER'SIZE + SYSTEM.STORAGE_UNIT - 1) /
SYSTEM.STORAGE_UNIT;
TYPE CHECK_TYPE_1 IS LIMITED PRIVATE;
PROCEDURE P;
PRIVATE
TYPE CHECK_TYPE_1 IS
RECORD
I1 : INTEGER RANGE 0 .. 255;
B1 : BOOLEAN;
B2 : BOOLEAN;
I2 : INTEGER RANGE 0 .. 15;
END RECORD;
FOR CHECK_TYPE_1 USE
RECORD
I1 AT 0 * UNITS_PER_INTEGER
RANGE 0 .. INTEGER'SIZE - 1;
B1 AT 1 * UNITS_PER_INTEGER
RANGE 0 .. BOOLEAN'SIZE - 1;
B2 AT 2 * UNITS_PER_INTEGER
RANGE 0 .. BOOLEAN'SIZE - 1;
I2 AT 3 * UNITS_PER_INTEGER
RANGE 0 .. INTEGER'SIZE - 1;
END RECORD;
END PACK;
PACKAGE BODY PACK IS
PROCEDURE P IS
R1 : CHECK_TYPE_1;
BEGIN
IF R1.I1'FIRST_BIT /= 0 OR
R1.I1'LAST_BIT /= INTEGER'SIZE - 1 OR
R1.I1'POSITION /= 0 THEN
FAILED ("INCORRECT REPRESENTATION FOR R1.I1");
END IF;
IF R1.B1'FIRST_BIT /= 0 OR
R1.B1'LAST_BIT /= BOOLEAN'SIZE - 1 OR
R1.B1'POSITION /= 1 * UNITS_PER_INTEGER
THEN
FAILED ("INCORRECT REPRESENTATION FOR R1.B1");
END IF;
IF R1.B2'FIRST_BIT /= 0 OR
R1.B2'LAST_BIT /= BOOLEAN'SIZE - 1 OR
R1.B2'POSITION /= 2 * UNITS_PER_INTEGER
THEN
FAILED ("INCORRECT REPRESENTATION FOR R1.B2");
END IF;
IF R1.I2'FIRST_BIT /= 0 OR
R1.I2'LAST_BIT /= INTEGER'SIZE - 1 OR
R1.I2'POSITION /= 3 * UNITS_PER_INTEGER
THEN
FAILED ("INCORRECT REPRESENTATION FOR R1.I2");
END IF;
END P;
END PACK;
USE PACK;
BEGIN
P;
END;
RESULT;
END CD1009Z;
|
-- WORDS, a Latin dictionary, by Colonel William Whitaker (USAF, Retired)
--
-- Copyright William A. Whitaker (1936–2010)
--
-- This is a free program, which means it is proper to copy it and pass
-- it on to your friends. Consider it a developmental item for which
-- there is no charge. However, just for form, it is Copyrighted
-- (c). Permission is hereby freely given for any and all use of program
-- and data. You can sell it as your own, but at least tell me.
--
-- This version is distributed without obligation, but the developer
-- would appreciate comments and suggestions.
--
-- All parts of the WORDS system, source code and data files, are made freely
-- available to anyone who wishes to use them, for whatever purpose.
with Ada.Text_IO;
package Support_Utils.Word_Parameters is
-- This package defines a number of parameters that are used in the program
-- The default values are set in the body, so that they may be changed
-- easily
Change_Parameters_Character : Character := '#';
Change_Language_Character : Character := '~';
Help_Character : Character := '?';
-- These files are used by the program if requested, but not necessary
-- They are all text files and human readable
-- MODE_FILE is used by the program to remember MODE values between runs
Mode_File : Ada.Text_IO.File_Type;
-- OUTPUT is used to Write out and save the results of a run
Output : aliased Ada.Text_IO.File_Type;
Input : Ada.Text_IO.File_Type;
-- UNKNOWNS is used to record the words that the program fails to find
Unknowns : Ada.Text_IO.File_Type;
-- This is a flag to tell if there has been Trim ming for this word
-- FIXME : this obviously should not exist
Trimmed : Boolean := False;
type Mode_Type is (
Trim_Output,
Have_Output_File,
Write_Output_To_File,
Do_Unknowns_Only,
Write_Unknowns_To_File,
Ignore_Unknown_Names,
Ignore_Unknown_Caps,
Do_Compounds,
Do_Fixes,
Do_Tricks,
Do_Dictionary_Forms,
Show_Age,
Show_Frequency,
Do_Examples,
Do_Only_Meanings,
Do_Stems_For_Unknown
);
package Mode_Type_Io is new Ada.Text_IO.Enumeration_IO (Mode_Type);
type Mode_Array is array (Mode_Type) of Boolean;
Words_Mode : Mode_Array; -- Initialized in body
procedure Change_Parameters;
procedure Initialize_Word_Parameters;
end Support_Utils.Word_Parameters;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2017 onox <denkpadje@gmail.com>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with GL.Low_Level.Enums;
with GL.Pixels;
with GL.Types;
with Orka.Strings;
package body Orka.Rendering.Textures is
procedure Bind
(Object : GL.Objects.Textures.Texture_Base'Class;
Target : Indexed_Texture_Target;
Index : Natural) is
begin
case Target is
when Texture =>
Object.Bind_Texture_Unit (GL.Types.UInt (Index));
when Image =>
Object.Bind_Image_Texture (GL.Types.UInt (Index));
end case;
end Bind;
function Bayer_Dithering_Pattern return GL.Objects.Samplers.Sampler is
use all type GL.Objects.Textures.Minifying_Function;
use all type GL.Objects.Textures.Wrapping_Mode;
begin
return Result : GL.Objects.Samplers.Sampler do
Result.Set_X_Wrapping (Repeat);
Result.Set_Y_Wrapping (Repeat);
Result.Set_Minifying_Filter (Nearest);
Result.Set_Magnifying_Filter (Nearest);
end return;
end Bayer_Dithering_Pattern;
function Bayer_Dithering_Pattern return GL.Objects.Textures.Texture is
Pixels : aliased constant GL.Types.UByte_Array
:= (0, 32, 8, 40, 2, 34, 10, 42,
48, 16, 56, 24, 50, 18, 58, 26,
12, 44, 4, 36, 14, 46, 6, 38,
60, 28, 52, 20, 62, 30, 54, 22,
3, 35, 11, 43, 1, 33, 9, 41,
51, 19, 59, 27, 49, 17, 57, 25,
15, 47, 7, 39, 13, 45, 5, 37,
63, 31, 55, 23, 61, 29, 53, 21);
-- * Bayer, B. E. (1973). An optimum method for two-level rendition of
-- continuous-tone pictures. In IEEE Int. Conf. on Communications
-- (Vol. 26, pp. 11-15).
-- * http://www.anisopteragames.com/how-to-fix-color-banding-with-dithering/
begin
return Result : GL.Objects.Textures.Texture (GL.Low_Level.Enums.Texture_2D) do
Result.Allocate_Storage (1, 1, GL.Pixels.R8, Width => 8, Height => 8, Depth => 1);
Result.Load_From_Data
(Level => 0,
Width => 8, Height => 8, Depth => 1,
Source_Format => GL.Pixels.Red,
Source_Type => GL.Pixels.Unsigned_Byte,
Source => Pixels'Address);
end return;
end Bayer_Dithering_Pattern;
function Image
(Texture : GL.Objects.Textures.Texture;
Level : GL.Objects.Textures.Mipmap_Level := 0) return String
is
Width : constant String := Orka.Strings.Trim (Texture.Width (Level)'Image);
Height : constant String := Orka.Strings.Trim (Texture.Height (Level)'Image);
Depth : constant String := Orka.Strings.Trim (Texture.Depth (Level)'Image);
begin
return (if Texture.Allocated then "" else "unallocated ") &
Width & " × " & Height & " × " & Depth & " " & Texture.Kind'Image &
" with " &
(if Texture.Compressed then
Texture.Compressed_Format'Image
else
Texture.Internal_Format'Image) & " format";
end Image;
end Orka.Rendering.Textures;
|
with
lace.Event,
lace.Response,
lace.Observer;
private
with
ada.Containers.indefinite_hashed_Maps,
ada.Strings.Hash;
generic
type T is abstract tagged limited private;
package lace.make_Observer
--
-- Makes a user class T into an event Observer.
--
is
pragma remote_Types;
type Item is abstract limited new T
and Observer.item with private;
type View is access all Item'Class;
procedure destroy (Self : in out Item);
-- Responses
--
overriding
procedure add (Self : access Item; the_Response : in Response.view;
to_Kind : in event.Kind;
from_Subject : in Event.subject_Name);
overriding
procedure rid (Self : access Item; the_Response : in Response.view;
to_Kind : in event.Kind;
from_Subject : in Event.subject_Name);
overriding
procedure relay_responseless_Events (Self : in out Item; To : in Observer.view);
-- Operations
--
overriding
procedure receive (Self : access Item; the_Event : in Event.item'Class := event.null_Event;
from_Subject : in Event.subject_Name);
overriding
procedure respond (Self : access Item);
private
-- Event response maps
--
use type event.Kind;
use type Response.view;
package event_response_Maps is new ada.Containers.indefinite_hashed_Maps (key_type => event.Kind,
element_type => Response.view,
hash => event.Hash,
equivalent_keys => "=");
subtype event_response_Map is event_response_Maps.Map;
type event_response_Map_view is access all event_response_Map;
-- Subject maps of event responses
--
package subject_Maps_of_event_responses
is new ada.Containers.indefinite_hashed_Maps (key_type => Event.subject_Name,
element_type => event_response_Map_view,
hash => ada.strings.Hash,
equivalent_keys => "=");
subtype subject_Map_of_event_responses is subject_Maps_of_event_responses.Map;
protected
type safe_Responses
is
procedure destroy;
-- Responses
--
procedure add (Self : access Item'Class;
the_Response : in Response.view;
to_Kind : in event.Kind;
from_Subject : in Event.subject_Name);
procedure rid (Self : access Item'Class;
the_Response : in Response.view;
to_Kind : in event.Kind;
from_Subject : in Event.subject_Name);
procedure relay_responseless_Events (To : in Observer.view);
function relay_Target return Observer.view;
function Contains (Subject : in Event.subject_Name) return Boolean;
function Element (Subject : in Event.subject_Name) return event_response_Map;
-- Operations
--
procedure receive (Self : access Item'Class;
the_Event : in Event.item'Class := event.null_Event;
from_Subject : in Event.subject_Name);
private
my_Responses : subject_Map_of_event_responses;
my_relay_Target : Observer.view;
end safe_Responses;
-- Observer Item
--
type Item is abstract limited new T
and Observer.item
with
record
Responses : safe_Responses;
end record;
end lace.make_Observer;
|
with AdaM.Assist.Query.find_All.Metrics;
with Ada.Wide_Text_IO;
with Ada.Characters.Handling;
with Ada.Exceptions;
with Asis.Exceptions;
with Asis.Errors;
with Asis.Implementation,
asis.Elements;
separate (AdaM.Assist.Query.find_All.Actuals_for_traversing)
procedure Post_Op
(Element : Asis.Element;
Control : in out Asis.Traverse_Control;
State : in out Traversal_State)
is
pragma Unreferenced (Control);
use Asis, asis.Elements;
the_Declaration : constant asis.Declaration := asis.Declaration (Element);
the_Kind : constant Asis.Declaration_Kinds := asis.Elements.Declaration_Kind (the_Declaration);
begin
if Is_Nil (State.ignore_Starter)
then
State.parent_Stack.delete_Last; -- Children no longer need to know their parent.
else
if Is_Equal (Element, State.ignore_Starter)
then
State.ignore_Starter := Nil_Element;
end if;
end if;
if the_Kind = Asis.A_Package_Declaration
then
if not Metrics.current_Packages.Is_Empty
then
Metrics.current_Packages.delete_Last; -- Pop the current package stack.
end if;
end if;
exception
when Ex : Asis.Exceptions.ASIS_Inappropriate_Context |
Asis.Exceptions.ASIS_Inappropriate_Container |
Asis.Exceptions.ASIS_Inappropriate_Compilation_Unit |
Asis.Exceptions.ASIS_Inappropriate_Element |
Asis.Exceptions.ASIS_Inappropriate_Line |
Asis.Exceptions.ASIS_Inappropriate_Line_Number |
Asis.Exceptions.ASIS_Failed =>
Ada.Wide_Text_IO.Put ("Post_Op : ASIS exception (");
Ada.Wide_Text_IO.Put (Ada.Characters.Handling.To_Wide_String (
Ada.Exceptions.Exception_Name (Ex)));
Ada.Wide_Text_IO.Put (") is raised");
Ada.Wide_Text_IO.New_Line;
Ada.Wide_Text_IO.Put ("ASIS Error Status is ");
Ada.Wide_Text_IO.Put
(Asis.Errors.Error_Kinds'Wide_Image (Asis.Implementation.Status));
Ada.Wide_Text_IO.New_Line;
Ada.Wide_Text_IO.Put ("ASIS Diagnosis is ");
Ada.Wide_Text_IO.New_Line;
Ada.Wide_Text_IO.Put (Asis.Implementation.Diagnosis);
Ada.Wide_Text_IO.New_Line;
Asis.Implementation.Set_Status;
when Ex : others =>
Ada.Wide_Text_IO.Put ("Post_Op : ");
Ada.Wide_Text_IO.Put (Ada.Characters.Handling.To_Wide_String (
Ada.Exceptions.Exception_Name (Ex)));
Ada.Wide_Text_IO.Put (" is raised (");
Ada.Wide_Text_IO.Put (Ada.Characters.Handling.To_Wide_String (
Ada.Exceptions.Exception_Information (Ex)));
Ada.Wide_Text_IO.Put (")");
Ada.Wide_Text_IO.New_Line;
end Post_Op;
|
with System.Address_Image; -- debug
pragma Warnings (Off);
with System.Finalization_Masters;
pragma Warnings (On);
with C.sys.mman;
separate (GC.Pools)
package body Finalization is
use type System.Finalization_Masters.Finalize_Address_Ptr; -- debug
use type System.Storage_Elements.Integer_Address;
use type C.signed_int;
use type C.unsigned_int;
package SysFM renames System.Finalization_Masters; -- short name
function To_FM_Node_Ptr is
new Ada.Unchecked_Conversion (System.Address, SysFM.FM_Node_Ptr);
type Relative_Address is mod 2 ** 32;
type jmp_Rec is record
Code : System.Storage_Elements.Storage_Element;
Data : Relative_Address;
end record;
pragma Pack (jmp_Rec);
Old_Instruction : jmp_Rec;
Allocating_Object : System.Address := System.Null_Address;
procedure Custom_Set_Finalize_Address_Unprotected (
Master : in out SysFM.Finalization_Master;
Fin_Addr_Ptr : in SysFM.Finalize_Address_Ptr);
procedure Custom_Set_Finalize_Address_Unprotected (
Master : in out SysFM.Finalization_Master;
Fin_Addr_Ptr : in SysFM.Finalize_Address_Ptr) is
begin
if Allocating_Object = System.Null_Address then
-- un-hook
declare
jmp : jmp_Rec;
for jmp'Address use SysFM.Set_Finalize_Address_Unprotected'Code_Address;
begin
jmp := Old_Instruction;
end;
-- call original
SysFM.Set_Finalize_Address_Unprotected (Master, Fin_Addr_Ptr);
-- re-hook
Initialize;
else
pragma Assert (Fin_Addr_Ptr /= null);
SysFM.Set_Is_Heterogeneous (Master);
SysFM.Set_Heterogeneous_Finalize_Address_Unprotected (
Allocating_Object,
Fin_Addr_Ptr);
Allocating_Object := System.Null_Address;
end if;
end Custom_Set_Finalize_Address_Unprotected;
-- implementation
procedure Initialize is
-- hook Set_Heterogeneous_Finalize_Address_Unprotected
Page_Size : constant := 4096;
Old_Target : constant System.Address :=
SysFM.Set_Finalize_Address_Unprotected'Code_Address;
New_Target : constant System.Address :=
Custom_Set_Finalize_Address_Unprotected'Code_Address;
jmp_Rec_Size : constant System.Storage_Elements.Storage_Count :=
jmp_Rec'Size / Standard'Storage_Unit;
jmp : jmp_Rec;
for jmp'Address use Old_Target;
Result : C.signed_int;
begin
-- make code memory as writable
Result :=
C.sys.mman.mprotect (
C.void_ptr (
System.Storage_Elements.To_Address (
System.Storage_Elements.To_Integer (Old_Target) and not (Page_Size - 1))),
C.size_t (Page_Size),
C.signed_int (
C.unsigned_int'(
C.sys.mman.PROT_READ or C.sys.mman.PROT_WRITE or C.sys.mman.PROT_EXEC)));
pragma Assert (Result = 0);
-- save
Old_Instruction := jmp;
-- make jmp instruction
jmp.Code := 16#e9#;
jmp.Data :=
Relative_Address'Mod (
System.Storage_Elements.To_Integer (New_Target)
- System.Storage_Elements.To_Integer (Old_Target)
- System.Storage_Elements.Integer_Address (jmp_Rec_Size));
end Initialize;
function Controlled_Size_In_Storage_Elements
return System.Storage_Elements.Storage_Count is
begin
return (SysFM.FM_Node'Size + System.Word_Size - 1) / System.Word_Size;
end Controlled_Size_In_Storage_Elements;
procedure After_Allocation (Storage_Address : in System.Address) is
begin
Allocating_Object := Storage_Address + SysFM.Header_Size;
end After_Allocation;
procedure Finalize_Controlled (obj : C.void_ptr; cd : C.void_ptr) is
pragma Unreferenced (cd);
Obj_Addr : constant System.Address := System.Address (obj) + SysFM.Header_Size;
Do_Finalize : constant SysFM.Finalize_Address_Ptr :=
SysFM.Finalize_Address_Unprotected (Obj_Addr);
begin
SysFM.Detach_Unprotected (To_FM_Node_Ptr (System.Address (obj)));
pragma Assert (
Do_Finalize /= null,
"Finalize_Address_Unprotected (" & System.Address_Image (Obj_Addr)
& ") = null");
Do_Finalize.all (Obj_Addr);
SysFM.Delete_Finalize_Address_Unprotected (Obj_Addr);
end Finalize_Controlled;
end Finalization;
|
-----------------------------------------------------------------------
-- components-ajax-factory -- Factory for AJAX Components
-- Copyright (C) 2011 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with ASF.Components.Base;
with ASF.Views.Nodes;
with ASF.Components.Ajax.Includes;
package body ASF.Components.Ajax.Factory is
function Create_Include return Base.UIComponent_Access;
-- ------------------------------
-- Create an UIInclude component
-- ------------------------------
function Create_Include return Base.UIComponent_Access is
begin
return new ASF.Components.Ajax.Includes.UIInclude;
end Create_Include;
use ASF.Views.Nodes;
URI : aliased constant String := "http://code.google.com/p/ada-asf/ajax";
INCLUDE_TAG : aliased constant String := "include";
Ajax_Bindings : aliased constant ASF.Factory.Binding_Array
:= (1 => (Name => INCLUDE_TAG'Access,
Component => Create_Include'Access,
Tag => Create_Component_Node'Access)
);
Ajax_Factory : aliased constant ASF.Factory.Factory_Bindings
:= (URI => URI'Access, Bindings => Ajax_Bindings'Access);
-- ------------------------------
-- Get the Ajax component factory.
-- ------------------------------
function Definition return ASF.Factory.Factory_Bindings_Access is
begin
return Ajax_Factory'Access;
end Definition;
end ASF.Components.Ajax.Factory;
|
------------------------------------------------------------------------------
-- A d a r u n - t i m e s p e c i f i c a t i o n --
-- ASIS implementation for Gela project, a portable Ada compiler --
-- http://gela.ada-ru.org --
-- - - - - - - - - - - - - - - - --
-- Read copyright and license at the end of ada.ads file --
------------------------------------------------------------------------------
-- $Revision: 209 $ $Date: 2013-11-30 21:03:24 +0200 (Сб., 30 нояб. 2013) $
package Ada.Strings.Wide_Maps is
pragma Preelaborate (Wide_Maps);
-- Representation for a set of Wide_Character values:
type Wide_Character_Set is private;
pragma Preelaborable_Initialization (Wide_Character_Set);
Null_Set : constant Wide_Character_Set;
type Wide_Character_Range is
record
Low : Wide_Character;
High : Wide_Character;
end record;
-- Represents Wide_Character range Low..High
type Wide_Character_Ranges is array (Positive range <>)
of Wide_Character_Range;
function To_Set (Ranges : in Wide_Character_Ranges)
return Wide_Character_Set;
function To_Set (Span : in Wide_Character_Range)
return Wide_Character_Set;
function To_Ranges (Set : in Wide_Character_Set)
return Wide_Character_Ranges;
function "=" (Left, Right : in Wide_Character_Set) return Boolean;
function "not" (Right : in Wide_Character_Set)
return Wide_Character_Set;
function "and" (Left, Right : in Wide_Character_Set)
return Wide_Character_Set;
function "or" (Left, Right : in Wide_Character_Set)
return Wide_Character_Set;
function "xor" (Left, Right : in Wide_Character_Set)
return Wide_Character_Set;
function "-" (Left, Right : in Wide_Character_Set)
return Wide_Character_Set;
function Is_In (Element : in Wide_Character;
Set : in Wide_Character_Set)
return Boolean;
function Is_Subset (Elements : in Wide_Character_Set;
Set : in Wide_Character_Set)
return Boolean;
function "<=" (Left : in Wide_Character_Set;
Right : in Wide_Character_Set)
return Boolean renames Is_Subset;
-- Alternative representation for a set of Wide_Character values:
subtype Wide_Character_Sequence is Wide_String;
function To_Set (Sequence : in Wide_Character_Sequence)
return Wide_Character_Set;
function To_Set (Singleton : in Wide_Character)
return Wide_Character_Set;
function To_Sequence (Set : in Wide_Character_Set)
return Wide_Character_Sequence;
-- Representation for a Wide_Character to Wide_Character mapping:
type Wide_Character_Mapping is private;
pragma Preelaborable_Initialization (Wide_Character_Mapping);
function Value (Map : in Wide_Character_Mapping;
Element : in Wide_Character)
return Wide_Character;
Identity : constant Wide_Character_Mapping;
function To_Mapping (From, To : in Wide_Character_Sequence)
return Wide_Character_Mapping;
function To_Domain (Map : in Wide_Character_Mapping)
return Wide_Character_Sequence;
function To_Range (Map : in Wide_Character_Mapping)
return Wide_Character_Sequence;
type Wide_Character_Mapping_Function is
access function (From : in Wide_Character) return Wide_Character;
private
pragma Import (Ada, Wide_Character_Set);
pragma Import (Ada, Null_Set);
pragma Import (Ada, Wide_Character_Mapping);
pragma Import (Ada, Identity);
end Ada.Strings.Wide_Maps;
|
with Screen_Interface; use Screen_Interface;
with Trains;
package Tracks_Display is
type Track_Points is array (Positive range <>) of Point;
type Track_T;
type Track_Access is access all Track_T;
type Switch_States is (S1, S2);
type Switch is array (Switch_States) of Track_Access;
type Entry_Sign_Position is (Top, Left, Bottom, Right);
type Entry_Sign_Color is (Green, Orange, Red);
type Entry_Sign_T is record
Coord : Point := (0, 0);
Color : Entry_Sign_Color := Green;
Disabled : Boolean := false;
end record;
type Track_T (Nb_Points : Positive) is record
Id : Trains.Track_Opt_Id := Trains.No_Track_Id;
Entry_Sign : Entry_Sign_T;
Points : Track_Points (1 .. Nb_Points);
Is_Straight : Boolean := False;
Switchable : Boolean := False;
Switch_State : Switch_States := S1;
Exits : Switch;
end record;
type Bogie is record
Track : Track_Access;
Track_Pos : Positive;
end record;
type Bogie_Array is array (Positive range <>) of Bogie;
type Train_T (Nb_Bogies : Positive) is record
Id : Trains.Train_Id;
Bogies : Bogie_Array (1 .. Nb_Bogies);
Speed : Natural := 0;
end record;
procedure Build_Straight_Track (Track : in out Track_T; Start, Stop : Point);
procedure Build_Curve_Track (Track : in out Track_T; P1, P2, P3, P4 : Point);
procedure Connect_Track (Track : in out Track_T; E1, E2 : Track_Access);
function Start_Coord (Track : Track_T) return Point;
function end_Coord (Track : Track_T) return Point;
procedure Set_Sign_Position (Track : in out Track_T;
Pos : Entry_Sign_Position);
procedure Update_Sign (Track : in out Track_T);
procedure Change_Switch (Track : in out Track_T);
procedure Draw_Track (Track : Track_T);
procedure Draw_Switch (Track : Track_T);
procedure Init_Train (Train : in out Train_T; Track : Track_Access);
procedure Move_Train (Train : in out Train_T);
procedure Draw_Train (Train : Train_T);
function Get_Coords (Bog : Bogie) return Point;
end Tracks_Display;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- E X P _ P R A G --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Atree; use Atree;
with Casing; use Casing;
with Checks; use Checks;
with Debug; use Debug;
with Einfo; use Einfo;
with Errout; use Errout;
with Exp_Ch11; use Exp_Ch11;
with Exp_Util; use Exp_Util;
with Expander; use Expander;
with Inline; use Inline;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Restrict; use Restrict;
with Rident; use Rident;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Ch8; use Sem_Ch8;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
with Snames; use Snames;
with Stringt; use Stringt;
with Stand; use Stand;
with Tbuild; use Tbuild;
with Uintp; use Uintp;
with Validsw; use Validsw;
package body Exp_Prag is
-----------------------
-- Local Subprograms --
-----------------------
function Arg1 (N : Node_Id) return Node_Id;
function Arg2 (N : Node_Id) return Node_Id;
function Arg3 (N : Node_Id) return Node_Id;
-- Obtain specified pragma argument expression
procedure Expand_Pragma_Abort_Defer (N : Node_Id);
procedure Expand_Pragma_Check (N : Node_Id);
procedure Expand_Pragma_Common_Object (N : Node_Id);
procedure Expand_Pragma_Import_Or_Interface (N : Node_Id);
procedure Expand_Pragma_Inspection_Point (N : Node_Id);
procedure Expand_Pragma_Interrupt_Priority (N : Node_Id);
procedure Expand_Pragma_Loop_Variant (N : Node_Id);
procedure Expand_Pragma_Psect_Object (N : Node_Id);
procedure Expand_Pragma_Relative_Deadline (N : Node_Id);
procedure Expand_Pragma_Suppress_Initialization (N : Node_Id);
procedure Undo_Initialization (Def_Id : Entity_Id; N : Node_Id);
-- This procedure is used to undo initialization already done for Def_Id,
-- which is always an E_Variable, in response to the occurrence of the
-- pragma N, a pragma Interface, Import, or Suppress_Initialization. In all
-- these cases we want no initialization to occur, but we have already done
-- the initialization by the time we see the pragma, so we have to undo it.
----------
-- Arg1 --
----------
function Arg1 (N : Node_Id) return Node_Id is
Arg : constant Node_Id := First (Pragma_Argument_Associations (N));
begin
if Present (Arg)
and then Nkind (Arg) = N_Pragma_Argument_Association
then
return Expression (Arg);
else
return Arg;
end if;
end Arg1;
----------
-- Arg2 --
----------
function Arg2 (N : Node_Id) return Node_Id is
Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
begin
if No (Arg1) then
return Empty;
else
declare
Arg : constant Node_Id := Next (Arg1);
begin
if Present (Arg)
and then Nkind (Arg) = N_Pragma_Argument_Association
then
return Expression (Arg);
else
return Arg;
end if;
end;
end if;
end Arg2;
----------
-- Arg3 --
----------
function Arg3 (N : Node_Id) return Node_Id is
Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
begin
if No (Arg1) then
return Empty;
else
declare
Arg : Node_Id := Next (Arg1);
begin
if No (Arg) then
return Empty;
else
Next (Arg);
if Present (Arg)
and then Nkind (Arg) = N_Pragma_Argument_Association
then
return Expression (Arg);
else
return Arg;
end if;
end if;
end;
end if;
end Arg3;
---------------------
-- Expand_N_Pragma --
---------------------
procedure Expand_N_Pragma (N : Node_Id) is
Pname : constant Name_Id := Pragma_Name (N);
begin
-- Rewrite pragma ignored by Ignore_Pragma to null statement, so that
-- the back end or the expander here does not get overenthusiastic and
-- start processing such a pragma!
if Get_Name_Table_Boolean3 (Pname) then
Rewrite (N, Make_Null_Statement (Sloc (N)));
return;
end if;
case Get_Pragma_Id (Pname) is
-- Pragmas requiring special expander action
when Pragma_Abort_Defer =>
Expand_Pragma_Abort_Defer (N);
when Pragma_Check =>
Expand_Pragma_Check (N);
when Pragma_Common_Object =>
Expand_Pragma_Common_Object (N);
when Pragma_Import =>
Expand_Pragma_Import_Or_Interface (N);
when Pragma_Inspection_Point =>
Expand_Pragma_Inspection_Point (N);
when Pragma_Interface =>
Expand_Pragma_Import_Or_Interface (N);
when Pragma_Interrupt_Priority =>
Expand_Pragma_Interrupt_Priority (N);
when Pragma_Loop_Variant =>
Expand_Pragma_Loop_Variant (N);
when Pragma_Psect_Object =>
Expand_Pragma_Psect_Object (N);
when Pragma_Relative_Deadline =>
Expand_Pragma_Relative_Deadline (N);
when Pragma_Suppress_Initialization =>
Expand_Pragma_Suppress_Initialization (N);
-- All other pragmas need no expander action (includes
-- Unknown_Pragma).
when others => null;
end case;
end Expand_N_Pragma;
-------------------------------
-- Expand_Pragma_Abort_Defer --
-------------------------------
-- An Abort_Defer pragma appears as the first statement in a handled
-- statement sequence (right after the begin). It defers aborts for
-- the entire statement sequence, but not for any declarations or
-- handlers (if any) associated with this statement sequence.
-- The transformation is to transform
-- pragma Abort_Defer;
-- statements;
-- into
-- begin
-- Abort_Defer.all;
-- statements
-- exception
-- when all others =>
-- Abort_Undefer.all;
-- raise;
-- at end
-- Abort_Undefer_Direct;
-- end;
procedure Expand_Pragma_Abort_Defer (N : Node_Id) is
begin
-- Abort_Defer has no useful effect if Abort's are not allowed
if not Abort_Allowed then
return;
end if;
-- Normal case where abort is possible
declare
Loc : constant Source_Ptr := Sloc (N);
Stm : Node_Id;
Stms : List_Id;
HSS : Node_Id;
Blk : constant Entity_Id :=
New_Internal_Entity (E_Block, Current_Scope, Sloc (N), 'B');
AUD : constant Entity_Id := RTE (RE_Abort_Undefer_Direct);
begin
Stms := New_List (Build_Runtime_Call (Loc, RE_Abort_Defer));
loop
Stm := Remove_Next (N);
exit when No (Stm);
Append (Stm, Stms);
end loop;
HSS :=
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stms,
At_End_Proc => New_Occurrence_Of (AUD, Loc));
-- Present the Abort_Undefer_Direct function to the backend so that
-- it can inline the call to the function.
Add_Inlined_Body (AUD, N);
Rewrite (N,
Make_Block_Statement (Loc, Handled_Statement_Sequence => HSS));
Set_Scope (Blk, Current_Scope);
Set_Etype (Blk, Standard_Void_Type);
Set_Identifier (N, New_Occurrence_Of (Blk, Sloc (N)));
Expand_At_End_Handler (HSS, Blk);
Analyze (N);
end;
end Expand_Pragma_Abort_Defer;
--------------------------
-- Expand_Pragma_Check --
--------------------------
procedure Expand_Pragma_Check (N : Node_Id) is
Cond : constant Node_Id := Arg2 (N);
Nam : constant Name_Id := Chars (Arg1 (N));
Msg : Node_Id;
Loc : constant Source_Ptr := Sloc (First_Node (Cond));
-- Source location used in the case of a failed assertion: point to the
-- failing condition, not Loc. Note that the source location of the
-- expression is not usually the best choice here, because it points to
-- the location of the topmost tree node, which may be an operator in
-- the middle of the source text of the expression. For example, it gets
-- located on the last AND keyword in a chain of boolean expressiond
-- AND'ed together. It is best to put the message on the first character
-- of the condition, which is the effect of the First_Node call here.
-- This source location is used to build the default exception message,
-- and also as the sloc of the call to the runtime subprogram raising
-- Assert_Failure, so that coverage analysis tools can relate the
-- call to the failed check.
begin
-- Nothing to do if pragma is ignored
if Is_Ignored (N) then
return;
end if;
-- Since this check is active, rewrite the pragma into a corresponding
-- if statement, and then analyze the statement.
-- The normal case expansion transforms:
-- pragma Check (name, condition [,message]);
-- into
-- if not condition then
-- System.Assertions.Raise_Assert_Failure (Str);
-- end if;
-- where Str is the message if one is present, or the default of
-- name failed at file:line if no message is given (the "name failed
-- at" is omitted for name = Assertion, since it is redundant, given
-- that the name of the exception is Assert_Failure.)
-- Also, instead of "XXX failed at", we generate slightly
-- different messages for some of the contract assertions (see
-- code below for details).
-- An alternative expansion is used when the No_Exception_Propagation
-- restriction is active and there is a local Assert_Failure handler.
-- This is not a common combination of circumstances, but it occurs in
-- the context of Aunit and the zero footprint profile. In this case we
-- generate:
-- if not condition then
-- raise Assert_Failure;
-- end if;
-- This will then be transformed into a goto, and the local handler will
-- be able to handle the assert error (which would not be the case if a
-- call is made to the Raise_Assert_Failure procedure).
-- We also generate the direct raise if the Suppress_Exception_Locations
-- is active, since we don't want to generate messages in this case.
-- Note that the reason we do not always generate a direct raise is that
-- the form in which the procedure is called allows for more efficient
-- breakpointing of assertion errors.
-- Generate the appropriate if statement. Note that we consider this to
-- be an explicit conditional in the source, not an implicit if, so we
-- do not call Make_Implicit_If_Statement.
-- Case where we generate a direct raise
if ((Debug_Flag_Dot_G
or else Restriction_Active (No_Exception_Propagation))
and then Present (Find_Local_Handler (RTE (RE_Assert_Failure), N)))
or else (Opt.Exception_Locations_Suppressed and then No (Arg3 (N)))
then
Rewrite (N,
Make_If_Statement (Loc,
Condition => Make_Op_Not (Loc, Right_Opnd => Cond),
Then_Statements => New_List (
Make_Raise_Statement (Loc,
Name => New_Occurrence_Of (RTE (RE_Assert_Failure), Loc)))));
-- Case where we call the procedure
else
-- If we have a message given, use it
if Present (Arg3 (N)) then
Msg := Get_Pragma_Arg (Arg3 (N));
-- Here we have no string, so prepare one
else
declare
Loc_Str : constant String := Build_Location_String (Loc);
begin
Name_Len := 0;
-- For Assert, we just use the location
if Nam = Name_Assert then
null;
-- For predicate, we generate the string "predicate failed at
-- yyy". We prefer all lower case for predicate.
elsif Nam = Name_Predicate then
Add_Str_To_Name_Buffer ("predicate failed at ");
-- For special case of Precondition/Postcondition the string is
-- "failed xx from yy" where xx is precondition/postcondition
-- in all lower case. The reason for this different wording is
-- that the failure is not at the point of occurrence of the
-- pragma, unlike the other Check cases.
elsif Nam_In (Nam, Name_Precondition, Name_Postcondition) then
Get_Name_String (Nam);
Insert_Str_In_Name_Buffer ("failed ", 1);
Add_Str_To_Name_Buffer (" from ");
-- For special case of Invariant, the string is "failed
-- invariant from yy", to be consistent with the string that is
-- generated for the aspect case (the code later on checks for
-- this specific string to modify it in some cases, so this is
-- functionally important).
elsif Nam = Name_Invariant then
Add_Str_To_Name_Buffer ("failed invariant from ");
-- For all other checks, the string is "xxx failed at yyy"
-- where xxx is the check name with current source file casing.
else
Get_Name_String (Nam);
Set_Casing (Identifier_Casing (Current_Source_File));
Add_Str_To_Name_Buffer (" failed at ");
end if;
-- In all cases, add location string
Add_Str_To_Name_Buffer (Loc_Str);
-- Build the message
Msg := Make_String_Literal (Loc, Name_Buffer (1 .. Name_Len));
end;
end if;
-- Now rewrite as an if statement
Rewrite (N,
Make_If_Statement (Loc,
Condition => Make_Op_Not (Loc, Right_Opnd => Cond),
Then_Statements => New_List (
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Raise_Assert_Failure), Loc),
Parameter_Associations => New_List (Relocate_Node (Msg))))));
end if;
Analyze (N);
-- If new condition is always false, give a warning
if Warn_On_Assertion_Failure
and then Nkind (N) = N_Procedure_Call_Statement
and then Is_RTE (Entity (Name (N)), RE_Raise_Assert_Failure)
then
-- If original condition was a Standard.False, we assume that this is
-- indeed intended to raise assert error and no warning is required.
if Is_Entity_Name (Original_Node (Cond))
and then Entity (Original_Node (Cond)) = Standard_False
then
null;
elsif Nam = Name_Assert then
Error_Msg_N ("?A?assertion will fail at run time", N);
else
Error_Msg_N ("?A?check will fail at run time", N);
end if;
end if;
end Expand_Pragma_Check;
---------------------------------
-- Expand_Pragma_Common_Object --
---------------------------------
-- Use a machine attribute to replicate semantic effect in DEC Ada
-- pragma Machine_Attribute (intern_name, "common_object", extern_name);
-- For now we do nothing with the size attribute ???
-- Note: Psect_Object shares this processing
procedure Expand_Pragma_Common_Object (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Internal : constant Node_Id := Arg1 (N);
External : constant Node_Id := Arg2 (N);
Psect : Node_Id;
-- Psect value upper cased as string literal
Iloc : constant Source_Ptr := Sloc (Internal);
Eloc : constant Source_Ptr := Sloc (External);
Ploc : Source_Ptr;
begin
-- Acquire Psect value and fold to upper case
if Present (External) then
if Nkind (External) = N_String_Literal then
String_To_Name_Buffer (Strval (External));
else
Get_Name_String (Chars (External));
end if;
Set_All_Upper_Case;
Psect :=
Make_String_Literal (Eloc, Strval => String_From_Name_Buffer);
else
Get_Name_String (Chars (Internal));
Set_All_Upper_Case;
Psect :=
Make_String_Literal (Iloc, Strval => String_From_Name_Buffer);
end if;
Ploc := Sloc (Psect);
-- Insert the pragma
Insert_After_And_Analyze (N,
Make_Pragma (Loc,
Chars => Name_Machine_Attribute,
Pragma_Argument_Associations => New_List (
Make_Pragma_Argument_Association (Iloc,
Expression => New_Copy_Tree (Internal)),
Make_Pragma_Argument_Association (Eloc,
Expression =>
Make_String_Literal (Sloc => Ploc, Strval => "common_object")),
Make_Pragma_Argument_Association (Ploc,
Expression => New_Copy_Tree (Psect)))));
end Expand_Pragma_Common_Object;
----------------------------------
-- Expand_Pragma_Contract_Cases --
----------------------------------
-- Pragma Contract_Cases is expanded in the following manner:
-- subprogram S is
-- Count : Natural := 0;
-- Flag_1 : Boolean := False;
-- . . .
-- Flag_N : Boolean := False;
-- Flag_N+1 : Boolean := False; -- when "others" present
-- Pref_1 : ...;
-- . . .
-- Pref_M : ...;
-- <preconditions (if any)>
-- -- Evaluate all case guards
-- if Case_Guard_1 then
-- Flag_1 := True;
-- Count := Count + 1;
-- end if;
-- . . .
-- if Case_Guard_N then
-- Flag_N := True;
-- Count := Count + 1;
-- end if;
-- -- Emit errors depending on the number of case guards that
-- -- evaluated to True.
-- if Count = 0 then
-- raise Assertion_Error with "xxx contract cases incomplete";
-- <or>
-- Flag_N+1 := True; -- when "others" present
-- elsif Count > 1 then
-- declare
-- Str0 : constant String :=
-- "contract cases overlap for subprogram ABC";
-- Str1 : constant String :=
-- (if Flag_1 then
-- Str0 & "case guard at xxx evaluates to True"
-- else Str0);
-- StrN : constant String :=
-- (if Flag_N then
-- StrN-1 & "case guard at xxx evaluates to True"
-- else StrN-1);
-- begin
-- raise Assertion_Error with StrN;
-- end;
-- end if;
-- -- Evaluate all attribute 'Old prefixes found in the selected
-- -- consequence.
-- if Flag_1 then
-- Pref_1 := <prefix of 'Old found in Consequence_1>
-- . . .
-- elsif Flag_N then
-- Pref_M := <prefix of 'Old found in Consequence_N>
-- end if;
-- procedure _Postconditions is
-- begin
-- <postconditions (if any)>
-- if Flag_1 and then not Consequence_1 then
-- raise Assertion_Error with "failed contract case at xxx";
-- end if;
-- . . .
-- if Flag_N[+1] and then not Consequence_N[+1] then
-- raise Assertion_Error with "failed contract case at xxx";
-- end if;
-- end _Postconditions;
-- begin
-- . . .
-- end S;
procedure Expand_Pragma_Contract_Cases
(CCs : Node_Id;
Subp_Id : Entity_Id;
Decls : List_Id;
Stmts : in out List_Id)
is
Loc : constant Source_Ptr := Sloc (CCs);
procedure Case_Guard_Error
(Decls : List_Id;
Flag : Entity_Id;
Error_Loc : Source_Ptr;
Msg : in out Entity_Id);
-- Given a declarative list Decls, status flag Flag, the location of the
-- error and a string Msg, construct the following check:
-- Msg : constant String :=
-- (if Flag then
-- Msg & "case guard at Error_Loc evaluates to True"
-- else Msg);
-- The resulting code is added to Decls
procedure Consequence_Error
(Checks : in out Node_Id;
Flag : Entity_Id;
Conseq : Node_Id);
-- Given an if statement Checks, status flag Flag and a consequence
-- Conseq, construct the following check:
-- [els]if Flag and then not Conseq then
-- raise Assertion_Error
-- with "failed contract case at Sloc (Conseq)";
-- [end if;]
-- The resulting code is added to Checks
function Declaration_Of (Id : Entity_Id) return Node_Id;
-- Given the entity Id of a boolean flag, generate:
-- Id : Boolean := False;
procedure Expand_Attributes_In_Consequence
(Decls : List_Id;
Evals : in out Node_Id;
Flag : Entity_Id;
Conseq : Node_Id);
-- Perform specialized expansion of all attribute 'Old references found
-- in consequence Conseq such that at runtime only prefixes coming from
-- the selected consequence are evaluated. Similarly expand attribute
-- 'Result references by replacing them with identifier _result which
-- resolves to the sole formal parameter of procedure _Postconditions.
-- Any temporaries generated in the process are added to declarations
-- Decls. Evals is a complex if statement tasked with the evaluation of
-- all prefixes coming from a single selected consequence. Flag is the
-- corresponding case guard flag. Conseq is the consequence expression.
function Increment (Id : Entity_Id) return Node_Id;
-- Given the entity Id of a numerical variable, generate:
-- Id := Id + 1;
function Set (Id : Entity_Id) return Node_Id;
-- Given the entity Id of a boolean variable, generate:
-- Id := True;
----------------------
-- Case_Guard_Error --
----------------------
procedure Case_Guard_Error
(Decls : List_Id;
Flag : Entity_Id;
Error_Loc : Source_Ptr;
Msg : in out Entity_Id)
is
New_Line : constant Character := Character'Val (10);
New_Msg : constant Entity_Id := Make_Temporary (Loc, 'S');
begin
Start_String;
Store_String_Char (New_Line);
Store_String_Chars (" case guard at ");
Store_String_Chars (Build_Location_String (Error_Loc));
Store_String_Chars (" evaluates to True");
-- Generate:
-- New_Msg : constant String :=
-- (if Flag then
-- Msg & "case guard at Error_Loc evaluates to True"
-- else Msg);
Append_To (Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => New_Msg,
Constant_Present => True,
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
Expression =>
Make_If_Expression (Loc,
Expressions => New_List (
New_Occurrence_Of (Flag, Loc),
Make_Op_Concat (Loc,
Left_Opnd => New_Occurrence_Of (Msg, Loc),
Right_Opnd => Make_String_Literal (Loc, End_String)),
New_Occurrence_Of (Msg, Loc)))));
Msg := New_Msg;
end Case_Guard_Error;
-----------------------
-- Consequence_Error --
-----------------------
procedure Consequence_Error
(Checks : in out Node_Id;
Flag : Entity_Id;
Conseq : Node_Id)
is
Cond : Node_Id;
Error : Node_Id;
begin
-- Generate:
-- Flag and then not Conseq
Cond :=
Make_And_Then (Loc,
Left_Opnd => New_Occurrence_Of (Flag, Loc),
Right_Opnd =>
Make_Op_Not (Loc,
Right_Opnd => Relocate_Node (Conseq)));
-- Generate:
-- raise Assertion_Error
-- with "failed contract case at Sloc (Conseq)";
Start_String;
Store_String_Chars ("failed contract case at ");
Store_String_Chars (Build_Location_String (Sloc (Conseq)));
Error :=
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Raise_Assert_Failure), Loc),
Parameter_Associations => New_List (
Make_String_Literal (Loc, End_String)));
if No (Checks) then
Checks :=
Make_Implicit_If_Statement (CCs,
Condition => Cond,
Then_Statements => New_List (Error));
else
if No (Elsif_Parts (Checks)) then
Set_Elsif_Parts (Checks, New_List);
end if;
Append_To (Elsif_Parts (Checks),
Make_Elsif_Part (Loc,
Condition => Cond,
Then_Statements => New_List (Error)));
end if;
end Consequence_Error;
--------------------
-- Declaration_Of --
--------------------
function Declaration_Of (Id : Entity_Id) return Node_Id is
begin
return
Make_Object_Declaration (Loc,
Defining_Identifier => Id,
Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc),
Expression => New_Occurrence_Of (Standard_False, Loc));
end Declaration_Of;
--------------------------------------
-- Expand_Attributes_In_Consequence --
--------------------------------------
procedure Expand_Attributes_In_Consequence
(Decls : List_Id;
Evals : in out Node_Id;
Flag : Entity_Id;
Conseq : Node_Id)
is
Eval_Stmts : List_Id := No_List;
-- The evaluation sequence expressed as assignment statements of all
-- prefixes of attribute 'Old found in the current consequence.
function Expand_Attributes (N : Node_Id) return Traverse_Result;
-- Determine whether an arbitrary node denotes attribute 'Old or
-- 'Result and if it does, perform all expansion-related actions.
-----------------------
-- Expand_Attributes --
-----------------------
function Expand_Attributes (N : Node_Id) return Traverse_Result is
Decl : Node_Id;
Pref : Node_Id;
Temp : Entity_Id;
begin
-- Attribute 'Old
if Nkind (N) = N_Attribute_Reference
and then Attribute_Name (N) = Name_Old
then
Pref := Prefix (N);
Temp := Make_Temporary (Loc, 'T', Pref);
Set_Etype (Temp, Etype (Pref));
-- Generate a temporary to capture the value of the prefix:
-- Temp : <Pref type>;
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Object_Definition =>
New_Occurrence_Of (Etype (Pref), Loc));
-- Place that temporary at the beginning of declarations, to
-- prevent anomalies in the GNATprove flow-analysis pass in
-- the precondition procedure that follows.
Prepend_To (Decls, Decl);
-- If the type is unconstrained, the prefix provides its
-- value and constraint, so add it to declaration.
if not Is_Constrained (Etype (Pref))
and then Is_Entity_Name (Pref)
then
Set_Expression (Decl, Pref);
Analyze (Decl);
-- Otherwise add an assignment statement to temporary using
-- prefix as RHS.
else
Analyze (Decl);
if No (Eval_Stmts) then
Eval_Stmts := New_List;
end if;
Append_To (Eval_Stmts,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Temp, Loc),
Expression => Pref));
end if;
-- Ensure that the prefix is valid
if Validity_Checks_On and then Validity_Check_Operands then
Ensure_Valid (Pref);
end if;
-- Replace the original attribute 'Old by a reference to the
-- generated temporary.
Rewrite (N, New_Occurrence_Of (Temp, Loc));
-- Attribute 'Result
elsif Is_Attribute_Result (N) then
Rewrite (N, Make_Identifier (Loc, Name_uResult));
end if;
return OK;
end Expand_Attributes;
procedure Expand_Attributes_In is
new Traverse_Proc (Expand_Attributes);
-- Start of processing for Expand_Attributes_In_Consequence
begin
-- Inspect the consequence and expand any attribute 'Old and 'Result
-- references found within.
Expand_Attributes_In (Conseq);
-- The consequence does not contain any attribute 'Old references
if No (Eval_Stmts) then
return;
end if;
-- Augment the machinery to trigger the evaluation of all prefixes
-- found in the step above. If Eval is empty, then this is the first
-- consequence to yield expansion of 'Old. Generate:
-- if Flag then
-- <evaluation statements>
-- end if;
if No (Evals) then
Evals :=
Make_Implicit_If_Statement (CCs,
Condition => New_Occurrence_Of (Flag, Loc),
Then_Statements => Eval_Stmts);
-- Otherwise generate:
-- elsif Flag then
-- <evaluation statements>
-- end if;
else
if No (Elsif_Parts (Evals)) then
Set_Elsif_Parts (Evals, New_List);
end if;
Append_To (Elsif_Parts (Evals),
Make_Elsif_Part (Loc,
Condition => New_Occurrence_Of (Flag, Loc),
Then_Statements => Eval_Stmts));
end if;
end Expand_Attributes_In_Consequence;
---------------
-- Increment --
---------------
function Increment (Id : Entity_Id) return Node_Id is
begin
return
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Id, Loc),
Expression =>
Make_Op_Add (Loc,
Left_Opnd => New_Occurrence_Of (Id, Loc),
Right_Opnd => Make_Integer_Literal (Loc, 1)));
end Increment;
---------
-- Set --
---------
function Set (Id : Entity_Id) return Node_Id is
begin
return
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Id, Loc),
Expression => New_Occurrence_Of (Standard_True, Loc));
end Set;
-- Local variables
Aggr : constant Node_Id :=
Expression (First (Pragma_Argument_Associations (CCs)));
Case_Guard : Node_Id;
CG_Checks : Node_Id;
CG_Stmts : List_Id;
Conseq : Node_Id;
Conseq_Checks : Node_Id := Empty;
Count : Entity_Id;
Count_Decl : Node_Id;
Error_Decls : List_Id;
Flag : Entity_Id;
Flag_Decl : Node_Id;
If_Stmt : Node_Id;
Msg_Str : Entity_Id;
Multiple_PCs : Boolean;
Old_Evals : Node_Id := Empty;
Others_Decl : Node_Id;
Others_Flag : Entity_Id := Empty;
Post_Case : Node_Id;
-- Start of processing for Expand_Pragma_Contract_Cases
begin
-- Do nothing if pragma is not enabled. If pragma is disabled, it has
-- already been rewritten as a Null statement.
if Is_Ignored (CCs) then
return;
-- Guard against malformed contract cases
elsif Nkind (Aggr) /= N_Aggregate then
return;
end if;
-- The expansion of contract cases is quite distributed as it produces
-- various statements to evaluate the case guards and consequences. To
-- preserve the original context, set the Is_Assertion_Expr flag. This
-- aids the Ghost legality checks when verifying the placement of a
-- reference to a Ghost entity.
In_Assertion_Expr := In_Assertion_Expr + 1;
Multiple_PCs := List_Length (Component_Associations (Aggr)) > 1;
-- Create the counter which tracks the number of case guards that
-- evaluate to True.
-- Count : Natural := 0;
Count := Make_Temporary (Loc, 'C');
Count_Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Count,
Object_Definition => New_Occurrence_Of (Standard_Natural, Loc),
Expression => Make_Integer_Literal (Loc, 0));
Prepend_To (Decls, Count_Decl);
Analyze (Count_Decl);
-- Create the base error message for multiple overlapping case guards
-- Msg_Str : constant String :=
-- "contract cases overlap for subprogram Subp_Id";
if Multiple_PCs then
Msg_Str := Make_Temporary (Loc, 'S');
Start_String;
Store_String_Chars ("contract cases overlap for subprogram ");
Store_String_Chars (Get_Name_String (Chars (Subp_Id)));
Error_Decls := New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => Msg_Str,
Constant_Present => True,
Object_Definition => New_Occurrence_Of (Standard_String, Loc),
Expression => Make_String_Literal (Loc, End_String)));
end if;
-- Process individual post cases
Post_Case := First (Component_Associations (Aggr));
while Present (Post_Case) loop
Case_Guard := First (Choices (Post_Case));
Conseq := Expression (Post_Case);
-- The "others" choice requires special processing
if Nkind (Case_Guard) = N_Others_Choice then
Others_Flag := Make_Temporary (Loc, 'F');
Others_Decl := Declaration_Of (Others_Flag);
Prepend_To (Decls, Others_Decl);
Analyze (Others_Decl);
-- Check possible overlap between a case guard and "others"
if Multiple_PCs and Exception_Extra_Info then
Case_Guard_Error
(Decls => Error_Decls,
Flag => Others_Flag,
Error_Loc => Sloc (Case_Guard),
Msg => Msg_Str);
end if;
-- Inspect the consequence and perform special expansion of any
-- attribute 'Old and 'Result references found within.
Expand_Attributes_In_Consequence
(Decls => Decls,
Evals => Old_Evals,
Flag => Others_Flag,
Conseq => Conseq);
-- Check the corresponding consequence of "others"
Consequence_Error
(Checks => Conseq_Checks,
Flag => Others_Flag,
Conseq => Conseq);
-- Regular post case
else
-- Create the flag which tracks the state of its associated case
-- guard.
Flag := Make_Temporary (Loc, 'F');
Flag_Decl := Declaration_Of (Flag);
Prepend_To (Decls, Flag_Decl);
Analyze (Flag_Decl);
-- The flag is set when the case guard is evaluated to True
-- if Case_Guard then
-- Flag := True;
-- Count := Count + 1;
-- end if;
If_Stmt :=
Make_Implicit_If_Statement (CCs,
Condition => Relocate_Node (Case_Guard),
Then_Statements => New_List (
Set (Flag),
Increment (Count)));
Append_To (Decls, If_Stmt);
Analyze (If_Stmt);
-- Check whether this case guard overlaps with another one
if Multiple_PCs and Exception_Extra_Info then
Case_Guard_Error
(Decls => Error_Decls,
Flag => Flag,
Error_Loc => Sloc (Case_Guard),
Msg => Msg_Str);
end if;
-- Inspect the consequence and perform special expansion of any
-- attribute 'Old and 'Result references found within.
Expand_Attributes_In_Consequence
(Decls => Decls,
Evals => Old_Evals,
Flag => Flag,
Conseq => Conseq);
-- The corresponding consequence of the case guard which evaluated
-- to True must hold on exit from the subprogram.
Consequence_Error
(Checks => Conseq_Checks,
Flag => Flag,
Conseq => Conseq);
end if;
Next (Post_Case);
end loop;
-- Raise Assertion_Error when none of the case guards evaluate to True.
-- The only exception is when we have "others", in which case there is
-- no error because "others" acts as a default True.
-- Generate:
-- Flag := True;
if Present (Others_Flag) then
CG_Stmts := New_List (Set (Others_Flag));
-- Generate:
-- raise Assertion_Error with "xxx contract cases incomplete";
else
Start_String;
Store_String_Chars (Build_Location_String (Loc));
Store_String_Chars (" contract cases incomplete");
CG_Stmts := New_List (
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Raise_Assert_Failure), Loc),
Parameter_Associations => New_List (
Make_String_Literal (Loc, End_String))));
end if;
CG_Checks :=
Make_Implicit_If_Statement (CCs,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd => New_Occurrence_Of (Count, Loc),
Right_Opnd => Make_Integer_Literal (Loc, 0)),
Then_Statements => CG_Stmts);
-- Detect a possible failure due to several case guards evaluating to
-- True.
-- Generate:
-- elsif Count > 0 then
-- declare
-- <Error_Decls>
-- begin
-- raise Assertion_Error with <Msg_Str>;
-- end if;
if Multiple_PCs then
Set_Elsif_Parts (CG_Checks, New_List (
Make_Elsif_Part (Loc,
Condition =>
Make_Op_Gt (Loc,
Left_Opnd => New_Occurrence_Of (Count, Loc),
Right_Opnd => Make_Integer_Literal (Loc, 1)),
Then_Statements => New_List (
Make_Block_Statement (Loc,
Declarations => Error_Decls,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of
(RTE (RE_Raise_Assert_Failure), Loc),
Parameter_Associations => New_List (
New_Occurrence_Of (Msg_Str, Loc))))))))));
end if;
Append_To (Decls, CG_Checks);
Analyze (CG_Checks);
-- Once all case guards are evaluated and checked, evaluate any prefixes
-- of attribute 'Old founds in the selected consequence.
if Present (Old_Evals) then
Append_To (Decls, Old_Evals);
Analyze (Old_Evals);
end if;
-- Raise Assertion_Error when the corresponding consequence of a case
-- guard that evaluated to True fails.
if No (Stmts) then
Stmts := New_List;
end if;
Append_To (Stmts, Conseq_Checks);
In_Assertion_Expr := In_Assertion_Expr - 1;
end Expand_Pragma_Contract_Cases;
---------------------------------------
-- Expand_Pragma_Import_Or_Interface --
---------------------------------------
procedure Expand_Pragma_Import_Or_Interface (N : Node_Id) is
Def_Id : Entity_Id;
begin
-- In Relaxed_RM_Semantics, support old Ada 83 style:
-- pragma Import (Entity, "external name");
if Relaxed_RM_Semantics
and then List_Length (Pragma_Argument_Associations (N)) = 2
and then Pragma_Name (N) = Name_Import
and then Nkind (Arg2 (N)) = N_String_Literal
then
Def_Id := Entity (Arg1 (N));
else
Def_Id := Entity (Arg2 (N));
end if;
-- Variable case (we have to undo any initialization already done)
if Ekind (Def_Id) = E_Variable then
Undo_Initialization (Def_Id, N);
-- Case of exception with convention C++
elsif Ekind (Def_Id) = E_Exception
and then Convention (Def_Id) = Convention_CPP
then
-- Import a C++ convention
declare
Loc : constant Source_Ptr := Sloc (N);
Rtti_Name : constant Node_Id := Arg3 (N);
Dum : constant Entity_Id := Make_Temporary (Loc, 'D');
Exdata : List_Id;
Lang_Char : Node_Id;
Foreign_Data : Node_Id;
begin
Exdata := Component_Associations (Expression (Parent (Def_Id)));
Lang_Char := Next (First (Exdata));
-- Change the one-character language designator to 'C'
Rewrite (Expression (Lang_Char),
Make_Character_Literal (Loc,
Chars => Name_uC,
Char_Literal_Value => UI_From_Int (Character'Pos ('C'))));
Analyze (Expression (Lang_Char));
-- Change the value of Foreign_Data
Foreign_Data := Next (Next (Next (Next (Lang_Char))));
Insert_Actions (Def_Id, New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => Dum,
Object_Definition =>
New_Occurrence_Of (Standard_Character, Loc)),
Make_Pragma (Loc,
Chars => Name_Import,
Pragma_Argument_Associations => New_List (
Make_Pragma_Argument_Association (Loc,
Expression => Make_Identifier (Loc, Name_Ada)),
Make_Pragma_Argument_Association (Loc,
Expression => Make_Identifier (Loc, Chars (Dum))),
Make_Pragma_Argument_Association (Loc,
Chars => Name_External_Name,
Expression => Relocate_Node (Rtti_Name))))));
Rewrite (Expression (Foreign_Data),
Unchecked_Convert_To (Standard_A_Char,
Make_Attribute_Reference (Loc,
Prefix => Make_Identifier (Loc, Chars (Dum)),
Attribute_Name => Name_Address)));
Analyze (Expression (Foreign_Data));
end;
-- No special expansion required for any other case
else
null;
end if;
end Expand_Pragma_Import_Or_Interface;
-------------------------------------
-- Expand_Pragma_Initial_Condition --
-------------------------------------
procedure Expand_Pragma_Initial_Condition (Spec_Or_Body : Node_Id) is
Loc : constant Source_Ptr := Sloc (Spec_Or_Body);
Check : Node_Id;
Expr : Node_Id;
Init_Cond : Node_Id;
List : List_Id;
Pack_Id : Entity_Id;
begin
if Nkind (Spec_Or_Body) = N_Package_Body then
Pack_Id := Corresponding_Spec (Spec_Or_Body);
if Present (Handled_Statement_Sequence (Spec_Or_Body)) then
List := Statements (Handled_Statement_Sequence (Spec_Or_Body));
-- The package body lacks statements, create an empty list
else
List := New_List;
Set_Handled_Statement_Sequence (Spec_Or_Body,
Make_Handled_Sequence_Of_Statements (Loc, Statements => List));
end if;
elsif Nkind (Spec_Or_Body) = N_Package_Declaration then
Pack_Id := Defining_Entity (Spec_Or_Body);
if Present (Visible_Declarations (Specification (Spec_Or_Body))) then
List := Visible_Declarations (Specification (Spec_Or_Body));
-- The package lacks visible declarations, create an empty list
else
List := New_List;
Set_Visible_Declarations (Specification (Spec_Or_Body), List);
end if;
-- This routine should not be used on anything other than packages
else
raise Program_Error;
end if;
Init_Cond := Get_Pragma (Pack_Id, Pragma_Initial_Condition);
-- The caller should check whether the package is subject to pragma
-- Initial_Condition.
pragma Assert (Present (Init_Cond));
Expr :=
Get_Pragma_Arg (First (Pragma_Argument_Associations (Init_Cond)));
-- The assertion expression was found to be illegal, do not generate the
-- runtime check as it will repeat the illegality.
if Error_Posted (Init_Cond) or else Error_Posted (Expr) then
return;
end if;
-- Generate:
-- pragma Check (Initial_Condition, <Expr>);
Check :=
Make_Pragma (Loc,
Chars => Name_Check,
Pragma_Argument_Associations => New_List (
Make_Pragma_Argument_Association (Loc,
Expression => Make_Identifier (Loc, Name_Initial_Condition)),
Make_Pragma_Argument_Association (Loc,
Expression => New_Copy_Tree (Expr))));
Append_To (List, Check);
Analyze (Check);
end Expand_Pragma_Initial_Condition;
------------------------------------
-- Expand_Pragma_Inspection_Point --
------------------------------------
-- If no argument is given, then we supply a default argument list that
-- includes all objects declared at the source level in all subprograms
-- that enclose the inspection point pragma.
procedure Expand_Pragma_Inspection_Point (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
A : List_Id;
Assoc : Node_Id;
S : Entity_Id;
E : Entity_Id;
begin
if No (Pragma_Argument_Associations (N)) then
A := New_List;
S := Current_Scope;
while S /= Standard_Standard loop
E := First_Entity (S);
while Present (E) loop
if Comes_From_Source (E)
and then Is_Object (E)
and then not Is_Entry_Formal (E)
and then Ekind (E) /= E_Component
and then Ekind (E) /= E_Discriminant
and then Ekind (E) /= E_Generic_In_Parameter
and then Ekind (E) /= E_Generic_In_Out_Parameter
then
Append_To (A,
Make_Pragma_Argument_Association (Loc,
Expression => New_Occurrence_Of (E, Loc)));
end if;
Next_Entity (E);
end loop;
S := Scope (S);
end loop;
Set_Pragma_Argument_Associations (N, A);
end if;
-- Expand the arguments of the pragma. Expanding an entity reference
-- is a noop, except in a protected operation, where a reference may
-- have to be transformed into a reference to the corresponding prival.
-- Are there other pragmas that may require this ???
Assoc := First (Pragma_Argument_Associations (N));
while Present (Assoc) loop
Expand (Expression (Assoc));
Next (Assoc);
end loop;
end Expand_Pragma_Inspection_Point;
--------------------------------------
-- Expand_Pragma_Interrupt_Priority --
--------------------------------------
-- Supply default argument if none exists (System.Interrupt_Priority'Last)
procedure Expand_Pragma_Interrupt_Priority (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
begin
if No (Pragma_Argument_Associations (N)) then
Set_Pragma_Argument_Associations (N, New_List (
Make_Pragma_Argument_Association (Loc,
Expression =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (RTE (RE_Interrupt_Priority), Loc),
Attribute_Name => Name_Last))));
end if;
end Expand_Pragma_Interrupt_Priority;
--------------------------------
-- Expand_Pragma_Loop_Variant --
--------------------------------
-- Pragma Loop_Variant is expanded in the following manner:
-- Original code
-- for | while ... loop
-- <preceding source statements>
-- pragma Loop_Variant
-- (Increases => Incr_Expr,
-- Decreases => Decr_Expr);
-- <succeeding source statements>
-- end loop;
-- Expanded code
-- Curr_1 : <type of Incr_Expr>;
-- Curr_2 : <type of Decr_Expr>;
-- Old_1 : <type of Incr_Expr>;
-- Old_2 : <type of Decr_Expr>;
-- Flag : Boolean := False;
-- for | while ... loop
-- <preceding source statements>
-- if Flag then
-- Old_1 := Curr_1;
-- Old_2 := Curr_2;
-- end if;
-- Curr_1 := <Incr_Expr>;
-- Curr_2 := <Decr_Expr>;
-- if Flag then
-- if Curr_1 /= Old_1 then
-- pragma Check (Loop_Variant, Curr_1 > Old_1);
-- else
-- pragma Check (Loop_Variant, Curr_2 < Old_2);
-- end if;
-- else
-- Flag := True;
-- end if;
-- <succeeding source statements>
-- end loop;
procedure Expand_Pragma_Loop_Variant (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Last_Var : constant Node_Id :=
Last (Pragma_Argument_Associations (N));
Curr_Assign : List_Id := No_List;
Flag_Id : Entity_Id := Empty;
If_Stmt : Node_Id := Empty;
Old_Assign : List_Id := No_List;
Loop_Scop : Entity_Id;
Loop_Stmt : Node_Id;
Variant : Node_Id;
procedure Process_Variant (Variant : Node_Id; Is_Last : Boolean);
-- Process a single increasing / decreasing termination variant. Flag
-- Is_Last should be set when processing the last variant.
---------------------
-- Process_Variant --
---------------------
procedure Process_Variant (Variant : Node_Id; Is_Last : Boolean) is
function Make_Op
(Loc : Source_Ptr;
Curr_Val : Node_Id;
Old_Val : Node_Id) return Node_Id;
-- Generate a comparison between Curr_Val and Old_Val depending on
-- the change mode (Increases / Decreases) of the variant.
-------------
-- Make_Op --
-------------
function Make_Op
(Loc : Source_Ptr;
Curr_Val : Node_Id;
Old_Val : Node_Id) return Node_Id
is
begin
if Chars (Variant) = Name_Increases then
return Make_Op_Gt (Loc, Curr_Val, Old_Val);
else pragma Assert (Chars (Variant) = Name_Decreases);
return Make_Op_Lt (Loc, Curr_Val, Old_Val);
end if;
end Make_Op;
-- Local variables
Expr : constant Node_Id := Expression (Variant);
Expr_Typ : constant Entity_Id := Etype (Expr);
Loc : constant Source_Ptr := Sloc (Expr);
Loop_Loc : constant Source_Ptr := Sloc (Loop_Stmt);
Curr_Id : Entity_Id;
Old_Id : Entity_Id;
Prag : Node_Id;
-- Start of processing for Process_Variant
begin
-- All temporaries generated in this routine must be inserted before
-- the related loop statement. Ensure that the proper scope is on the
-- stack when analyzing the temporaries. Note that we also use the
-- Sloc of the related loop.
Push_Scope (Scope (Loop_Scop));
-- Step 1: Create the declaration of the flag which controls the
-- behavior of the assertion on the first iteration of the loop.
if No (Flag_Id) then
-- Generate:
-- Flag : Boolean := False;
Flag_Id := Make_Temporary (Loop_Loc, 'F');
Insert_Action (Loop_Stmt,
Make_Object_Declaration (Loop_Loc,
Defining_Identifier => Flag_Id,
Object_Definition =>
New_Occurrence_Of (Standard_Boolean, Loop_Loc),
Expression =>
New_Occurrence_Of (Standard_False, Loop_Loc)));
-- Prevent an unwanted optimization where the Current_Value of
-- the flag eliminates the if statement which stores the variant
-- values coming from the previous iteration.
-- Flag : Boolean := False;
-- loop
-- if Flag then -- condition rewritten to False
-- Old_N := Curr_N; -- and if statement eliminated
-- end if;
-- . . .
-- Flag := True;
-- end loop;
Set_Current_Value (Flag_Id, Empty);
end if;
-- Step 2: Create the temporaries which store the old and current
-- values of the associated expression.
-- Generate:
-- Curr : <type of Expr>;
Curr_Id := Make_Temporary (Loc, 'C');
Insert_Action (Loop_Stmt,
Make_Object_Declaration (Loop_Loc,
Defining_Identifier => Curr_Id,
Object_Definition => New_Occurrence_Of (Expr_Typ, Loop_Loc)));
-- Generate:
-- Old : <type of Expr>;
Old_Id := Make_Temporary (Loc, 'P');
Insert_Action (Loop_Stmt,
Make_Object_Declaration (Loop_Loc,
Defining_Identifier => Old_Id,
Object_Definition => New_Occurrence_Of (Expr_Typ, Loop_Loc)));
-- Restore original scope after all temporaries have been analyzed
Pop_Scope;
-- Step 3: Store value of the expression from the previous iteration
if No (Old_Assign) then
Old_Assign := New_List;
end if;
-- Generate:
-- Old := Curr;
Append_To (Old_Assign,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Old_Id, Loc),
Expression => New_Occurrence_Of (Curr_Id, Loc)));
-- Step 4: Store the current value of the expression
if No (Curr_Assign) then
Curr_Assign := New_List;
end if;
-- Generate:
-- Curr := <Expr>;
Append_To (Curr_Assign,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Curr_Id, Loc),
Expression => Relocate_Node (Expr)));
-- Step 5: Create corresponding assertion to verify change of value
-- Generate:
-- pragma Check (Loop_Variant, Curr <|> Old);
Prag :=
Make_Pragma (Loc,
Chars => Name_Check,
Pragma_Argument_Associations => New_List (
Make_Pragma_Argument_Association (Loc,
Expression => Make_Identifier (Loc, Name_Loop_Variant)),
Make_Pragma_Argument_Association (Loc,
Expression =>
Make_Op (Loc,
Curr_Val => New_Occurrence_Of (Curr_Id, Loc),
Old_Val => New_Occurrence_Of (Old_Id, Loc)))));
-- Generate:
-- if Curr /= Old then
-- <Prag>;
if No (If_Stmt) then
-- When there is just one termination variant, do not compare the
-- old and current value for equality, just check the pragma.
if Is_Last then
If_Stmt := Prag;
else
If_Stmt :=
Make_If_Statement (Loc,
Condition =>
Make_Op_Ne (Loc,
Left_Opnd => New_Occurrence_Of (Curr_Id, Loc),
Right_Opnd => New_Occurrence_Of (Old_Id, Loc)),
Then_Statements => New_List (Prag));
end if;
-- Generate:
-- else
-- <Prag>;
-- end if;
elsif Is_Last then
Set_Else_Statements (If_Stmt, New_List (Prag));
-- Generate:
-- elsif Curr /= Old then
-- <Prag>;
else
if Elsif_Parts (If_Stmt) = No_List then
Set_Elsif_Parts (If_Stmt, New_List);
end if;
Append_To (Elsif_Parts (If_Stmt),
Make_Elsif_Part (Loc,
Condition =>
Make_Op_Ne (Loc,
Left_Opnd => New_Occurrence_Of (Curr_Id, Loc),
Right_Opnd => New_Occurrence_Of (Old_Id, Loc)),
Then_Statements => New_List (Prag)));
end if;
end Process_Variant;
-- Start of processing for Expand_Pragma_Loop_Variant
begin
-- If pragma is not enabled, rewrite as Null statement. If pragma is
-- disabled, it has already been rewritten as a Null statement.
if Is_Ignored (N) then
Rewrite (N, Make_Null_Statement (Loc));
Analyze (N);
return;
end if;
-- The expansion of Loop_Variant is quite distributed as it produces
-- various statements to capture and compare the arguments. To preserve
-- the original context, set the Is_Assertion_Expr flag. This aids the
-- Ghost legality checks when verifying the placement of a reference to
-- a Ghost entity.
In_Assertion_Expr := In_Assertion_Expr + 1;
-- Locate the enclosing loop for which this assertion applies. In the
-- case of Ada 2012 array iteration, we might be dealing with nested
-- loops. Only the outermost loop has an identifier.
Loop_Stmt := N;
while Present (Loop_Stmt) loop
if Nkind (Loop_Stmt) = N_Loop_Statement
and then Present (Identifier (Loop_Stmt))
then
exit;
end if;
Loop_Stmt := Parent (Loop_Stmt);
end loop;
Loop_Scop := Entity (Identifier (Loop_Stmt));
-- Create the circuitry which verifies individual variants
Variant := First (Pragma_Argument_Associations (N));
while Present (Variant) loop
Process_Variant (Variant, Is_Last => Variant = Last_Var);
Next (Variant);
end loop;
-- Construct the segment which stores the old values of all expressions.
-- Generate:
-- if Flag then
-- <Old_Assign>
-- end if;
Insert_Action (N,
Make_If_Statement (Loc,
Condition => New_Occurrence_Of (Flag_Id, Loc),
Then_Statements => Old_Assign));
-- Update the values of all expressions
Insert_Actions (N, Curr_Assign);
-- Add the assertion circuitry to test all changes in expressions.
-- Generate:
-- if Flag then
-- <If_Stmt>
-- else
-- Flag := True;
-- end if;
Insert_Action (N,
Make_If_Statement (Loc,
Condition => New_Occurrence_Of (Flag_Id, Loc),
Then_Statements => New_List (If_Stmt),
Else_Statements => New_List (
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Flag_Id, Loc),
Expression => New_Occurrence_Of (Standard_True, Loc)))));
-- Note: the pragma has been completely transformed into a sequence of
-- corresponding declarations and statements. We leave it in the tree
-- for documentation purposes. It will be ignored by the backend.
In_Assertion_Expr := In_Assertion_Expr - 1;
end Expand_Pragma_Loop_Variant;
--------------------------------
-- Expand_Pragma_Psect_Object --
--------------------------------
-- Convert to Common_Object, and expand the resulting pragma
procedure Expand_Pragma_Psect_Object (N : Node_Id)
renames Expand_Pragma_Common_Object;
-------------------------------------
-- Expand_Pragma_Relative_Deadline --
-------------------------------------
procedure Expand_Pragma_Relative_Deadline (N : Node_Id) is
P : constant Node_Id := Parent (N);
Loc : constant Source_Ptr := Sloc (N);
begin
-- Expand the pragma only in the case of the main subprogram. For tasks
-- the expansion is done in exp_ch9. Generate a call to Set_Deadline
-- at Clock plus the relative deadline specified in the pragma. Time
-- values are translated into Duration to allow for non-private
-- addition operation.
if Nkind (P) = N_Subprogram_Body then
Rewrite
(N,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (RTE (RE_Set_Deadline), Loc),
Parameter_Associations => New_List (
Unchecked_Convert_To (RTE (RO_RT_Time),
Make_Op_Add (Loc,
Left_Opnd =>
Make_Function_Call (Loc,
New_Occurrence_Of (RTE (RO_RT_To_Duration), Loc),
New_List
(Make_Function_Call
(Loc, New_Occurrence_Of (RTE (RE_Clock), Loc)))),
Right_Opnd =>
Unchecked_Convert_To (Standard_Duration, Arg1 (N)))))));
Analyze (N);
end if;
end Expand_Pragma_Relative_Deadline;
-------------------------------------------
-- Expand_Pragma_Suppress_Initialization --
-------------------------------------------
procedure Expand_Pragma_Suppress_Initialization (N : Node_Id) is
Def_Id : constant Entity_Id := Entity (Arg1 (N));
begin
-- Variable case (we have to undo any initialization already done)
if Ekind (Def_Id) = E_Variable then
Undo_Initialization (Def_Id, N);
end if;
end Expand_Pragma_Suppress_Initialization;
-------------------------
-- Undo_Initialization --
-------------------------
procedure Undo_Initialization (Def_Id : Entity_Id; N : Node_Id) is
Init_Call : Node_Id;
begin
-- When applied to a variable, the default initialization must not be
-- done. As it is already done when the pragma is found, we just get rid
-- of the call the initialization procedure which followed the object
-- declaration. The call is inserted after the declaration, but validity
-- checks may also have been inserted and thus the initialization call
-- does not necessarily appear immediately after the object declaration.
-- We can't use the freezing mechanism for this purpose, since we have
-- to elaborate the initialization expression when it is first seen (so
-- this elaboration cannot be deferred to the freeze point).
-- Find and remove generated initialization call for object, if any
Init_Call := Remove_Init_Call (Def_Id, Rep_Clause => N);
-- Any default initialization expression should be removed (e.g.
-- null defaults for access objects, zero initialization of packed
-- bit arrays). Imported objects aren't allowed to have explicit
-- initialization, so the expression must have been generated by
-- the compiler.
if No (Init_Call) and then Present (Expression (Parent (Def_Id))) then
Set_Expression (Parent (Def_Id), Empty);
end if;
-- The object may not have any initialization, but in the presence of
-- Initialize_Scalars code is inserted after then declaration, which
-- must now be removed as well. The code carries the same source
-- location as the declaration itself.
if Initialize_Scalars and then Is_Array_Type (Etype (Def_Id)) then
declare
Init : Node_Id;
Nxt : Node_Id;
begin
Init := Next (Parent (Def_Id));
while not Comes_From_Source (Init)
and then Sloc (Init) = Sloc (Def_Id)
loop
Nxt := Next (Init);
Remove (Init);
Init := Nxt;
end loop;
end;
end if;
end Undo_Initialization;
end Exp_Prag;
|
with Courbes.Visiteurs; use Courbes.Visiteurs;
package body Courbes.Singletons is
function Ctor_Singleton (P : Point2D) return Singleton is
begin
return (Debut => P, Fin => P);
end;
-- X pas utilisé
overriding function Obtenir_Point(Self : Singleton; X : Coordonnee_Normalisee) return Point2D is
begin
return Self.Debut;
end;
overriding procedure Accepter (Self : Singleton; Visiteur : Visiteur_Courbe'Class) is
begin
Visiteur.Visiter (Self);
end;
end Courbes.Singletons;
|
-- C43107A.ADA
-- Grant of Unlimited Rights
--
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
-- unlimited rights in the software and documentation contained herein.
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
-- this public release, the Government intends to confer upon all
-- recipients unlimited rights equal to those held by the Government.
-- These rights include rights to use, duplicate, release or disclose the
-- released technical data and computer software in whole or in part, in
-- any manner and for any purpose whatsoever, and to have or permit others
-- to do so.
--
-- DISCLAIMER
--
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
-- PARTICULAR PURPOSE OF SAID MATERIAL.
--*
-- CHECK THAT AN EXPRESSION ASSOCIATED WITH MORE THAN ONE RECORD
-- COMPONENT IS EVALUATED ONCE FOR EACH ASSOCIATED COMPONENT.
-- EG 02/14/84
WITH REPORT;
PROCEDURE C43107A IS
USE REPORT;
BEGIN
TEST("C43107A","CHECK THAT AN EXPRESSION WITH MORE THAN ONE " &
"RECORD COMPONENT IS EVALUATED ONCE FOR EACH " &
"ASSOCIATED COMPONENT");
BEGIN
CASE_A : DECLARE
TYPE T1 IS ARRAY(1 .. 2) OF INTEGER;
TYPE R1 IS
RECORD
A : T1;
B : INTEGER;
C : T1;
D : INTEGER;
E : INTEGER;
END RECORD;
A1 : R1;
CNTR : INTEGER := 0;
FUNCTION FUN1 (A : T1) RETURN T1 IS
BEGIN
CNTR := IDENT_INT(CNTR+1);
RETURN A;
END FUN1;
FUNCTION FUN2 (A : INTEGER) RETURN INTEGER IS
BEGIN
CNTR := CNTR+1;
RETURN IDENT_INT(A);
END FUN2;
BEGIN
A1 := (A | C => FUN1((-1, -2)), OTHERS => FUN2(-3)+1);
IF CNTR /= 5 THEN
FAILED ("CASE A : INCORRECT NUMBER OF EVALUATIONS" &
" OF RECORD ASSOCIATED COMPONENTS");
END IF;
IF A1.A /= (-1, -2) OR A1.C /= (-1, -2) OR
A1.B /= -2 OR A1.D /= -2 OR A1.E /= -2 THEN
FAILED ("CASE A : INCORRECT VALUES IN RECORD");
END IF;
END CASE_A;
CASE_B : DECLARE
TYPE T2 IS ACCESS INTEGER;
TYPE R2 IS
RECORD
A : T2;
B : INTEGER;
C : T2;
D : INTEGER;
E : INTEGER;
END RECORD;
B1 : R2;
CNTR : INTEGER := 0;
FUNCTION FUN3 RETURN INTEGER IS
BEGIN
CNTR := CNTR+1;
RETURN IDENT_INT(2);
END FUN3;
BEGIN
B1 := (A | C => NEW INTEGER'(-1),
B | D | E => FUN3);
IF B1.A = B1.C OR CNTR /= 3 THEN
FAILED ("CASE B : INCORRECT NUMBER OF EVALUATION" &
" OF RECORD ASSOCIATED COMPONENTS");
END IF;
IF B1.B /= 2 OR B1.D /= 2 OR B1.E /= 2 OR
B1.A = NULL OR B1.C = NULL OR B1.A = B1.C THEN
FAILED ("CASE B : INCORRECT VALUES IN RECORD");
END IF;
END CASE_B;
END;
RESULT;
END C43107A;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . S T R I N G S . U N B O U N D E D . A U X --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2021, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This child package of Ada.Strings.Unbounded provides some specialized
-- access functions which are intended to allow more efficient use of the
-- facilities of Ada.Strings.Unbounded, particularly by other layered
-- utilities (such as GNAT.SPITBOL.Patterns).
package Ada.Strings.Unbounded.Aux is
pragma Preelaborate;
subtype Big_String is String (1 .. Positive'Last);
pragma Suppress_Initialization (Big_String);
-- Type used to obtain string access to given address. Initialization is
-- suppressed, since we never want to have variables of this type, and
-- we never want to attempt initialiazation of virtual variables of this
-- type (e.g. when pragma Normalize_Scalars is used).
type Big_String_Access is access all Big_String;
for Big_String_Access'Storage_Size use 0;
-- We use this access type to pass a pointer to an area of storage to be
-- accessed as a string. Of course when this pointer is used, it is the
-- responsibility of the accessor to ensure proper bounds. The storage
-- size clause ensures we do not allocate variables of this type.
procedure Get_String
(U : Unbounded_String;
S : out Big_String_Access;
L : out Natural);
pragma Inline (Get_String);
-- Return the internal string pointer used in the representation of an
-- unbounded string as well as the actual current length (which may be less
-- than S.all'Length because in general there can be extra space assigned).
-- The characters of this string may be not be modified via the returned
-- pointer, and are valid only as long as the original unbounded string is
-- not accessed or modified.
--
-- This procedure is much more efficient than the use of To_String
-- since it avoids the need to copy the string. The lower bound of the
-- referenced string returned by this call is always one, so the actual
-- string data is always accessible as S (1 .. L).
procedure Set_String
(U : out Unbounded_String;
Length : Positive;
Set : not null access procedure (S : out String));
pragma Inline (Set_String);
-- Create an unbounded string U with the given Length, using Set to fill
-- the contents of U.
end Ada.Strings.Unbounded.Aux;
|
package ascan_dfa is
aflex_debug : boolean := false;
yytext_ptr : integer; -- points to start of yytext in buffer
-- yy_ch_buf has to be 2 characters longer than YY_BUF_SIZE because we need
-- to put in 2 end-of-buffer characters (this is explained where it is
-- done) at the end of yy_ch_buf
YY_READ_BUF_SIZE : constant integer := 8192;
YY_BUF_SIZE : constant integer := YY_READ_BUF_SIZE * 2; -- size of input buffer
type unbounded_character_array is array(integer range <>) of character;
subtype ch_buf_type is unbounded_character_array(0..YY_BUF_SIZE + 1);
yy_ch_buf : ch_buf_type;
yy_cp, yy_bp : integer;
-- yy_hold_char holds the character lost when yytext is formed
yy_hold_char : character;
yy_c_buf_p : integer; -- points to current character in buffer
function YYText return string;
function YYLength return integer;
procedure YY_DO_BEFORE_ACTION;
--These variables are needed between calls to YYLex.
yy_init : boolean := true; -- do we need to initialize YYLex?
yy_start : integer := 0; -- current start state number
subtype yy_state_type is integer;
yy_last_accepting_state : yy_state_type;
yy_last_accepting_cpos : integer;
end ascan_dfa;
with ascan_dfa; use ascan_dfa;
package body ascan_dfa is
function YYText return string is
i : integer;
str_loc : integer := 1;
buffer : string(1..1024);
EMPTY_STRING : constant string := "";
begin
-- find end of buffer
i := yytext_ptr;
while ( yy_ch_buf(i) /= ASCII.NUL ) loop
buffer(str_loc ) := yy_ch_buf(i);
i := i + 1;
str_loc := str_loc + 1;
end loop;
-- return yy_ch_buf(yytext_ptr.. i - 1);
if (str_loc < 2) then
return EMPTY_STRING;
else
return buffer(1..str_loc-1);
end if;
end;
-- returns the length of the matched text
function YYLength return integer is
begin
return yy_cp - yy_bp;
end YYLength;
-- done after the current pattern has been matched and before the
-- corresponding action - sets up yytext
procedure YY_DO_BEFORE_ACTION is
begin
yytext_ptr := yy_bp;
yy_hold_char := yy_ch_buf(yy_cp);
yy_ch_buf(yy_cp) := ASCII.NUL;
yy_c_buf_p := yy_cp;
end YY_DO_BEFORE_ACTION;
end ascan_dfa;
|
with System; use System;
with Interfaces.C; use Interfaces.C;
package Memory_Set is
pragma Preelaborate;
function Memset (M : Address; C : int; Size : size_t) return Address;
pragma Export (C, Memset, "memset");
-- This function stores C converted to a Character in each of the elements
-- of the array of Characters beginning at M, with size Size. It returns a
-- pointer to M.
end Memory_Set;
|
-- { dg-do compile }
-- { dg-options "-gnatws" }
package Size_Clause1 is
-- The record inherits the alignment of Integer, which is 4, so
-- the real size is 64 instead of 40. That's OK, as long as the
-- size of a component of type R1 in a packed record is 40.
type R1 is record
I : Integer;
B : Boolean;
end record;
for R1'Size use 40;
type S1 is record
rr : R1; -- size must be 40
end record;
pragma Pack(S1);
-- The record is explicitly given alignment 1 so its real type is 40 too.
-- The size of a component of type R2 in a packed record is naturally 40.
type R2 is record
I : Integer;
B : Boolean;
end record;
for R2'Size use 40;
for R2'Alignment use 1;
type S2 is record
rr : R2; -- size must be 40
end record;
pragma Pack(S2);
-- The record is explicitly given alignment 4 so its real type is 64.
-- That's OK, as long as the size of a component of type R3 in a packed
-- record is 40.
type R3 is record
I : Integer;
B : Boolean;
end record;
for R3'Size use 40;
for R3'Alignment use 4;
type S3 is record
rr : R3; -- size must be 40
end record;
pragma Pack(S3);
end Size_Clause1;
|
-- This spec has been automatically generated from STM32WL5x_CM0P.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package STM32_SVD.ADC is
pragma Preelaborate;
---------------
-- Registers --
---------------
-- ADC_ISR_AWD array
type ADC_ISR_AWD_Field_Array is array (1 .. 3) of Boolean
with Component_Size => 1, Size => 3;
-- Type definition for ADC_ISR_AWD
type ADC_ISR_AWD_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- AWD as a value
Val : HAL.UInt3;
when True =>
-- AWD as an array
Arr : ADC_ISR_AWD_Field_Array;
end case;
end record
with Unchecked_Union, Size => 3;
for ADC_ISR_AWD_Field use record
Val at 0 range 0 .. 2;
Arr at 0 range 0 .. 2;
end record;
-- ADC interrupt and status register
type ADC_ISR_Register is record
-- ADRDY
ADRDY : Boolean := False;
-- EOSMP
EOSMP : Boolean := False;
-- EOC
EOC : Boolean := False;
-- EOS
EOS : Boolean := False;
-- OVR
OVR : Boolean := False;
-- unspecified
Reserved_5_6 : HAL.UInt2 := 16#0#;
-- AWD1
AWD : ADC_ISR_AWD_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_10_10 : HAL.Bit := 16#0#;
-- EOCAL
EOCAL : Boolean := False;
-- unspecified
Reserved_12_12 : HAL.Bit := 16#0#;
-- CCRDY
CCRDY : Boolean := False;
-- unspecified
Reserved_14_31 : HAL.UInt18 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_ISR_Register use record
ADRDY at 0 range 0 .. 0;
EOSMP at 0 range 1 .. 1;
EOC at 0 range 2 .. 2;
EOS at 0 range 3 .. 3;
OVR at 0 range 4 .. 4;
Reserved_5_6 at 0 range 5 .. 6;
AWD at 0 range 7 .. 9;
Reserved_10_10 at 0 range 10 .. 10;
EOCAL at 0 range 11 .. 11;
Reserved_12_12 at 0 range 12 .. 12;
CCRDY at 0 range 13 .. 13;
Reserved_14_31 at 0 range 14 .. 31;
end record;
-- ADC interrupt enable register
type ADC_IER_Register is record
-- ADRDYIE
ADRDYIE : Boolean := False;
-- EOSMPIE
EOSMPIE : Boolean := False;
-- EOCIE
EOCIE : Boolean := False;
-- EOSIE
EOSIE : Boolean := False;
-- OVRIE
OVRIE : Boolean := False;
-- unspecified
Reserved_5_6 : HAL.UInt2 := 16#0#;
-- AWD1IE
AWD1IE : Boolean := False;
-- AWD2IE
AWD2IE : Boolean := False;
-- AWD3IE
AWD3IE : Boolean := False;
-- unspecified
Reserved_10_10 : HAL.Bit := 16#0#;
-- EOCALIE
EOCALIE : Boolean := False;
-- unspecified
Reserved_12_12 : HAL.Bit := 16#0#;
-- CCRDYIE
CCRDYIE : Boolean := False;
-- unspecified
Reserved_14_31 : HAL.UInt18 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_IER_Register use record
ADRDYIE at 0 range 0 .. 0;
EOSMPIE at 0 range 1 .. 1;
EOCIE at 0 range 2 .. 2;
EOSIE at 0 range 3 .. 3;
OVRIE at 0 range 4 .. 4;
Reserved_5_6 at 0 range 5 .. 6;
AWD1IE at 0 range 7 .. 7;
AWD2IE at 0 range 8 .. 8;
AWD3IE at 0 range 9 .. 9;
Reserved_10_10 at 0 range 10 .. 10;
EOCALIE at 0 range 11 .. 11;
Reserved_12_12 at 0 range 12 .. 12;
CCRDYIE at 0 range 13 .. 13;
Reserved_14_31 at 0 range 14 .. 31;
end record;
-- ADC control register
type ADC_CR_Register is record
-- ADEN
ADEN : Boolean := False;
-- ADDIS
ADDIS : Boolean := False;
-- ADSTART
ADSTART : Boolean := False;
-- unspecified
Reserved_3_3 : HAL.Bit := 16#0#;
-- ADSTP
ADSTP : Boolean := False;
-- unspecified
Reserved_5_27 : HAL.UInt23 := 16#0#;
-- ADVREGEN
ADVREGEN : Boolean := False;
-- unspecified
Reserved_29_30 : HAL.UInt2 := 16#0#;
-- ADCAL
ADCAL : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_CR_Register use record
ADEN at 0 range 0 .. 0;
ADDIS at 0 range 1 .. 1;
ADSTART at 0 range 2 .. 2;
Reserved_3_3 at 0 range 3 .. 3;
ADSTP at 0 range 4 .. 4;
Reserved_5_27 at 0 range 5 .. 27;
ADVREGEN at 0 range 28 .. 28;
Reserved_29_30 at 0 range 29 .. 30;
ADCAL at 0 range 31 .. 31;
end record;
subtype ADC_CFGR1_RES_Field is HAL.UInt2;
subtype ADC_CFGR1_EXTSEL_Field is HAL.UInt3;
subtype ADC_CFGR1_EXTEN_Field is HAL.UInt2;
subtype ADC_CFGR1_AWD1CH_Field is HAL.UInt5;
-- ADC configuration register 1
type ADC_CFGR1_Register is record
-- DMAEN
DMAEN : Boolean := False;
-- DMACFG
DMACFG : Boolean := False;
-- SCANDIR
SCANDIR : Boolean := False;
-- RES
RES : ADC_CFGR1_RES_Field := 16#0#;
-- ALIGN
ALIGN : Boolean := False;
-- EXTSEL
EXTSEL : ADC_CFGR1_EXTSEL_Field := 16#0#;
-- unspecified
Reserved_9_9 : HAL.Bit := 16#0#;
-- EXTEN
EXTEN : ADC_CFGR1_EXTEN_Field := 16#0#;
-- OVRMOD
OVRMOD : Boolean := False;
-- CONT
CONT : Boolean := False;
-- WAIT
WAIT : Boolean := False;
-- AUTOFF
AUTOFF : Boolean := False;
-- DISCEN
DISCEN : Boolean := False;
-- unspecified
Reserved_17_20 : HAL.UInt4 := 16#0#;
-- CHSELRMOD
CHSELRMOD : Boolean := False;
-- AWD1SGL
AWD1SGL : Boolean := False;
-- AWD1EN
AWD1EN : Boolean := False;
-- unspecified
Reserved_24_25 : HAL.UInt2 := 16#0#;
-- AWD1CH
AWD1CH : ADC_CFGR1_AWD1CH_Field := 16#0#;
-- unspecified
Reserved_31_31 : HAL.Bit := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_CFGR1_Register use record
DMAEN at 0 range 0 .. 0;
DMACFG at 0 range 1 .. 1;
SCANDIR at 0 range 2 .. 2;
RES at 0 range 3 .. 4;
ALIGN at 0 range 5 .. 5;
EXTSEL at 0 range 6 .. 8;
Reserved_9_9 at 0 range 9 .. 9;
EXTEN at 0 range 10 .. 11;
OVRMOD at 0 range 12 .. 12;
CONT at 0 range 13 .. 13;
WAIT at 0 range 14 .. 14;
AUTOFF at 0 range 15 .. 15;
DISCEN at 0 range 16 .. 16;
Reserved_17_20 at 0 range 17 .. 20;
CHSELRMOD at 0 range 21 .. 21;
AWD1SGL at 0 range 22 .. 22;
AWD1EN at 0 range 23 .. 23;
Reserved_24_25 at 0 range 24 .. 25;
AWD1CH at 0 range 26 .. 30;
Reserved_31_31 at 0 range 31 .. 31;
end record;
-- ADC_CFGR2_OVSR array
type ADC_CFGR2_OVSR_Field_Array is array (0 .. 2) of Boolean
with Component_Size => 1, Size => 3;
-- Type definition for ADC_CFGR2_OVSR
type ADC_CFGR2_OVSR_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- OVSR as a value
Val : HAL.UInt3;
when True =>
-- OVSR as an array
Arr : ADC_CFGR2_OVSR_Field_Array;
end case;
end record
with Unchecked_Union, Size => 3;
for ADC_CFGR2_OVSR_Field use record
Val at 0 range 0 .. 2;
Arr at 0 range 0 .. 2;
end record;
-- ADC_CFGR2_OVSS array
type ADC_CFGR2_OVSS_Field_Array is array (0 .. 3) of Boolean
with Component_Size => 1, Size => 4;
-- Type definition for ADC_CFGR2_OVSS
type ADC_CFGR2_OVSS_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- OVSS as a value
Val : HAL.UInt4;
when True =>
-- OVSS as an array
Arr : ADC_CFGR2_OVSS_Field_Array;
end case;
end record
with Unchecked_Union, Size => 4;
for ADC_CFGR2_OVSS_Field use record
Val at 0 range 0 .. 3;
Arr at 0 range 0 .. 3;
end record;
subtype ADC_CFGR2_CKMODE_Field is HAL.UInt2;
-- ADC configuration register 2
type ADC_CFGR2_Register is record
-- OVSE
OVSE : Boolean := False;
-- unspecified
Reserved_1_1 : HAL.Bit := 16#0#;
-- OVSR0
OVSR : ADC_CFGR2_OVSR_Field :=
(As_Array => False, Val => 16#0#);
-- OVSS0
OVSS : ADC_CFGR2_OVSS_Field :=
(As_Array => False, Val => 16#0#);
-- TOVS
TOVS : Boolean := False;
-- unspecified
Reserved_10_28 : HAL.UInt19 := 16#0#;
-- LFTRIG
LFTRIG : Boolean := False;
-- CKMODE
CKMODE : ADC_CFGR2_CKMODE_Field := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_CFGR2_Register use record
OVSE at 0 range 0 .. 0;
Reserved_1_1 at 0 range 1 .. 1;
OVSR at 0 range 2 .. 4;
OVSS at 0 range 5 .. 8;
TOVS at 0 range 9 .. 9;
Reserved_10_28 at 0 range 10 .. 28;
LFTRIG at 0 range 29 .. 29;
CKMODE at 0 range 30 .. 31;
end record;
subtype ADC_SMPR_SMP1_Field is HAL.UInt3;
subtype ADC_SMPR_SMP2_Field is HAL.UInt3;
subtype ADC_SMPR_SMPSEL_Field is HAL.UInt18;
-- ADC sampling time register
type ADC_SMPR_Register is record
-- SMP1
SMP1 : ADC_SMPR_SMP1_Field := 16#0#;
-- unspecified
Reserved_3_3 : HAL.Bit := 16#0#;
-- SMP2
SMP2 : ADC_SMPR_SMP2_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- SMPSEL
SMPSEL : ADC_SMPR_SMPSEL_Field := 16#0#;
-- unspecified
Reserved_26_31 : HAL.UInt6 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_SMPR_Register use record
SMP1 at 0 range 0 .. 2;
Reserved_3_3 at 0 range 3 .. 3;
SMP2 at 0 range 4 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
SMPSEL at 0 range 8 .. 25;
Reserved_26_31 at 0 range 26 .. 31;
end record;
subtype ADC_AWD1TR_LT1_Field is HAL.UInt12;
subtype ADC_AWD1TR_HT1_Field is HAL.UInt12;
-- ADC watchdog threshold register
type ADC_AWD1TR_Register is record
-- LT1
LT1 : ADC_AWD1TR_LT1_Field := 16#0#;
-- unspecified
Reserved_12_15 : HAL.UInt4 := 16#0#;
-- HT1
HT1 : ADC_AWD1TR_HT1_Field := 16#FFF#;
-- unspecified
Reserved_28_31 : HAL.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_AWD1TR_Register use record
LT1 at 0 range 0 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
HT1 at 0 range 16 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype ADC_AWD2TR_LT2_Field is HAL.UInt12;
subtype ADC_AWD2TR_HT2_Field is HAL.UInt12;
-- ADC watchdog threshold register
type ADC_AWD2TR_Register is record
-- LT2
LT2 : ADC_AWD2TR_LT2_Field := 16#0#;
-- unspecified
Reserved_12_15 : HAL.UInt4 := 16#0#;
-- HT2
HT2 : ADC_AWD2TR_HT2_Field := 16#0#;
-- unspecified
Reserved_28_31 : HAL.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_AWD2TR_Register use record
LT2 at 0 range 0 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
HT2 at 0 range 16 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype ADC_CHSELR0_CHSEL_Field is HAL.UInt18;
-- channel selection register
type ADC_CHSELR0_Register is record
-- CHSEL
CHSEL : ADC_CHSELR0_CHSEL_Field := 16#0#;
-- unspecified
Reserved_18_31 : HAL.UInt14 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_CHSELR0_Register use record
CHSEL at 0 range 0 .. 17;
Reserved_18_31 at 0 range 18 .. 31;
end record;
-- ADC_CHSELR1_SQ array element
subtype ADC_CHSELR1_SQ_Element is HAL.UInt4;
-- ADC_CHSELR1_SQ array
type ADC_CHSELR1_SQ_Field_Array is array (1 .. 8)
of ADC_CHSELR1_SQ_Element
with Component_Size => 4, Size => 32;
-- channel selection register
type ADC_CHSELR1_Register
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- SQ as a value
Val : HAL.UInt32;
when True =>
-- SQ as an array
Arr : ADC_CHSELR1_SQ_Field_Array;
end case;
end record
with Unchecked_Union, Size => 32, Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_CHSELR1_Register use record
Val at 0 range 0 .. 31;
Arr at 0 range 0 .. 31;
end record;
subtype ADC_AWD3TR_LT3_Field is HAL.UInt12;
subtype ADC_AWD3TR_HT3_Field is HAL.UInt12;
-- ADC watchdog threshold register
type ADC_AWD3TR_Register is record
-- LT3
LT3 : ADC_AWD3TR_LT3_Field := 16#0#;
-- unspecified
Reserved_12_15 : HAL.UInt4 := 16#0#;
-- HT3
HT3 : ADC_AWD3TR_HT3_Field := 16#FFF#;
-- unspecified
Reserved_28_31 : HAL.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_AWD3TR_Register use record
LT3 at 0 range 0 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
HT3 at 0 range 16 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype ADC_DR_DATA_Field is HAL.UInt16;
-- ADC data register
type ADC_DR_Register is record
-- Read-only. DATA
DATA : ADC_DR_DATA_Field;
-- unspecified
Reserved_16_31 : HAL.UInt16;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_DR_Register use record
DATA at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype ADC_AWD2CR_AWD2CH_Field is HAL.UInt18;
-- ADC Analog Watchdog 2 Configuration register
type ADC_AWD2CR_Register is record
-- AWD2CH
AWD2CH : ADC_AWD2CR_AWD2CH_Field := 16#0#;
-- unspecified
Reserved_18_31 : HAL.UInt14 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_AWD2CR_Register use record
AWD2CH at 0 range 0 .. 17;
Reserved_18_31 at 0 range 18 .. 31;
end record;
subtype ADC_AWD3CR_AWD3CH_Field is HAL.UInt18;
-- ADC Analog Watchdog 3 Configuration register
type ADC_AWD3CR_Register is record
-- AWD3CH
AWD3CH : ADC_AWD3CR_AWD3CH_Field := 16#0#;
-- unspecified
Reserved_18_31 : HAL.UInt14 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_AWD3CR_Register use record
AWD3CH at 0 range 0 .. 17;
Reserved_18_31 at 0 range 18 .. 31;
end record;
subtype ADC_CALFACT_CALFACT_Field is HAL.UInt7;
-- ADC Calibration factor
type ADC_CALFACT_Register is record
-- CALFACT
CALFACT : ADC_CALFACT_CALFACT_Field := 16#0#;
-- unspecified
Reserved_7_31 : HAL.UInt25 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_CALFACT_Register use record
CALFACT at 0 range 0 .. 6;
Reserved_7_31 at 0 range 7 .. 31;
end record;
-- ADC_CCR_PRESC array
type ADC_CCR_PRESC_Field_Array is array (0 .. 3) of Boolean
with Component_Size => 1, Size => 4;
-- Type definition for ADC_CCR_PRESC
type ADC_CCR_PRESC_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- PRESC as a value
Val : HAL.UInt4;
when True =>
-- PRESC as an array
Arr : ADC_CCR_PRESC_Field_Array;
end case;
end record
with Unchecked_Union, Size => 4;
for ADC_CCR_PRESC_Field use record
Val at 0 range 0 .. 3;
Arr at 0 range 0 .. 3;
end record;
-- ADC common configuration register
type ADC_CCR_Register is record
-- unspecified
Reserved_0_17 : HAL.UInt18 := 16#0#;
-- PRESC0
PRESC : ADC_CCR_PRESC_Field :=
(As_Array => False, Val => 16#0#);
-- VREFEN
VREFEN : Boolean := False;
-- TSEN
TSEN : Boolean := False;
-- VBATEN
VBATEN : Boolean := False;
-- unspecified
Reserved_25_31 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ADC_CCR_Register use record
Reserved_0_17 at 0 range 0 .. 17;
PRESC at 0 range 18 .. 21;
VREFEN at 0 range 22 .. 22;
TSEN at 0 range 23 .. 23;
VBATEN at 0 range 24 .. 24;
Reserved_25_31 at 0 range 25 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
type ADC_Disc is
(Val_0,
Val_1);
-- Analog to digital convertor
type ADC_Peripheral
(Discriminent : ADC_Disc := Val_0)
is record
-- ADC interrupt and status register
ADC_ISR : aliased ADC_ISR_Register;
-- ADC interrupt enable register
ADC_IER : aliased ADC_IER_Register;
-- ADC control register
ADC_CR : aliased ADC_CR_Register;
-- ADC configuration register 1
ADC_CFGR1 : aliased ADC_CFGR1_Register;
-- ADC configuration register 2
ADC_CFGR2 : aliased ADC_CFGR2_Register;
-- ADC sampling time register
ADC_SMPR : aliased ADC_SMPR_Register;
-- ADC watchdog threshold register
ADC_AWD1TR : aliased ADC_AWD1TR_Register;
-- ADC watchdog threshold register
ADC_AWD2TR : aliased ADC_AWD2TR_Register;
-- ADC watchdog threshold register
ADC_AWD3TR : aliased ADC_AWD3TR_Register;
-- ADC data register
ADC_DR : aliased ADC_DR_Register;
-- ADC Analog Watchdog 2 Configuration register
ADC_AWD2CR : aliased ADC_AWD2CR_Register;
-- ADC Analog Watchdog 3 Configuration register
ADC_AWD3CR : aliased ADC_AWD3CR_Register;
-- ADC Calibration factor
ADC_CALFACT : aliased ADC_CALFACT_Register;
-- ADC common configuration register
ADC_CCR : aliased ADC_CCR_Register;
case Discriminent is
when Val_0 =>
-- channel selection register
ADC_CHSELR0 : aliased ADC_CHSELR0_Register;
when Val_1 =>
-- channel selection register
ADC_CHSELR1 : aliased ADC_CHSELR1_Register;
end case;
end record
with Unchecked_Union, Volatile;
for ADC_Peripheral use record
ADC_ISR at 16#0# range 0 .. 31;
ADC_IER at 16#4# range 0 .. 31;
ADC_CR at 16#8# range 0 .. 31;
ADC_CFGR1 at 16#C# range 0 .. 31;
ADC_CFGR2 at 16#10# range 0 .. 31;
ADC_SMPR at 16#14# range 0 .. 31;
ADC_AWD1TR at 16#20# range 0 .. 31;
ADC_AWD2TR at 16#24# range 0 .. 31;
ADC_AWD3TR at 16#2C# range 0 .. 31;
ADC_DR at 16#40# range 0 .. 31;
ADC_AWD2CR at 16#A0# range 0 .. 31;
ADC_AWD3CR at 16#A4# range 0 .. 31;
ADC_CALFACT at 16#B4# range 0 .. 31;
ADC_CCR at 16#308# range 0 .. 31;
ADC_CHSELR0 at 16#28# range 0 .. 31;
ADC_CHSELR1 at 16#28# range 0 .. 31;
end record;
-- Analog to digital convertor
ADC_Periph : aliased ADC_Peripheral
with Import, Address => ADC_Base;
end STM32_SVD.ADC;
|
package body Main_Loop is
procedure Main_Loop_f (This : in out MOS_T; Instruction : in Fun_Array) is
-- Frequency is expressed in MHz
-- 1 MHz = 10**(-6) seconds = 1 microsecond = 1000 nanoseconds
-- 3 MHz = 3*10**(-6) seconds = 0.333333.. microseconds = 333 nanosceonds
Next_Release : Ada.Real_Time.Time := The_Clock;
Frequency : Integer := 3;
Period : Integer := 1000/Frequency;
Release_Interval : constant Ada.Real_Time.Time_Span := Ada.Real_Time.Nanoseconds (Period);
begin
Next_Release := The_Clock + Release_Interval;
While_Loop :
while This.Mem(This.PC) /= 0 loop
Print_Status(This);
Instruction(This.Mem(This.PC))(This);
This.PC := This.PC + 2;
delay until Next_Release;
Next_Release := Next_Release + Release_Interval;
end loop While_Loop;
end Main_Loop_f;
end Main_Loop;
|
-- Copyright 2016 Steven Stewart-Gallus
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-- implied. See the License for the specific language governing
-- permissions and limitations under the License.
with System;
limited with Libc.Time.GNU;
package Pulse.Mainloop.API with
Spark_Mode => Off is
subtype pa_io_event_flags is unsigned;
PA_IO_EVENT_NULL : constant pa_io_event_flags := 0;
PA_IO_EVENT_INPUT : constant pa_io_event_flags := 1;
PA_IO_EVENT_OUTPUT : constant pa_io_event_flags := 2;
PA_IO_EVENT_HANGUP : constant pa_io_event_flags := 4;
PA_IO_EVENT_ERROR : constant pa_io_event_flags :=
8; -- /usr/include/pulse/mainloop-api.h:52
subtype pa_io_event_flags_t is pa_io_event_flags;
-- skipped empty struct pa_io_event
type pa_io_event_cb_t is access procedure
(arg1 : System.Address;
arg2 : System.Address;
arg3 : int;
arg4 : pa_io_event_flags_t;
arg5 : System.Address);
pragma Convention
(C,
pa_io_event_cb_t); -- /usr/include/pulse/mainloop-api.h:63
type pa_io_event_destroy_cb_t is access procedure
(arg1 : System.Address;
arg2 : System.Address;
arg3 : System.Address);
pragma Convention
(C,
pa_io_event_destroy_cb_t); -- /usr/include/pulse/mainloop-api.h:65
-- skipped empty struct pa_time_event
type pa_time_event_cb_t is access procedure
(arg1 : System.Address;
arg2 : System.Address;
arg3 : access constant Libc.Time.GNU.timeval;
arg4 : System.Address);
pragma Convention
(C,
pa_time_event_cb_t); -- /usr/include/pulse/mainloop-api.h:70
type pa_time_event_destroy_cb_t is access procedure
(arg1 : System.Address;
arg2 : System.Address;
arg3 : System.Address);
pragma Convention
(C,
pa_time_event_destroy_cb_t); -- /usr/include/pulse/mainloop-api.h:72
-- skipped empty struct pa_defer_event
type pa_defer_event_cb_t is access procedure
(arg1 : System.Address;
arg2 : System.Address;
arg3 : System.Address);
pragma Convention
(C,
pa_defer_event_cb_t); -- /usr/include/pulse/mainloop-api.h:77
type pa_defer_event_destroy_cb_t is access procedure
(arg1 : System.Address;
arg2 : System.Address;
arg3 : System.Address);
pragma Convention
(C,
pa_defer_event_destroy_cb_t); -- /usr/include/pulse/mainloop-api.h:79
type pa_mainloop_api is record
userdata : System.Address; -- /usr/include/pulse/mainloop-api.h:84
io_new : access function
(arg1 : access pa_mainloop_api;
arg2 : int;
arg3 : pa_io_event_flags_t;
arg4 : pa_io_event_cb_t;
arg5 : System.Address)
return System.Address; -- /usr/include/pulse/mainloop-api.h:87
io_enable : access procedure
(arg1 : System.Address;
arg2 : pa_io_event_flags_t); -- /usr/include/pulse/mainloop-api.h:89
io_free : access procedure
(arg1 : System.Address); -- /usr/include/pulse/mainloop-api.h:91
io_set_destroy : access procedure
(arg1 : System.Address;
arg2 : pa_io_event_destroy_cb_t); -- /usr/include/pulse/mainloop-api.h:93
time_new : access function
(arg1 : access pa_mainloop_api;
arg2 : access constant Libc.Time.GNU.timeval;
arg3 : pa_time_event_cb_t;
arg4 : System.Address)
return System.Address; -- /usr/include/pulse/mainloop-api.h:96
time_restart : access procedure
(arg1 : System.Address;
arg2 : access constant Libc.Time.GNU
.timeval); -- /usr/include/pulse/mainloop-api.h:98
time_free : access procedure
(arg1 : System.Address); -- /usr/include/pulse/mainloop-api.h:100
time_set_destroy : access procedure
(arg1 : System.Address;
arg2 : pa_time_event_destroy_cb_t); -- /usr/include/pulse/mainloop-api.h:102
defer_new : access function
(arg1 : access pa_mainloop_api;
arg2 : pa_defer_event_cb_t;
arg3 : System.Address)
return System.Address; -- /usr/include/pulse/mainloop-api.h:105
defer_enable : access procedure
(arg1 : System.Address;
arg2 : int); -- /usr/include/pulse/mainloop-api.h:107
defer_free : access procedure
(arg1 : System.Address); -- /usr/include/pulse/mainloop-api.h:109
defer_set_destroy : access procedure
(arg1 : System.Address;
arg2 : pa_defer_event_destroy_cb_t); -- /usr/include/pulse/mainloop-api.h:111
quit : access procedure
(arg1 : access pa_mainloop_api;
arg2 : int); -- /usr/include/pulse/mainloop-api.h:114
end record;
pragma Convention
(C_Pass_By_Copy,
pa_mainloop_api); -- /usr/include/pulse/mainloop-api.h:82
procedure pa_mainloop_api_once
(m : access pa_mainloop_api;
callback : access procedure
(arg1 : access pa_mainloop_api;
arg2 : System.Address);
userdata : System.Address); -- /usr/include/pulse/mainloop-api.h:118
pragma Import (C, pa_mainloop_api_once, "pa_mainloop_api_once");
end Pulse.Mainloop.API;
|
-- { dg-do compile }
-- { dg-options "-O -fdump-tree-esra" }
with Opt34_Pkg; use Opt34_Pkg;
procedure Opt34 is
function Local_Fun (Arg : T_Private) return T_Private is
Result : T_Private;
begin
case Get_Integer (Arg) is
when 1 =>
Result := Get_Private (100);
when 2 =>
Result := T_Private_Zero;
when others =>
null;
end case;
return Result;
end Local_Fun;
begin
Assert (Get_Integer (Local_Fun (Get_Private (1))) = 100);
end;
-- { dg-final { scan-tree-dump "Created a replacement for result" "esra" } }
|
-- This package has been generated automatically by GNATtest.
-- Do not edit any part of it, see GNATtest documentation for more details.
-- begin read only
with GNATtest_Generated;
package Tk.TopLevel.Toplevel_Create_Options_Test_Data
.Toplevel_Create_Options_Tests
is
type Test_Toplevel_Create_Options is new GNATtest_Generated
.GNATtest_Standard
.Tk
.TopLevel
.Toplevel_Create_Options_Test_Data
.Test_Toplevel_Create_Options with
null record;
procedure Test_Create_32e405_9db90c
(Gnattest_T: in out Test_Toplevel_Create_Options);
-- tk-toplevel.ads:135:4:Create:Test_Create_TopLevel1
procedure Test_Create_ebbdc1_055047
(Gnattest_T: in out Test_Toplevel_Create_Options);
-- tk-toplevel.ads:168:4:Create:Test_Create_TopLevel2
procedure Test_Get_Options_ded36e_2e13ca
(Gnattest_T: in out Test_Toplevel_Create_Options);
-- tk-toplevel.ads:192:4:Get_Options:Test_Get_Options_TopLevel
end Tk.TopLevel.Toplevel_Create_Options_Test_Data
.Toplevel_Create_Options_Tests;
-- end read only
|
------------------------------------------------------------------------------
-- Copyright (c) 2014, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Natools.Web.List_Templates provides an abstraction around list rendering --
-- parameters, and a generic procedure to use it. --
-- When the list is empty, only If_Empty is output, otherwise the following --
-- scheme is rendered: --
-- <prefix> [<ellipsis_prefix>] <item_1> <separator> <item_2> ... --
-- ... <separator> <item_n> [<ellipsis_suffix>] <suffix> --
-- The optional ellipses are output when the list is only partially output. --
-- Ellipses_Are_Items controls whether the non-empty ellipses count towards --
-- the given limit. --
-- Shown_End controls whether partially rendered lists omit items at the --
-- beginning or at the end of the displayed list (i.e. after taking into --
-- account Going). --
------------------------------------------------------------------------------
with Ada.Containers;
with Ada.Iterator_Interfaces;
with Natools.S_Expressions.Atom_Refs;
with Natools.S_Expressions.Caches;
with Natools.S_Expressions.Lockable;
with Natools.Web.Sites;
package Natools.Web.List_Templates is
type Count is new Ada.Containers.Count_Type;
type Direction is (Forward, Backward);
type List_End is (Beginning, Ending);
type Parameters is record
Ellipses_Are_Items : Boolean := False;
Ellipsis_Prefix : S_Expressions.Atom_Refs.Immutable_Reference;
Ellipsis_Suffix : S_Expressions.Atom_Refs.Immutable_Reference;
Going : Direction := Forward;
Shown_End : List_End := Beginning;
If_Empty : S_Expressions.Atom_Refs.Immutable_Reference;
Limit : Count := 0;
Prefix : S_Expressions.Atom_Refs.Immutable_Reference;
Separator : S_Expressions.Atom_Refs.Immutable_Reference;
Suffix : S_Expressions.Atom_Refs.Immutable_Reference;
Template : S_Expressions.Caches.Cursor;
end record;
procedure Read_Parameters
(Object : in out Parameters;
Expression : in out S_Expressions.Lockable.Descriptor'Class);
function Read_Parameters
(Expression : in out S_Expressions.Lockable.Descriptor'Class)
return Parameters;
generic
type Cursor (<>) is private;
with package Iterators is new Ada.Iterator_Interfaces
(Cursor => Cursor, others => <>);
with procedure Render
(Exchange : in out Sites.Exchange;
Position : in Cursor;
Expression : in out S_Expressions.Lockable.Descriptor'Class) is <>;
procedure Render
(Exchange : in out Sites.Exchange;
Iterator : in Iterators.Reversible_Iterator'Class;
Param : in Parameters);
end Natools.Web.List_Templates;
|
-- This spec has been automatically generated from STM32F7x9.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package STM32_SVD.LTDC is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype SSCR_VSH_Field is HAL.UInt11;
subtype SSCR_HSW_Field is HAL.UInt10;
-- Synchronization Size Configuration Register
type SSCR_Register is record
-- Vertical Synchronization Height (in units of horizontal scan line)
VSH : SSCR_VSH_Field := 16#0#;
-- unspecified
Reserved_11_15 : HAL.UInt5 := 16#0#;
-- Horizontal Synchronization Width (in units of pixel clock period)
HSW : SSCR_HSW_Field := 16#0#;
-- unspecified
Reserved_26_31 : HAL.UInt6 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SSCR_Register use record
VSH at 0 range 0 .. 10;
Reserved_11_15 at 0 range 11 .. 15;
HSW at 0 range 16 .. 25;
Reserved_26_31 at 0 range 26 .. 31;
end record;
subtype BPCR_AVBP_Field is HAL.UInt11;
subtype BPCR_AHBP_Field is HAL.UInt10;
-- Back Porch Configuration Register
type BPCR_Register is record
-- Accumulated Vertical back porch (in units of horizontal scan line)
AVBP : BPCR_AVBP_Field := 16#0#;
-- unspecified
Reserved_11_15 : HAL.UInt5 := 16#0#;
-- Accumulated Horizontal back porch (in units of pixel clock period)
AHBP : BPCR_AHBP_Field := 16#0#;
-- unspecified
Reserved_26_31 : HAL.UInt6 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for BPCR_Register use record
AVBP at 0 range 0 .. 10;
Reserved_11_15 at 0 range 11 .. 15;
AHBP at 0 range 16 .. 25;
Reserved_26_31 at 0 range 26 .. 31;
end record;
subtype AWCR_AAH_Field is HAL.UInt11;
subtype AWCR_AAW_Field is HAL.UInt10;
-- Active Width Configuration Register
type AWCR_Register is record
-- Accumulated Active Height (in units of horizontal scan line)
AAH : AWCR_AAH_Field := 16#0#;
-- unspecified
Reserved_11_15 : HAL.UInt5 := 16#0#;
-- Accumulated Active Width
AAW : AWCR_AAW_Field := 16#0#;
-- unspecified
Reserved_26_31 : HAL.UInt6 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for AWCR_Register use record
AAH at 0 range 0 .. 10;
Reserved_11_15 at 0 range 11 .. 15;
AAW at 0 range 16 .. 25;
Reserved_26_31 at 0 range 26 .. 31;
end record;
subtype TWCR_TOTALH_Field is HAL.UInt11;
subtype TWCR_TOTALW_Field is HAL.UInt10;
-- Total Width Configuration Register
type TWCR_Register is record
-- Total Height (in units of horizontal scan line)
TOTALH : TWCR_TOTALH_Field := 16#0#;
-- unspecified
Reserved_11_15 : HAL.UInt5 := 16#0#;
-- Total Width (in units of pixel clock period)
TOTALW : TWCR_TOTALW_Field := 16#0#;
-- unspecified
Reserved_26_31 : HAL.UInt6 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for TWCR_Register use record
TOTALH at 0 range 0 .. 10;
Reserved_11_15 at 0 range 11 .. 15;
TOTALW at 0 range 16 .. 25;
Reserved_26_31 at 0 range 26 .. 31;
end record;
subtype GCR_DBW_Field is HAL.UInt3;
subtype GCR_DGW_Field is HAL.UInt3;
subtype GCR_DRW_Field is HAL.UInt3;
-- Global Control Register
type GCR_Register is record
-- LCD-TFT controller enable bit
LTDCEN : Boolean := False;
-- unspecified
Reserved_1_3 : HAL.UInt3 := 16#0#;
-- Read-only. Dither Blue Width
DBW : GCR_DBW_Field := 16#2#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Read-only. Dither Green Width
DGW : GCR_DGW_Field := 16#2#;
-- unspecified
Reserved_11_11 : HAL.Bit := 16#0#;
-- Read-only. Dither Red Width
DRW : GCR_DRW_Field := 16#2#;
-- unspecified
Reserved_15_15 : HAL.Bit := 16#0#;
-- Dither Enable
DEN : Boolean := False;
-- unspecified
Reserved_17_27 : HAL.UInt11 := 16#0#;
-- Pixel Clock Polarity
PCPOL : Boolean := False;
-- Data Enable Polarity
DEPOL : Boolean := False;
-- Vertical Synchronization Polarity
VSPOL : Boolean := False;
-- Horizontal Synchronization Polarity
HSPOL : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for GCR_Register use record
LTDCEN at 0 range 0 .. 0;
Reserved_1_3 at 0 range 1 .. 3;
DBW at 0 range 4 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
DGW at 0 range 8 .. 10;
Reserved_11_11 at 0 range 11 .. 11;
DRW at 0 range 12 .. 14;
Reserved_15_15 at 0 range 15 .. 15;
DEN at 0 range 16 .. 16;
Reserved_17_27 at 0 range 17 .. 27;
PCPOL at 0 range 28 .. 28;
DEPOL at 0 range 29 .. 29;
VSPOL at 0 range 30 .. 30;
HSPOL at 0 range 31 .. 31;
end record;
-- Shadow Reload Configuration Register
type SRCR_Register is record
-- Immediate Reload
IMR : Boolean := False;
-- Vertical Blanking Reload
VBR : Boolean := False;
-- unspecified
Reserved_2_31 : HAL.UInt30 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for SRCR_Register use record
IMR at 0 range 0 .. 0;
VBR at 0 range 1 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
subtype BCCR_BC_Field is HAL.UInt24;
-- Background Color Configuration Register
type BCCR_Register is record
-- Background Color Red value
BC : BCCR_BC_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for BCCR_Register use record
BC at 0 range 0 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
-- Interrupt Enable Register
type IER_Register is record
-- Line Interrupt Enable
LIE : Boolean := False;
-- FIFO Underrun Interrupt Enable
FUIE : Boolean := False;
-- Transfer Error Interrupt Enable
TERRIE : Boolean := False;
-- Register Reload interrupt enable
RRIE : Boolean := False;
-- unspecified
Reserved_4_31 : HAL.UInt28 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for IER_Register use record
LIE at 0 range 0 .. 0;
FUIE at 0 range 1 .. 1;
TERRIE at 0 range 2 .. 2;
RRIE at 0 range 3 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
-- Interrupt Status Register
type ISR_Register is record
-- Read-only. Line Interrupt flag
LIF : Boolean;
-- Read-only. FIFO Underrun Interrupt flag
FUIF : Boolean;
-- Read-only. Transfer Error interrupt flag
TERRIF : Boolean;
-- Read-only. Register Reload Interrupt Flag
RRIF : Boolean;
-- unspecified
Reserved_4_31 : HAL.UInt28;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for ISR_Register use record
LIF at 0 range 0 .. 0;
FUIF at 0 range 1 .. 1;
TERRIF at 0 range 2 .. 2;
RRIF at 0 range 3 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
-- Interrupt Clear Register
type ICR_Register is record
-- Write-only. Clears the Line Interrupt Flag
CLIF : Boolean := False;
-- Write-only. Clears the FIFO Underrun Interrupt flag
CFUIF : Boolean := False;
-- Write-only. Clears the Transfer Error Interrupt Flag
CTERRIF : Boolean := False;
-- Write-only. Clears Register Reload Interrupt Flag
CRRIF : Boolean := False;
-- unspecified
Reserved_4_31 : HAL.UInt28 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for ICR_Register use record
CLIF at 0 range 0 .. 0;
CFUIF at 0 range 1 .. 1;
CTERRIF at 0 range 2 .. 2;
CRRIF at 0 range 3 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
subtype LIPCR_LIPOS_Field is HAL.UInt11;
-- Line Interrupt Position Configuration Register
type LIPCR_Register is record
-- Line Interrupt Position
LIPOS : LIPCR_LIPOS_Field := 16#0#;
-- unspecified
Reserved_11_31 : HAL.UInt21 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for LIPCR_Register use record
LIPOS at 0 range 0 .. 10;
Reserved_11_31 at 0 range 11 .. 31;
end record;
subtype CPSR_CYPOS_Field is HAL.UInt16;
subtype CPSR_CXPOS_Field is HAL.UInt16;
-- Current Position Status Register
type CPSR_Register is record
-- Read-only. Current Y Position
CYPOS : CPSR_CYPOS_Field;
-- Read-only. Current X Position
CXPOS : CPSR_CXPOS_Field;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CPSR_Register use record
CYPOS at 0 range 0 .. 15;
CXPOS at 0 range 16 .. 31;
end record;
-- Current Display Status Register
type CDSR_Register is record
-- Read-only. Vertical Data Enable display Status
VDES : Boolean;
-- Read-only. Horizontal Data Enable display Status
HDES : Boolean;
-- Read-only. Vertical Synchronization display Status
VSYNCS : Boolean;
-- Read-only. Horizontal Synchronization display Status
HSYNCS : Boolean;
-- unspecified
Reserved_4_31 : HAL.UInt28;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for CDSR_Register use record
VDES at 0 range 0 .. 0;
HDES at 0 range 1 .. 1;
VSYNCS at 0 range 2 .. 2;
HSYNCS at 0 range 3 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
-- Layerx Control Register
type L1CR_Register is record
-- Layer Enable
LEN : Boolean := False;
-- Color Keying Enable
COLKEN : Boolean := False;
-- unspecified
Reserved_2_3 : HAL.UInt2 := 16#0#;
-- Color Look-Up Table Enable
CLUTEN : Boolean := False;
-- unspecified
Reserved_5_31 : HAL.UInt27 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L1CR_Register use record
LEN at 0 range 0 .. 0;
COLKEN at 0 range 1 .. 1;
Reserved_2_3 at 0 range 2 .. 3;
CLUTEN at 0 range 4 .. 4;
Reserved_5_31 at 0 range 5 .. 31;
end record;
subtype L1WHPCR_WHSTPOS_Field is HAL.UInt12;
subtype L1WHPCR_WHSPPOS_Field is HAL.UInt12;
-- Layerx Window Horizontal Position Configuration Register
type L1WHPCR_Register is record
-- Window Horizontal Start Position
WHSTPOS : L1WHPCR_WHSTPOS_Field := 16#0#;
-- unspecified
Reserved_12_15 : HAL.UInt4 := 16#0#;
-- Window Horizontal Stop Position
WHSPPOS : L1WHPCR_WHSPPOS_Field := 16#0#;
-- unspecified
Reserved_28_31 : HAL.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L1WHPCR_Register use record
WHSTPOS at 0 range 0 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
WHSPPOS at 0 range 16 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype L1WVPCR_WVSTPOS_Field is HAL.UInt11;
subtype L1WVPCR_WVSPPOS_Field is HAL.UInt11;
-- Layerx Window Vertical Position Configuration Register
type L1WVPCR_Register is record
-- Window Vertical Start Position
WVSTPOS : L1WVPCR_WVSTPOS_Field := 16#0#;
-- unspecified
Reserved_11_15 : HAL.UInt5 := 16#0#;
-- Window Vertical Stop Position
WVSPPOS : L1WVPCR_WVSPPOS_Field := 16#0#;
-- unspecified
Reserved_27_31 : HAL.UInt5 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L1WVPCR_Register use record
WVSTPOS at 0 range 0 .. 10;
Reserved_11_15 at 0 range 11 .. 15;
WVSPPOS at 0 range 16 .. 26;
Reserved_27_31 at 0 range 27 .. 31;
end record;
subtype L1CKCR_CKBLUE_Field is HAL.UInt8;
subtype L1CKCR_CKGREEN_Field is HAL.UInt8;
subtype L1CKCR_CKRED_Field is HAL.UInt8;
-- Layerx Color Keying Configuration Register
type L1CKCR_Register is record
-- Color Key Blue value
CKBLUE : L1CKCR_CKBLUE_Field := 16#0#;
-- Color Key Green value
CKGREEN : L1CKCR_CKGREEN_Field := 16#0#;
-- Color Key Red value
CKRED : L1CKCR_CKRED_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L1CKCR_Register use record
CKBLUE at 0 range 0 .. 7;
CKGREEN at 0 range 8 .. 15;
CKRED at 0 range 16 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype L1PFCR_PF_Field is HAL.UInt3;
-- Layerx Pixel Format Configuration Register
type L1PFCR_Register is record
-- Pixel Format
PF : L1PFCR_PF_Field := 16#0#;
-- unspecified
Reserved_3_31 : HAL.UInt29 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L1PFCR_Register use record
PF at 0 range 0 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
subtype L1CACR_CONSTA_Field is HAL.UInt8;
-- Layerx Constant Alpha Configuration Register
type L1CACR_Register is record
-- Constant Alpha
CONSTA : L1CACR_CONSTA_Field := 16#0#;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L1CACR_Register use record
CONSTA at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype L1DCCR_DCBLUE_Field is HAL.UInt8;
subtype L1DCCR_DCGREEN_Field is HAL.UInt8;
subtype L1DCCR_DCRED_Field is HAL.UInt8;
subtype L1DCCR_DCALPHA_Field is HAL.UInt8;
-- Layerx Default Color Configuration Register
type L1DCCR_Register is record
-- Default Color Blue
DCBLUE : L1DCCR_DCBLUE_Field := 16#0#;
-- Default Color Green
DCGREEN : L1DCCR_DCGREEN_Field := 16#0#;
-- Default Color Red
DCRED : L1DCCR_DCRED_Field := 16#0#;
-- Default Color Alpha
DCALPHA : L1DCCR_DCALPHA_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L1DCCR_Register use record
DCBLUE at 0 range 0 .. 7;
DCGREEN at 0 range 8 .. 15;
DCRED at 0 range 16 .. 23;
DCALPHA at 0 range 24 .. 31;
end record;
subtype L1BFCR_BF2_Field is HAL.UInt3;
subtype L1BFCR_BF1_Field is HAL.UInt3;
-- Layerx Blending Factors Configuration Register
type L1BFCR_Register is record
-- Blending Factor 2
BF2 : L1BFCR_BF2_Field := 16#7#;
-- unspecified
Reserved_3_7 : HAL.UInt5 := 16#0#;
-- Blending Factor 1
BF1 : L1BFCR_BF1_Field := 16#6#;
-- unspecified
Reserved_11_31 : HAL.UInt21 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L1BFCR_Register use record
BF2 at 0 range 0 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
BF1 at 0 range 8 .. 10;
Reserved_11_31 at 0 range 11 .. 31;
end record;
subtype L1CFBLR_CFBLL_Field is HAL.UInt13;
subtype L1CFBLR_CFBP_Field is HAL.UInt13;
-- Layerx Color Frame Buffer Length Register
type L1CFBLR_Register is record
-- Color Frame Buffer Line Length
CFBLL : L1CFBLR_CFBLL_Field := 16#0#;
-- unspecified
Reserved_13_15 : HAL.UInt3 := 16#0#;
-- Color Frame Buffer Pitch in bytes
CFBP : L1CFBLR_CFBP_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L1CFBLR_Register use record
CFBLL at 0 range 0 .. 12;
Reserved_13_15 at 0 range 13 .. 15;
CFBP at 0 range 16 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype L1CFBLNR_CFBLNBR_Field is HAL.UInt11;
-- Layerx ColorFrame Buffer Line Number Register
type L1CFBLNR_Register is record
-- Frame Buffer Line Number
CFBLNBR : L1CFBLNR_CFBLNBR_Field := 16#0#;
-- unspecified
Reserved_11_31 : HAL.UInt21 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L1CFBLNR_Register use record
CFBLNBR at 0 range 0 .. 10;
Reserved_11_31 at 0 range 11 .. 31;
end record;
subtype L1CLUTWR_BLUE_Field is HAL.UInt8;
subtype L1CLUTWR_GREEN_Field is HAL.UInt8;
subtype L1CLUTWR_RED_Field is HAL.UInt8;
subtype L1CLUTWR_CLUTADD_Field is HAL.UInt8;
-- Layerx CLUT Write Register
type L1CLUTWR_Register is record
-- Write-only. Blue value
BLUE : L1CLUTWR_BLUE_Field := 16#0#;
-- Write-only. Green value
GREEN : L1CLUTWR_GREEN_Field := 16#0#;
-- Write-only. Red value
RED : L1CLUTWR_RED_Field := 16#0#;
-- Write-only. CLUT Address
CLUTADD : L1CLUTWR_CLUTADD_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L1CLUTWR_Register use record
BLUE at 0 range 0 .. 7;
GREEN at 0 range 8 .. 15;
RED at 0 range 16 .. 23;
CLUTADD at 0 range 24 .. 31;
end record;
-- Layerx Control Register
type L2CR_Register is record
-- Layer Enable
LEN : Boolean := False;
-- Color Keying Enable
COLKEN : Boolean := False;
-- unspecified
Reserved_2_3 : HAL.UInt2 := 16#0#;
-- Color Look-Up Table Enable
CLUTEN : Boolean := False;
-- unspecified
Reserved_5_31 : HAL.UInt27 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L2CR_Register use record
LEN at 0 range 0 .. 0;
COLKEN at 0 range 1 .. 1;
Reserved_2_3 at 0 range 2 .. 3;
CLUTEN at 0 range 4 .. 4;
Reserved_5_31 at 0 range 5 .. 31;
end record;
subtype L2WHPCR_WHSTPOS_Field is HAL.UInt12;
subtype L2WHPCR_WHSPPOS_Field is HAL.UInt12;
-- Layerx Window Horizontal Position Configuration Register
type L2WHPCR_Register is record
-- Window Horizontal Start Position
WHSTPOS : L2WHPCR_WHSTPOS_Field := 16#0#;
-- unspecified
Reserved_12_15 : HAL.UInt4 := 16#0#;
-- Window Horizontal Stop Position
WHSPPOS : L2WHPCR_WHSPPOS_Field := 16#0#;
-- unspecified
Reserved_28_31 : HAL.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L2WHPCR_Register use record
WHSTPOS at 0 range 0 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
WHSPPOS at 0 range 16 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype L2WVPCR_WVSTPOS_Field is HAL.UInt11;
subtype L2WVPCR_WVSPPOS_Field is HAL.UInt11;
-- Layerx Window Vertical Position Configuration Register
type L2WVPCR_Register is record
-- Window Vertical Start Position
WVSTPOS : L2WVPCR_WVSTPOS_Field := 16#0#;
-- unspecified
Reserved_11_15 : HAL.UInt5 := 16#0#;
-- Window Vertical Stop Position
WVSPPOS : L2WVPCR_WVSPPOS_Field := 16#0#;
-- unspecified
Reserved_27_31 : HAL.UInt5 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L2WVPCR_Register use record
WVSTPOS at 0 range 0 .. 10;
Reserved_11_15 at 0 range 11 .. 15;
WVSPPOS at 0 range 16 .. 26;
Reserved_27_31 at 0 range 27 .. 31;
end record;
subtype L2CKCR_CKBLUE_Field is HAL.UInt8;
subtype L2CKCR_CKGREEN_Field is HAL.UInt7;
subtype L2CKCR_CKRED_Field is HAL.UInt9;
-- Layerx Color Keying Configuration Register
type L2CKCR_Register is record
-- Color Key Blue value
CKBLUE : L2CKCR_CKBLUE_Field := 16#0#;
-- Color Key Green value
CKGREEN : L2CKCR_CKGREEN_Field := 16#0#;
-- Color Key Red value
CKRED : L2CKCR_CKRED_Field := 16#0#;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L2CKCR_Register use record
CKBLUE at 0 range 0 .. 7;
CKGREEN at 0 range 8 .. 14;
CKRED at 0 range 15 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
subtype L2PFCR_PF_Field is HAL.UInt3;
-- Layerx Pixel Format Configuration Register
type L2PFCR_Register is record
-- Pixel Format
PF : L2PFCR_PF_Field := 16#0#;
-- unspecified
Reserved_3_31 : HAL.UInt29 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L2PFCR_Register use record
PF at 0 range 0 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
subtype L2CACR_CONSTA_Field is HAL.UInt8;
-- Layerx Constant Alpha Configuration Register
type L2CACR_Register is record
-- Constant Alpha
CONSTA : L2CACR_CONSTA_Field := 16#0#;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L2CACR_Register use record
CONSTA at 0 range 0 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
subtype L2DCCR_DCBLUE_Field is HAL.UInt8;
subtype L2DCCR_DCGREEN_Field is HAL.UInt8;
subtype L2DCCR_DCRED_Field is HAL.UInt8;
subtype L2DCCR_DCALPHA_Field is HAL.UInt8;
-- Layerx Default Color Configuration Register
type L2DCCR_Register is record
-- Default Color Blue
DCBLUE : L2DCCR_DCBLUE_Field := 16#0#;
-- Default Color Green
DCGREEN : L2DCCR_DCGREEN_Field := 16#0#;
-- Default Color Red
DCRED : L2DCCR_DCRED_Field := 16#0#;
-- Default Color Alpha
DCALPHA : L2DCCR_DCALPHA_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L2DCCR_Register use record
DCBLUE at 0 range 0 .. 7;
DCGREEN at 0 range 8 .. 15;
DCRED at 0 range 16 .. 23;
DCALPHA at 0 range 24 .. 31;
end record;
subtype L2BFCR_BF2_Field is HAL.UInt3;
subtype L2BFCR_BF1_Field is HAL.UInt3;
-- Layerx Blending Factors Configuration Register
type L2BFCR_Register is record
-- Blending Factor 2
BF2 : L2BFCR_BF2_Field := 16#7#;
-- unspecified
Reserved_3_7 : HAL.UInt5 := 16#0#;
-- Blending Factor 1
BF1 : L2BFCR_BF1_Field := 16#6#;
-- unspecified
Reserved_11_31 : HAL.UInt21 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L2BFCR_Register use record
BF2 at 0 range 0 .. 2;
Reserved_3_7 at 0 range 3 .. 7;
BF1 at 0 range 8 .. 10;
Reserved_11_31 at 0 range 11 .. 31;
end record;
subtype L2CFBLR_CFBLL_Field is HAL.UInt13;
subtype L2CFBLR_CFBP_Field is HAL.UInt13;
-- Layerx Color Frame Buffer Length Register
type L2CFBLR_Register is record
-- Color Frame Buffer Line Length
CFBLL : L2CFBLR_CFBLL_Field := 16#0#;
-- unspecified
Reserved_13_15 : HAL.UInt3 := 16#0#;
-- Color Frame Buffer Pitch in bytes
CFBP : L2CFBLR_CFBP_Field := 16#0#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L2CFBLR_Register use record
CFBLL at 0 range 0 .. 12;
Reserved_13_15 at 0 range 13 .. 15;
CFBP at 0 range 16 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype L2CFBLNR_CFBLNBR_Field is HAL.UInt11;
-- Layerx ColorFrame Buffer Line Number Register
type L2CFBLNR_Register is record
-- Frame Buffer Line Number
CFBLNBR : L2CFBLNR_CFBLNBR_Field := 16#0#;
-- unspecified
Reserved_11_31 : HAL.UInt21 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L2CFBLNR_Register use record
CFBLNBR at 0 range 0 .. 10;
Reserved_11_31 at 0 range 11 .. 31;
end record;
subtype L2CLUTWR_BLUE_Field is HAL.UInt8;
subtype L2CLUTWR_GREEN_Field is HAL.UInt8;
subtype L2CLUTWR_RED_Field is HAL.UInt8;
subtype L2CLUTWR_CLUTADD_Field is HAL.UInt8;
-- Layerx CLUT Write Register
type L2CLUTWR_Register is record
-- Write-only. Blue value
BLUE : L2CLUTWR_BLUE_Field := 16#0#;
-- Write-only. Green value
GREEN : L2CLUTWR_GREEN_Field := 16#0#;
-- Write-only. Red value
RED : L2CLUTWR_RED_Field := 16#0#;
-- Write-only. CLUT Address
CLUTADD : L2CLUTWR_CLUTADD_Field := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for L2CLUTWR_Register use record
BLUE at 0 range 0 .. 7;
GREEN at 0 range 8 .. 15;
RED at 0 range 16 .. 23;
CLUTADD at 0 range 24 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- LCD-TFT Controller
type LTDC_Peripheral is record
-- Synchronization Size Configuration Register
SSCR : aliased SSCR_Register;
-- Back Porch Configuration Register
BPCR : aliased BPCR_Register;
-- Active Width Configuration Register
AWCR : aliased AWCR_Register;
-- Total Width Configuration Register
TWCR : aliased TWCR_Register;
-- Global Control Register
GCR : aliased GCR_Register;
-- Shadow Reload Configuration Register
SRCR : aliased SRCR_Register;
-- Background Color Configuration Register
BCCR : aliased BCCR_Register;
-- Interrupt Enable Register
IER : aliased IER_Register;
-- Interrupt Status Register
ISR : aliased ISR_Register;
-- Interrupt Clear Register
ICR : aliased ICR_Register;
-- Line Interrupt Position Configuration Register
LIPCR : aliased LIPCR_Register;
-- Current Position Status Register
CPSR : aliased CPSR_Register;
-- Current Display Status Register
CDSR : aliased CDSR_Register;
-- Layerx Control Register
L1CR : aliased L1CR_Register;
-- Layerx Window Horizontal Position Configuration Register
L1WHPCR : aliased L1WHPCR_Register;
-- Layerx Window Vertical Position Configuration Register
L1WVPCR : aliased L1WVPCR_Register;
-- Layerx Color Keying Configuration Register
L1CKCR : aliased L1CKCR_Register;
-- Layerx Pixel Format Configuration Register
L1PFCR : aliased L1PFCR_Register;
-- Layerx Constant Alpha Configuration Register
L1CACR : aliased L1CACR_Register;
-- Layerx Default Color Configuration Register
L1DCCR : aliased L1DCCR_Register;
-- Layerx Blending Factors Configuration Register
L1BFCR : aliased L1BFCR_Register;
-- Layerx Color Frame Buffer Address Register
L1CFBAR : aliased HAL.UInt32;
-- Layerx Color Frame Buffer Length Register
L1CFBLR : aliased L1CFBLR_Register;
-- Layerx ColorFrame Buffer Line Number Register
L1CFBLNR : aliased L1CFBLNR_Register;
-- Layerx CLUT Write Register
L1CLUTWR : aliased L1CLUTWR_Register;
-- Layerx Control Register
L2CR : aliased L2CR_Register;
-- Layerx Window Horizontal Position Configuration Register
L2WHPCR : aliased L2WHPCR_Register;
-- Layerx Window Vertical Position Configuration Register
L2WVPCR : aliased L2WVPCR_Register;
-- Layerx Color Keying Configuration Register
L2CKCR : aliased L2CKCR_Register;
-- Layerx Pixel Format Configuration Register
L2PFCR : aliased L2PFCR_Register;
-- Layerx Constant Alpha Configuration Register
L2CACR : aliased L2CACR_Register;
-- Layerx Default Color Configuration Register
L2DCCR : aliased L2DCCR_Register;
-- Layerx Blending Factors Configuration Register
L2BFCR : aliased L2BFCR_Register;
-- Layerx Color Frame Buffer Address Register
L2CFBAR : aliased HAL.UInt32;
-- Layerx Color Frame Buffer Length Register
L2CFBLR : aliased L2CFBLR_Register;
-- Layerx ColorFrame Buffer Line Number Register
L2CFBLNR : aliased L2CFBLNR_Register;
-- Layerx CLUT Write Register
L2CLUTWR : aliased L2CLUTWR_Register;
end record
with Volatile;
for LTDC_Peripheral use record
SSCR at 16#8# range 0 .. 31;
BPCR at 16#C# range 0 .. 31;
AWCR at 16#10# range 0 .. 31;
TWCR at 16#14# range 0 .. 31;
GCR at 16#18# range 0 .. 31;
SRCR at 16#24# range 0 .. 31;
BCCR at 16#2C# range 0 .. 31;
IER at 16#34# range 0 .. 31;
ISR at 16#38# range 0 .. 31;
ICR at 16#3C# range 0 .. 31;
LIPCR at 16#40# range 0 .. 31;
CPSR at 16#44# range 0 .. 31;
CDSR at 16#48# range 0 .. 31;
L1CR at 16#84# range 0 .. 31;
L1WHPCR at 16#88# range 0 .. 31;
L1WVPCR at 16#8C# range 0 .. 31;
L1CKCR at 16#90# range 0 .. 31;
L1PFCR at 16#94# range 0 .. 31;
L1CACR at 16#98# range 0 .. 31;
L1DCCR at 16#9C# range 0 .. 31;
L1BFCR at 16#A0# range 0 .. 31;
L1CFBAR at 16#AC# range 0 .. 31;
L1CFBLR at 16#B0# range 0 .. 31;
L1CFBLNR at 16#B4# range 0 .. 31;
L1CLUTWR at 16#C4# range 0 .. 31;
L2CR at 16#104# range 0 .. 31;
L2WHPCR at 16#108# range 0 .. 31;
L2WVPCR at 16#10C# range 0 .. 31;
L2CKCR at 16#110# range 0 .. 31;
L2PFCR at 16#114# range 0 .. 31;
L2CACR at 16#118# range 0 .. 31;
L2DCCR at 16#11C# range 0 .. 31;
L2BFCR at 16#120# range 0 .. 31;
L2CFBAR at 16#12C# range 0 .. 31;
L2CFBLR at 16#130# range 0 .. 31;
L2CFBLNR at 16#134# range 0 .. 31;
L2CLUTWR at 16#144# range 0 .. 31;
end record;
-- LCD-TFT Controller
LTDC_Periph : aliased LTDC_Peripheral
with Import, Address => System'To_Address (16#40016800#);
end STM32_SVD.LTDC;
|
with Ada.Text_IO, Ada.Directories, Ada.Containers.Indefinite_Vectors;
procedure Directory_List is
use Ada.Directories, Ada.Text_IO;
Search: Search_Type; Found: Directory_Entry_Type;
package SV is new Ada.Containers.Indefinite_Vectors(Natural, String);
Result: SV.Vector;
package Sorting is new SV.Generic_Sorting; use Sorting;
function SName return String is (Simple_Name(Found));
begin
-- search directory and store it in Result, a vector of strings
Start_Search(Search, Directory => ".", Pattern =>"");
while More_Entries(Search) loop
Get_Next_Entry(Search, Found);
declare
Name: String := Simple_Name(Found);
begin
if Name(Name'First) /= '.' then
Result.Append(Name);
end if; -- ingnore filenames beginning with "."
end;
end loop; -- Result holds the entire directory in arbitrary order
Sort(Result); -- Result holds the directory in proper order
-- print Result
for I in Result.First_Index .. Result.Last_Index loop
Put_Line(Result.Element(I));
end loop;
end Directory_List;
|
with AdaBase;
with Connect;
with Ada.Text_IO;
with AdaBase.Logger.Facility;
procedure Fruit3 is
package CON renames Connect;
package TIO renames Ada.Text_IO;
package ALF renames AdaBase.Logger.Facility;
numrows : AdaBase.Affected_Rows;
log : constant String := "/tmp/fruit3.test.log";
cmd : constant String := "DELETE FROM fruits WHERE color = 'red'";
begin
CON.DR.command_standard_logger (device => ALF.file, action => ALF.attach);
CON.DR.set_logger_filename (filename => log);
TIO.Put_Line ("The " & log & " has been attached.");
CON.connect_database;
numrows := CON.DR.execute (sql => cmd);
TIO.Put_Line ("SQL: " & cmd);
TIO.Put_Line ("Result: Deleted" & numrows'Img & " rows");
CON.DR.command_standard_logger (device => ALF.file, action => ALF.detach);
TIO.Put_Line ("The " & log & " has been deattached.");
numrows := CON.DR.execute (sql => cmd);
TIO.Put_Line ("Second execution:");
TIO.Put_Line ("Result: Deleted" & numrows'Img & " rows");
CON.DR.command_standard_logger (device => ALF.file, action => ALF.attach);
TIO.Put_Line ("The " & log & " has been attached.");
CON.DR.rollback;
CON.DR.disconnect;
end Fruit3;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . B B . C A C H E _ C O N T R O L --
-- --
-- B o d y --
-- --
-- Copyright (C) 2010-2016, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
------------------------------------------------------------------------------
-- This is the LEON version of this package
with System.BB.Threads;
with System.BB.Threads.Queues;
with System.BB.CPU_Primitives; use System.BB.CPU_Primitives;
with System.BB.Parameters; use System.BB.Parameters;
with Ada.Unchecked_Conversion; use Ada;
package body System.BB.Cache_Control is
-- As we like to share a single implementation of this
-- package between different versions of LEON, we only define
-- those bits that actually used and common to all implementations.
-- A new port can only use this package if its register definition
-- is compatible with the one declared below.
type Status_2 is mod 2**2;
for Status_2'Size use 2;
type Cache_Control_Register is
record
Ics : Status_2;
Dcs : Status_2;
Icf : Boolean;
Dcf : Boolean;
Fi : Boolean;
Fd : Boolean;
end record;
for Cache_Control_Register use
record
Ics at 0 range 30 .. 31;
Dcs at 0 range 28 .. 29;
Icf at 0 range 27 .. 27;
Dcf at 0 range 26 .. 26;
Fi at 0 range 10 .. 10;
Fd at 0 range 9 .. 9;
end record;
for Cache_Control_Register'Size use 32;
for Cache_Control_Register'Alignment use 4;
pragma Suppress_Initialization (Cache_Control_Register);
type Action_Type is (Disable, Enable, Freeze,
Enable_Freeze_Interrupt, Disable_Freeze_Interrupt);
-- Actions that can be performed on the cache control register
procedure Modify_Cache_Register
(Register : in out Cache_Control_Register;
Cache : Cache_Type;
Action : Action_Type);
-- Update the required fields in the CCR to enable/disable/freeze the
-- requested cache type.
procedure Modify_Cache_Register
(Context : in out Context_Buffer;
Index : Context_Id;
Cache : Cache_Type;
Action : Action_Type);
-- Version of Modify_Cache_Register that updates an existing context
procedure Modify_Cache
(Cache : Cache_Type;
Action : Action_Type;
Partition_Wide : Boolean);
-- Update the required fields in the CCR to enable/disable/freeze
-- (depending on Action) the requested cache type (depending on Cache)
-- for the current task or all (depending on Partition_Wide).
procedure Set_CCR (Value : Word);
pragma Import (Asm, Set_CCR, "set_ccr");
-- Set the specified value in the hardware Cache Control Register.
-- NOTE: Ideally, this function should use type Cache_Control_Register
-- as parameter. We use a simple 32-bit word to pass the parameter
-- by value (this is the convention expected by the assembly
-- implementation of set_ccr) instead of by reference (as it would
-- be the case if the parameter were a structure).
function Get_CCR return Word;
pragma Import (Asm, Get_CCR, "get_ccr");
-- Get the value from the hardware Cache Control Register.
-- NOTE: Ideally, this function should return a type
-- Cache_Control_Register. However, it returns a simple 32-bit word
-- to avoid having a function returning a structure. In SPARC, functions
-- returning structure, union, or quad-precision values require a more
-- complex handshaking mechanism between the caller and the callee (see
-- SPARC ABI) that is complicated and inefficient.
function To_Word is new Unchecked_Conversion (Cache_Control_Register, Word);
-- Necessary conversion to store the CCR in the Context
function To_CCR is new Unchecked_Conversion (Word, Cache_Control_Register);
-- Necessary conversion to retrieve the CCR from the Context
-----------------
-- Cache_Flush --
-----------------
procedure Cache_Flush (Cache : Cache_Type) is
Tmp_CCR : Cache_Control_Register;
begin
-- Get current value
Tmp_CCR := To_CCR (Get_CCR);
-- Set the appropriate bit to 1 to flush the required cache
case Cache is
when Instruction => Tmp_CCR.Fi := True;
when Data => Tmp_CCR.Fd := True;
end case;
-- Store modified value
Set_CCR (To_Word (Tmp_CCR));
end Cache_Flush;
---------------------------------------
-- Disable_Cache_Freeze_On_Interrupt --
---------------------------------------
procedure Disable_Cache_Freeze_On_Interrupt
(Cache : Cache_Type;
Partition_Wide : Boolean := False)
is
begin
Modify_Cache (Cache, Disable_Freeze_Interrupt, Partition_Wide);
end Disable_Cache_Freeze_On_Interrupt;
--------------------------------------
-- Enable_Cache_Freeze_On_Interrupt --
--------------------------------------
procedure Enable_Cache_Freeze_On_Interrupt
(Cache : Cache_Type;
Partition_Wide : Boolean := False)
is
begin
Modify_Cache (Cache, Enable_Freeze_Interrupt, Partition_Wide);
end Enable_Cache_Freeze_On_Interrupt;
---------------------
-- Get_Cache_State --
---------------------
function Get_Cache_State (Cache : Cache_Type) return Cache_State is
Status : Status_2;
begin
-- Get the requested state
case Cache is
when Instruction => Status := To_CCR (Get_CCR).Ics;
when Data => Status := To_CCR (Get_CCR).Dcs;
end case;
-- Interpret state
case Status is
when 2#00# | 2#10# => return Disabled;
when 2#11# => return Enabled;
when 2#01# => return Frozen;
end case;
end Get_Cache_State;
------------------
-- Modify_Cache --
------------------
procedure Modify_Cache
(Cache : Cache_Type;
Action : Action_Type;
Partition_Wide : Boolean)
is
Tmp_CCR : Cache_Control_Register;
Self_Id : constant Threads.Thread_Id := Threads.Thread_Self;
use type Threads.Thread_Id;
begin
-- Get current value
Tmp_CCR := To_CCR (Get_CCR);
-- Update status for the currently executing task
Modify_Cache_Register (Tmp_CCR, Cache, Action);
-- Store modified value both in the task buffer and in the actual
-- Cache Control Register. The goal of storing the value in the
-- base register is to be able to set the desired state when leaving
-- from interrupt handlers.
Modify_Cache_Register
(Self_Id.Context, Base_CCR_Context_Index, Cache, Action);
Set_CCR (To_Word (Tmp_CCR));
if Partition_Wide then
-- Update the stored cache control register for all tasks. We modify
-- both the base and the actual register to be able to set the
-- required state both for the next time the task will execute and
-- after the execution of interrupt handlers.
declare
Next_Thread : Threads.Thread_Id;
begin
Next_Thread := Threads.Queues.Global_List;
while Next_Thread /= null loop
Modify_Cache_Register
(Next_Thread.Context, Base_CCR_Context_Index, Cache, Action);
Modify_Cache_Register
(Next_Thread.Context, CCR_Context_Index, Cache, Action);
Next_Thread := Next_Thread.Global_List;
end loop;
end;
end if;
end Modify_Cache;
---------------------------
-- Modify_Cache_Register --
---------------------------
procedure Modify_Cache_Register
(Register : in out Cache_Control_Register;
Cache : Cache_Type;
Action : Action_Type)
is
begin
case Action is
-- For cache control
when Disable
| Enable
| Freeze
=>
declare
Value : constant Status_2 :=
(if Action = Enable then 2#11#
elsif Action = Freeze then 2#01#
else 2#00#);
begin
case Cache is
when Instruction => Register.Ics := Value;
when Data => Register.Dcs := Value;
end case;
end;
-- For freeze-on-interrupt
when Disable_Freeze_Interrupt
| Enable_Freeze_Interrupt
=>
case Cache is
when Instruction =>
Register.Icf := Action = Enable_Freeze_Interrupt;
when Data =>
Register.Dcf := Action = Enable_Freeze_Interrupt;
end case;
end case;
end Modify_Cache_Register;
procedure Modify_Cache_Register
(Context : in out Context_Buffer;
Index : Context_Id;
Cache : Cache_Type;
Action : Action_Type)
is
CCR : Cache_Control_Register := To_CCR (Get_Context (Context, Index));
begin
Modify_Cache_Register (CCR, Cache, Action);
Set_Context (Context, Index, To_Word (CCR));
end Modify_Cache_Register;
---------------------
-- Set_Cache_State --
---------------------
procedure Set_Cache_State
(Cache : Cache_Type;
State : Cache_State;
Partition_Wide : Boolean := False)
is
Action : constant Action_Type :=
(if State = Disabled then Disable
elsif State = Enabled then Enable
else Freeze);
begin
Modify_Cache (Cache, Action, Partition_Wide);
end Set_Cache_State;
end System.BB.Cache_Control;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2021 onox <denkpadje@gmail.com>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with EGL.API;
with EGL.Errors;
package body EGL.Objects.Configs is
Config_Color_Buffer_Type : constant Int := 16#303F#;
Config_RGB_Buffer : constant Int := 16#308E#;
Config_Caveat : constant Int := 16#3027#;
Config_Conformant : constant Int := 16#3042#;
Config_OpenGL_Bit : constant Int := 16#0008#;
Config_Renderable_Type : constant Int := 16#3040#;
Config_Surface_Type : constant Int := 16#3033#;
Config_Window_Bit : constant Int := 16#0004#;
Config_Min_Swap_Interval : constant Int := 16#303B#;
Config_Red : constant Int := 16#3024#;
Config_Green : constant Int := 16#3023#;
Config_Blue : constant Int := 16#3022#;
Config_Alpha : constant Int := 16#3021#;
Config_Depth : constant Int := 16#3025#;
Config_Stencil : constant Int := 16#3026#;
Config_Samples : constant Int := 16#3031#;
function Get_Value
(Object : Config;
Display : Displays.Display;
Attribute : Int) return Natural
is
Value : Int;
begin
if not Boolean (API.Get_Config_Attrib (Display.ID, Object.ID, Attribute, Value)) then
Errors.Raise_Exception_On_EGL_Error;
end if;
return Natural (Value);
end Get_Value;
function State (Object : Config) return Config_State is (Object.State);
function Get_Configs
(Display : Displays.Display;
Red, Green, Blue, Alpha : Natural;
Depth, Stencil : Natural;
Samples : Sample_Size) return Config_Array
is
Attributes : constant Int_Array :=
(Config_Caveat, None,
Config_Conformant, Config_OpenGL_Bit,
Config_Renderable_Type, Config_OpenGL_Bit,
Config_Color_Buffer_Type, Config_RGB_Buffer,
Config_Surface_Type, Config_Window_Bit,
Config_Red, Int (Red),
Config_Green, Int (Green),
Config_Blue, Int (Blue),
Config_Alpha, Int (Alpha),
Config_Depth, Int (Depth),
Config_Stencil, Int (Stencil),
Config_Samples, Int (Samples),
Config_Min_Swap_Interval, 0,
None);
Max_Configs : constant := 32;
IDs : ID_Array (1 .. Max_Configs);
Count : Int := 0;
begin
if not Boolean (API.Choose_Config (Display.ID, Attributes, IDs, IDs'Length, Count)) then
Errors.Raise_Exception_On_EGL_Error;
end if;
return Result : Configs.Config_Array (1 .. Natural (Count)) do
for Index in Result'Range loop
Result (Index).Reference.ID := IDs (Index);
Result (Index).State :=
(Red => Get_Value (Result (Index), Display, Config_Red),
Green => Get_Value (Result (Index), Display, Config_Green),
Blue => Get_Value (Result (Index), Display, Config_Blue),
Alpha => Get_Value (Result (Index), Display, Config_Alpha),
Depth => Get_Value (Result (Index), Display, Config_Depth),
Stencil => Get_Value (Result (Index), Display, Config_Stencil),
Samples => Sample_Size (Get_Value (Result (Index), Display, Config_Samples)));
end loop;
end return;
end Get_Configs;
end EGL.Objects.Configs;
|
-----------------------------------------------------------------------
-- Util.Beans.Objects.Records -- Generic Typed Data Representation
-- Copyright (C) 2011, 2016 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
package body Util.Beans.Objects.Records is
use Util.Concurrent.Counters;
-- ------------------------------
-- Bean Type
-- ------------------------------
type Record_Bean_Type is new Bean_Type with null record;
-- Get the type name
function Get_Name (Type_Def : in Record_Bean_Type) return String;
-- Convert the value into a boolean.
function To_Boolean (Type_Def : in Record_Bean_Type;
Value : in Object_Value) return Boolean;
-- ------------------------------
-- Get the type name
-- ------------------------------
function Get_Name (Type_Def : in Record_Bean_Type) return String is
pragma Unreferenced (Type_Def);
begin
return "Bean_Record";
end Get_Name;
-- ------------------------------
-- Convert the value into a boolean.
-- ------------------------------
function To_Boolean (Type_Def : in Record_Bean_Type;
Value : in Object_Value) return Boolean is
pragma Unreferenced (Type_Def);
begin
return Value.Proxy /= null;
end To_Boolean;
Bn_Type : aliased Record_Bean_Type := Record_Bean_Type '(null record);
-- ------------------------------
-- Create an object which holds a record of the type <b>Element_Type</b>.
-- ------------------------------
function Create return Object is
begin
return Object '(Controlled with
V => Object_Value '(Of_Type => TYPE_BEAN,
Proxy => new Element_Proxy '(Ref_Counter => ONE,
others => <>)),
Type_Def => Bn_Type'Access);
end Create;
-- ------------------------------
-- Create an object which is initialized with the given value.
-- ------------------------------
function To_Object (Value : in Element_Type) return Object is
begin
return Object '(Controlled with
V => Object_Value '(Of_Type => TYPE_BEAN,
Proxy => new Element_Proxy '(Ref_Counter => ONE,
Value => Value)),
Type_Def => Bn_Type'Access);
end To_Object;
-- ------------------------------
-- Returns the element
-- ------------------------------
function To_Element (Value : in Object) return Element_Type is
begin
if Value.V.Of_Type /= TYPE_BEAN then
raise Conversion_Error with "Object is not a bean";
end if;
declare
Proxy : constant Bean_Proxy_Access := Value.V.Proxy;
begin
if Proxy = null then
raise Conversion_Error with "Object is null";
end if;
if not (Proxy.all in Element_Proxy'Class) then
raise Conversion_Error with "Object is not of the good type";
end if;
return Element_Proxy'Class (Proxy.all).Value;
end;
end To_Element;
-- ------------------------------
-- Returns an access to the element.
-- ------------------------------
function To_Element_Access (Value : in Object) return Element_Type_Access is
begin
if Value.V.Of_Type /= TYPE_BEAN then
return null;
end if;
declare
Proxy : constant Bean_Proxy_Access := Value.V.Proxy;
begin
if Proxy = null then
return null;
end if;
if not (Proxy.all in Element_Proxy'Class) then
return null;
end if;
return Element_Proxy'Class (Proxy.all).Value'Access;
end;
end To_Element_Access;
end Util.Beans.Objects.Records;
|
with Ada.Text_IO;
procedure Hello is
package IO renames Ada.Text_IO;
begin
IO.Put_Line("Hello, world!");
end Hello;
|
with Ada.Text_Io;
package body Slots is
procedure Xaa is
begin
Ada.Text_Io.Put_Line("Xaa() called");
end;
procedure Xab is
begin
Ada.Text_Io.Put_Line("Xab() called");
end;
procedure Xac is
begin
Ada.Text_Io.Put_Line("Xac() called");
end;
procedure S1a (Value : in Integer) is
begin
Ada.Text_Io.Put_Line("S1a(" & Value'Image & ") called");
end;
procedure S1b (Value : in Integer) is
begin
Ada.Text_Io.Put_Line("S1b(" & Value'Image & ") called");
end;
procedure S1c (Value : in Integer) is
begin
Ada.Text_Io.Put_Line("S1c(" & Value'Image & ") called");
end;
end Slots;
|
package body System.Shared_Locking is
pragma Suppress (All_Checks);
procedure Enter is
begin
Enter_Hook.all;
end Enter;
procedure Leave is
begin
Leave_Hook.all;
end Leave;
end System.Shared_Locking;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure TestCSV is
csv: CSV_File;
begin
Open(csv, "FL_insurance_sample.csv", has_header => true);
Close(csv);
end TestCSV;
|
with Ada.Unchecked_Deallocation;
package body Fifo is
----------
-- Push --
----------
procedure Push (List : in out Fifo_Type; Item : in Element_Type) is
Temp : Fifo_Ptr := new Fifo_Element'(Item, null);
begin
if List.Tail = null then
List.Tail := Temp;
end if;
if List.Head /= null then
List.Head.Next := Temp;
end if;
List.Head := Temp;
end Push;
---------
-- Pop --
---------
procedure Pop (List : in out Fifo_Type; Item : out Element_Type) is
procedure Free is new Ada.Unchecked_Deallocation(Fifo_Element, Fifo_Ptr);
Temp : Fifo_Ptr := List.Tail;
begin
if List.Head = null then
raise Empty_Error;
end if;
Item := List.Tail.Value;
List.Tail := List.Tail.Next;
if List.Tail = null then
List.Head := null;
end if;
Free(Temp);
end Pop;
--------------
-- Is_Empty --
--------------
function Is_Empty (List : Fifo_Type) return Boolean is
begin
return List.Head = null;
end Is_Empty;
end Fifo;
|
-- With in my Text io package for put/get
With Text_IO; Use Text_IO;
-- With in Random float package for my random number generator
With Ada.Numerics.Float_Random; Use Ada.Numerics.Float_Random;
-- With in Unbounded strings for my string monipulation
With Ada.Strings.Unbounded; Use Ada.Strings.Unbounded;
-- Begining of lamport_algorithm code
Procedure zo is
type type_message is (req, ack, rel);
-- Instantiating integer IO.
Package INT_IO is new Integer_IO(Integer); Use INT_IO;
Package MSG_IO is new Enumeration_IO(type_message); Use MSG_IO;
-- This is my random variable.
G: Generator;
-- random seed
seed: Integer;
type receiver;
-- This is the type for my pointer variable for my receiver process.
type rec is Access receiver;
type rec_array_type is array (0..20) of rec;
all_systems_go, all_dead: boolean := false;
-- This is the declaration for my receiver type task.
task type receiver(id: Integer; n: Integer) is
Entry start(friend_array: rec_array_type);
Entry RX(dest: Integer; msg: type_message; k: Integer; j: Integer);
Entry kill;
end receiver;
-- This is the intialization or body of the receiver type and
-- this is the code that the processeses will be excuting.
task Body receiver is
type message;
type message is
record
mestype: type_message := rel;
clock: Integer := 0;
id: Integer;
end record;
task type transmit(dest: Integer; mess: type_message; clock:
Integer; i: Integer) is
end transmit;
friends: rec_array_type;
st: Unbounded_String := Null_Unbounded_String;
--mestype: type_message;
type TX is access transmit;
tsk_TX: TX;
osn, local_clock: Integer := 0;
q: array (0 .. n) of message;
temp1, temp2: message;
for_all: boolean := true;
dead: boolean := false;
task algorithm;
task body algorithm is
begin
loop
for index in 0 .. n loop
q(index).id := index;
end loop;
exit when (all_systems_go = true);
end loop;
loop
--broadcast
for I in 0..n loop
if(I /= id)then
tsk_TX := new transmit(I, req, local_clock, id);
end if;
end loop;
q(id) := (req, local_clock, id);
osn := osn + 1;
local_clock := osn;
wait:
loop
for j in 0..n loop
if j /= id then
if((q(id).clock < q(j).clock)or((q(id).clock =
q(j).clock)and(q(id).id < q(j).id)))then
null;
else
for_all := false;
end if;
end if;
end loop;
exit wait when (for_all = true);
for_all := true;
end loop wait;
exit when dead = true;
-- This is my CS. Which ever process made it to this section will
-- get to do all of this wonderful stuff. I am cating my string for
-- printing. After that small section I basicly do the samething
-- again but this time i print process # " out CS". I also have a
-- delay in there just to add more randomness.
st := (((80/(n+1))*id) * " ") & Integer'Image(id) & " in CS.";
Put(To_String(st)); New_line;
delay Duration(float(random(G)) + float(10));
st := (((80/(n+1))*id) * " ") & Integer'Image(id) & " out CS.";
Put_line(To_String(st));
-- broadcast
local_clock := osn;
for I in 0..n loop
if(I /= id)then
tsk_TX := new transmit(I, rel, local_clock, id);
end if;
end loop;
q(id) := (rel, local_clock, id);
osn := osn + 1;
local_clock := osn;
exit when dead = true;
end loop;
end algorithm;
task body transmit is
Begin
friends(dest).RX(dest, mess, clock, i);
st := ((((80/(n+1))*id)* " ") & Integer'Image(i) & "TX " &
type_message'image(mess) & integer'image(dest));
Put_line(to_string(st));
end transmit;
Begin
loop
select
accept start(friend_array: rec_array_type)do
friends := friend_array;
end start;
or
accept RX (dest: Integer; msg: type_message; k: Integer; j:Integer) do
if(dest /= id)then
st := ((((80/(n+1))*id)*" ")&integer'image(id)&"FWD "
&type_message'image(msg) & integer'image(dest)&" FROM "&integer'image(j));
put_line(to_string(st));
tsk_TX := new transmit(dest, msg, k, j);
else
if(osn < k)then
osn := k;
end if;
osn := osn + 1;
if(msg = req)then
q(j) := (req, k, j);
tsk_TX := new transmit(j, ack, osn, id);
elsif (msg = rel)then
q(j) := (rel, k, j);
elsif(msg = ack)then
if (q(j).mestype /= req) then
q(j) := (ack, k, j);
end if;
end if;
st := ((((80/(n+1))*id)*" ")&integer'image(id) & "RX " &
type_message'image(msg) & integer'image(j));
put_line(to_string(st));
end if;
end RX;
or
accept kill do
st := ((((80/(n+1))*id)*" ")&integer'image(id)&" DIE");
put_line(to_string(st));
dead := true;
-- broadcast
local_clock := osn;
for I in 0..n loop
if(I /= id)then
tsk_TX := new transmit(I, rel, local_clock, id);
end if;
end loop;
st := (((80/(n+1))*id*" ")&integer'image(id)&" DED");
put_line(to_string(st));
end kill;
end select;
exit when all_dead = true;
end loop;
end receiver;
-------------------------------------------------------------------------------
type FILE_MODE is (IN_FILE, OUT_FILE);
-- This variable is used to send the number of processes.
p_count: Integer;
pro_array: array(0..20) of rec;
friend_array: rec_array_type;
friend_file: FILE_TYPE;
-- number to keep the for loops correct
n: Integer;
index, victim, buddy: Integer;
clock: Integer := 0;
toKill : Integer;
--assigned a random ID to determine which process to kill next
dead : ARRAY (0..20) of Boolean := (Others => FALSE);
--keeps track of which processes have been slain, so we dont try to kill a
--process twice , which would raise an exception
-- to hold number of victim
--victim: Integer;
-- This is the start of my main section of code that does the prompt for how
-- many loops, what process to turn is set to and how many processes. This
-- is also the section for the process calls.
Begin -- lamport_algorithm
open(friend_file, IN_FILE, "star1");
seed := 997;
get(friend_file, p_count);
skip_line(friend_file);
reset(G, seed);
n := p_count - 1;
-- Loop to create the total number of processes that were put in.
for pid in 0 .. n loop
pro_array(pid) := new receiver(pid, n);
end loop;
for I in 0 .. n loop
while (not(END_OF_LINE(friend_file))) loop
get(friend_file, index);
get(friend_file, buddy);
friend_array(index) := pro_array(buddy);
end loop;
skip_line(friend_file);
pro_array(I).start(friend_array);
end loop;
all_systems_go := true;
FOR kill_index IN 1 .. (p_count) --for as many as there are tasks
LOOP
delay (60.0);
Put ("Going to kill random process ... ");
toKill := (Integer(random(g)) MOD p_count);
WHILE (dead(toKill))
LOOP --iterate until process toKill isn't one that is already dead!
toKill := (toKill + 1) MOD p_count; --random didnt cut it, try the next one
END LOOP;
Put (toKill); new_line;
pro_Array(toKill).kill; --kill off our random process
dead(toKill) := TRUE;
END LOOP; --end loop to kill out all processes
all_dead := true;
close(friend_file);
end zo; -- lamport_algorithm
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S W I T C H --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2005 Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package together with a child package appropriate to the client
-- tool scans switches. Note that the body of the appropraite Usage package
-- must be coordinated with the switches that are recognized by this package.
-- These Usage packages also act as the official documentation for the
-- switches that are recognized. In addition, package Debug documents
-- the otherwise undocumented debug switches that are also recognized.
with Types; use Types;
package Switch is
-- Note: The default switch character is indicated by Switch_Character,
-- but regardless of what it is, a hyphen is always allowed as an
-- (alternative) switch character.
-- Note: In GNAT, the case of switches is not significant if
-- Switches_Case_Sensitive is False. If this is the case, switch
-- characters, or letters appearing in the parameter to a switch, may be
-- either upper case or lower case.
-----------------
-- Subprograms --
-----------------
function Is_Switch (Switch_Chars : String) return Boolean;
-- Returns True iff Switch_Chars is at least two characters long,
-- and the first character indicates it is a switch.
function Is_Front_End_Switch (Switch_Chars : String) return Boolean;
-- Returns True iff Switch_Chars represents a front-end switch,
-- ie. it starts with -I or -gnat.
private
-- This section contains some common routines used by the tool dependent
-- child packages (there is one such child package for each tool that
-- uses Switches to scan switches - Compiler/gnatbind/gnatmake/.
Switch_Max_Value : constant := 999_999;
-- Maximum value permitted in switches that take a value
procedure Scan_Nat
(Switch_Chars : String;
Max : Integer;
Ptr : in out Integer;
Result : out Nat;
Switch : Character);
-- Scan natural integer parameter for switch. On entry, Ptr points
-- just past the switch character, on exit it points past the last
-- digit of the integer value.
procedure Scan_Pos
(Switch_Chars : String;
Max : Integer;
Ptr : in out Integer;
Result : out Pos;
Switch : Character);
-- Scan positive integer parameter for switch. On entry, Ptr points
-- just past the switch character, on exit it points past the last
-- digit of the integer value.
procedure Bad_Switch (Switch : Character);
procedure Bad_Switch (Switch : String);
-- Fail with an appropriate message when a switch is not recognized
end Switch;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . W I D E _ W I D E _ C H A R A C T E R T S . U N I C O D E --
-- --
-- B o d y --
-- --
-- Copyright (C) 2005, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
package body Ada.Wide_Wide_Characters.Unicode is
package G renames GNAT.UTF_32;
------------------
-- Get_Category --
------------------
function Get_Category (U : Wide_Wide_Character) return Category is
begin
return Category (G.Get_Category (Wide_Wide_Character'Pos (U)));
end Get_Category;
--------------
-- Is_Digit --
--------------
function Is_Digit (U : Wide_Wide_Character) return Boolean is
begin
return G.Is_UTF_32_Digit (Wide_Wide_Character'Pos (U));
end Is_Digit;
function Is_Digit (C : Category) return Boolean is
begin
return G.Is_UTF_32_Digit (G.Category (C));
end Is_Digit;
---------------
-- Is_Letter --
---------------
function Is_Letter (U : Wide_Wide_Character) return Boolean is
begin
return G.Is_UTF_32_Letter (Wide_Wide_Character'Pos (U));
end Is_Letter;
function Is_Letter (C : Category) return Boolean is
begin
return G.Is_UTF_32_Letter (G.Category (C));
end Is_Letter;
------------------------
-- Is_Line_Terminator --
------------------------
function Is_Line_Terminator (U : Wide_Wide_Character) return Boolean is
begin
return G.Is_UTF_32_Line_Terminator (Wide_Wide_Character'Pos (U));
end Is_Line_Terminator;
-------------
-- Is_Mark --
-------------
function Is_Mark (U : Wide_Wide_Character) return Boolean is
begin
return G.Is_UTF_32_Mark (Wide_Wide_Character'Pos (U));
end Is_Mark;
function Is_Mark (C : Category) return Boolean is
begin
return G.Is_UTF_32_Mark (G.Category (C));
end Is_Mark;
--------------------
-- Is_Non_Graphic --
--------------------
function Is_Non_Graphic (U : Wide_Wide_Character) return Boolean is
begin
return G.Is_UTF_32_Non_Graphic (Wide_Wide_Character'Pos (U));
end Is_Non_Graphic;
function Is_Non_Graphic (C : Category) return Boolean is
begin
return G.Is_UTF_32_Non_Graphic (G.Category (C));
end Is_Non_Graphic;
--------------
-- Is_Other --
--------------
function Is_Other (U : Wide_Wide_Character) return Boolean is
begin
return G.Is_UTF_32_Other (Wide_Wide_Character'Pos (U));
end Is_Other;
function Is_Other (C : Category) return Boolean is
begin
return G.Is_UTF_32_Other (G.Category (C));
end Is_Other;
--------------------
-- Is_Punctuation --
--------------------
function Is_Punctuation (U : Wide_Wide_Character) return Boolean is
begin
return G.Is_UTF_32_Punctuation (Wide_Wide_Character'Pos (U));
end Is_Punctuation;
function Is_Punctuation (C : Category) return Boolean is
begin
return G.Is_UTF_32_Punctuation (G.Category (C));
end Is_Punctuation;
--------------
-- Is_Space --
--------------
function Is_Space (U : Wide_Wide_Character) return Boolean is
begin
return G.Is_UTF_32_Space (Wide_Wide_Character'Pos (U));
end Is_Space;
function Is_Space (C : Category) return Boolean is
begin
return G.Is_UTF_32_Space (G.Category (C));
end Is_Space;
-------------------
-- To_Upper_Case --
-------------------
function To_Upper_Case
(U : Wide_Wide_Character) return Wide_Wide_Character
is
begin
return
Wide_Wide_Character'Val
(G.UTF_32_To_Upper_Case (Wide_Wide_Character'Pos (U)));
end To_Upper_Case;
end Ada.Wide_Wide_Characters.Unicode;
|
with Lto18_Pkg; use Lto18_Pkg;
package Lto18 is
procedure Proc (Driver : Rec);
end Lto18;
|
-- MIT License
--
-- Copyright (c) 2021 Glen Cornell <glen.m.cornell@gmail.com>
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
-- This is a simple example using socketcan's filtering feature to
-- help reduce CPU load. In this example, the application creates an
-- array of CAN IDs that it's interested in. The kernel will only
-- pass incoming CAN frames to the application that matches the
-- filters. To demonstrate this capability, compile and run this
-- application. In another shell, generate a random workload on
-- vcan0:
--
-- cangen vcan0
--
-- In another shell, now send specific can messages that match the
-- filter:
--
-- cansend vcan0 110#11.22.33
-- cansend vcan0 0A0#AA.BB.CC
-- cansend vcan0 320#DEADBEEF
--
-- You then see the following output for this program:
--
-- Got 16#110#
-- Got 16#0A0#
-- Got 16#320#
with Ada.Text_Io;
with Sockets.Os_Constants;
with Sockets.Can;
with Sockets.Can_Frame;
with Print_Can_Frame;
procedure Filtered_Reader is
Socket : Sockets.Can.Socket_Type;
Frame : Sockets.Can_Frame.Can_Frame;
If_Name : constant String := "vcan0";
Filters : constant Sockets.Can.Can_Filter_Array_Type :=
((Can_Id => 16#0A0#, Can_Mask => Sockets.Os_Constants.CAN_SFF_MASK),
(Can_Id => 16#110#, Can_Mask => Sockets.Os_Constants.CAN_SFF_MASK),
(Can_Id => 16#320#, Can_Mask => Sockets.Os_Constants.CAN_SFF_MASK));
procedure Process_Frame (Frame : in Sockets.Can_Frame.Can_Frame; If_Name : in String) is
begin
case Frame.Can_Id is
when 16#0A0# =>
Ada.Text_Io.Put_Line ("Got 16#0A0#");
when 16#110# =>
Ada.Text_Io.Put_Line ("Got 16#110#");
when 16#320# =>
Ada.Text_Io.Put_Line ("Got 16#320#");
when others =>
Ada.Text_Io.Put ("Received unexpected CAN frame: ");
Print_Can_Frame (Frame, If_Name);
end case;
end Process_Frame;
begin
Socket := Sockets.Can.Open(If_Name);
Sockets.Can.Apply_Filters (Socket, Filters, True);
loop
Sockets.Can.Receive_Socket(Socket, Frame);
Process_Frame (Frame, If_Name);
end loop;
end Filtered_Reader;
|
-- Copyright 2017-2021 Bartek thindil Jasicki
--
-- This file is part of Steam Sky.
--
-- Steam Sky is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- Steam Sky is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with Steam Sky. If not, see <http://www.gnu.org/licenses/>.
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with DOM.Core.Documents; use DOM.Core.Documents;
with DOM.Core.Nodes; use DOM.Core.Nodes;
with DOM.Core.Elements; use DOM.Core.Elements;
with ShipModules; use ShipModules;
with Bases; use Bases;
package body Ships.SaveLoad is
procedure SavePlayerShip(SaveData: Document; MainNode: DOM.Core.Element) is
CategoryNode, DataNode: DOM.Core.Element;
procedure SaveNumber
(Value: Integer; Name: String;
Node: DOM.Core.Element := CategoryNode) is
RawValue: constant String :=
Trim(Integer'Image(Value), Ada.Strings.Left);
begin
Set_Attribute(Node, Name, RawValue);
end SaveNumber;
begin
CategoryNode := Create_Element(SaveData, "playership");
CategoryNode := Append_Child(MainNode, CategoryNode);
Set_Attribute(CategoryNode, "name", To_String(Player_Ship.Name));
SaveNumber(Player_Ship.Sky_X, "x");
SaveNumber(Player_Ship.Sky_Y, "y");
SaveNumber(Ship_Speed'Pos(Player_Ship.Speed), "speed");
SaveNumber(Player_Ship.Upgrade_Module, "upgrademodule");
SaveNumber(Player_Ship.Destination_X, "destinationx");
SaveNumber(Player_Ship.Destination_Y, "destinationy");
SaveNumber(Player_Ship.Repair_Module, "repairpriority");
SaveNumber(Player_Ship.Home_Base, "homebase");
declare
ModuleDataNode: DOM.Core.Element;
begin
Save_Modules_Loop :
for Module of Player_Ship.Modules loop
DataNode := Create_Element(SaveData, "module");
DataNode := Append_Child(CategoryNode, DataNode);
Set_Attribute(DataNode, "name", To_String(Module.Name));
Set_Attribute(DataNode, "index", To_String(Module.Proto_Index));
SaveNumber(Module.Weight, "weight", DataNode);
SaveNumber(Module.Durability, "durability", DataNode);
SaveNumber(Module.Max_Durability, "maxdurability", DataNode);
Save_Module_Owners_Loop :
for Owner of Module.Owner loop
ModuleDataNode := Create_Element(SaveData, "owner");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
SaveNumber(Owner, "value", ModuleDataNode);
end loop Save_Module_Owners_Loop;
if Module.Upgrade_Progress > 0 then
SaveNumber
(Module.Upgrade_Progress, "upgradeprogress", DataNode);
end if;
if Module.Upgrade_Action /= NONE then
SaveNumber
(Ship_Upgrade'Pos(Module.Upgrade_Action), "upgradeaction",
DataNode);
end if;
case Module.M_Type is
when WORKSHOP =>
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
Set_Attribute
(ModuleDataNode, "value",
To_String(Module.Crafting_Index));
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
SaveNumber(Module.Crafting_Time, "value", ModuleDataNode);
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
SaveNumber(Module.Crafting_Amount, "value", ModuleDataNode);
when TRAINING_ROOM =>
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
SaveNumber(Module.Trained_Skill, "value", ModuleDataNode);
when MEDICAL_ROOM | COCKPIT | ARMOR | ANY | CARGO_ROOM =>
null;
when ENGINE =>
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
SaveNumber(Module.Fuel_Usage, "value", ModuleDataNode);
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
SaveNumber(Module.Power, "value", ModuleDataNode);
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
if Module.Disabled then
Set_Attribute(ModuleDataNode, "value", "1");
else
Set_Attribute(ModuleDataNode, "value", "0");
end if;
when CABIN =>
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
SaveNumber(Module.Cleanliness, "value", ModuleDataNode);
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
SaveNumber(Module.Quality, "value", ModuleDataNode);
when TURRET =>
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
SaveNumber(Module.Gun_Index, "value", ModuleDataNode);
when GUN =>
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
SaveNumber(Module.Ammo_Index, "value", ModuleDataNode);
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
SaveNumber(Module.Damage, "value", ModuleDataNode);
when HULL =>
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
SaveNumber
(Module.Installed_Modules, "value", ModuleDataNode);
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
SaveNumber(Module.Max_Modules, "value", ModuleDataNode);
when BATTERING_RAM =>
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
SaveNumber(Module.Damage2, "value", ModuleDataNode);
when HARPOON_GUN =>
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
SaveNumber(Module.Harpoon_Index, "value", ModuleDataNode);
ModuleDataNode := Create_Element(SaveData, "data");
ModuleDataNode := Append_Child(DataNode, ModuleDataNode);
SaveNumber(Module.Duration, "value", ModuleDataNode);
end case;
end loop Save_Modules_Loop;
end;
Save_Cargo_Loop :
for Item of Player_Ship.Cargo loop
DataNode := Create_Element(SaveData, "cargo");
DataNode := Append_Child(CategoryNode, DataNode);
Set_Attribute(DataNode, "index", To_String(Item.ProtoIndex));
SaveNumber(Item.Amount, "amount", DataNode);
if Item.Name /= Null_Unbounded_String then
Set_Attribute(DataNode, "name", To_String(Item.Name));
end if;
SaveNumber(Item.Durability, "durability", DataNode);
if Item.Price > 0 then
SaveNumber(Item.Price, "price", DataNode);
end if;
end loop Save_Cargo_Loop;
declare
StatNode: DOM.Core.Element;
AttributesNames: constant array(1 .. 14) of Unbounded_String :=
(To_Unbounded_String("health"), To_Unbounded_String("tired"),
To_Unbounded_String("hunger"), To_Unbounded_String("thirst"),
To_Unbounded_String("order"), To_Unbounded_String("previousorder"),
To_Unbounded_String("ordertime"), To_Unbounded_String("dailypay"),
To_Unbounded_String("tradepay"),
To_Unbounded_String("contractlength"),
To_Unbounded_String("moralelevel"),
To_Unbounded_String("moralepoints"),
To_Unbounded_String("loyalty"), To_Unbounded_String("homebase"));
AttributesValues: array(AttributesNames'Range) of Integer;
begin
Save_Crew_Loop :
for Member of Player_Ship.Crew loop
DataNode := Create_Element(SaveData, "member");
DataNode := Append_Child(CategoryNode, DataNode);
Set_Attribute(DataNode, "name", To_String(Member.Name));
Set_Attribute(DataNode, "gender", Member.Gender & "");
Set_Attribute(DataNode, "faction", To_String(Member.Faction));
AttributesValues :=
(Member.Health, Member.Tired, Member.Hunger, Member.Thirst,
Crew_Orders'Pos(Member.Order),
Crew_Orders'Pos(Member.PreviousOrder), Member.OrderTime,
Member.Payment(1), Member.Payment(2), Member.ContractLength,
Member.Morale(1), Member.Morale(2), Member.Loyalty,
Member.HomeBase);
Save_Characteristics_Loop :
for I in AttributesNames'Range loop
SaveNumber
(AttributesValues(I), To_String(AttributesNames(I)),
DataNode);
end loop Save_Characteristics_Loop;
Save_Skills_Loop :
for Skill of Member.Skills loop
StatNode := Create_Element(SaveData, "skill");
StatNode := Append_Child(DataNode, StatNode);
SaveNumber(Skill.Index, "index", StatNode);
SaveNumber(Skill.Level, "level", StatNode);
if Skill.Experience > 0 then
SaveNumber(Skill.Experience, "experience", StatNode);
end if;
end loop Save_Skills_Loop;
Save_Priorities_Loop :
for J in Member.Orders'Range loop
StatNode := Create_Element(SaveData, "priority");
StatNode := Append_Child(DataNode, StatNode);
SaveNumber(Member.Orders(J), "value", StatNode);
end loop Save_Priorities_Loop;
Save_Attributes_Loop :
for Attribute of Member.Attributes loop
StatNode := Create_Element(SaveData, "attribute");
StatNode := Append_Child(DataNode, StatNode);
SaveNumber(Attribute.Level, "level", StatNode);
if Attribute.Experience > 0 then
SaveNumber(Attribute.Experience, "experience", StatNode);
end if;
end loop Save_Attributes_Loop;
Save_Inventory_Loop :
for Item of Member.Inventory loop
StatNode := Create_Element(SaveData, "item");
StatNode := Append_Child(DataNode, StatNode);
Set_Attribute(StatNode, "index", To_String(Item.ProtoIndex));
SaveNumber(Item.Amount, "amount", StatNode);
if Item.Name /= Null_Unbounded_String then
Set_Attribute(StatNode, "name", To_String(Item.Name));
end if;
SaveNumber(Item.Durability, "durability", StatNode);
if Item.Price > 0 then
SaveNumber(Item.Price, "price", StatNode);
end if;
end loop Save_Inventory_Loop;
Save_Equipment_Loop :
for I in Member.Equipment'Range loop
StatNode := Create_Element(SaveData, "equipment");
StatNode := Append_Child(DataNode, StatNode);
SaveNumber(Member.Equipment(I), "index", StatNode);
end loop Save_Equipment_Loop;
end loop Save_Crew_Loop;
end;
end SavePlayerShip;
procedure LoadPlayerShip(SaveData: Document) is
ShipNode, ChildNodes: Node_List;
LoadNode, ChildNode: Node;
begin
ShipNode :=
DOM.Core.Documents.Get_Elements_By_Tag_Name(SaveData, "playership");
LoadNode := Item(ShipNode, 0);
Player_Ship.Name := To_Unbounded_String(Get_Attribute(LoadNode, "name"));
Player_Ship.Sky_X := Integer'Value(Get_Attribute(LoadNode, "x"));
Player_Ship.Sky_Y := Integer'Value(Get_Attribute(LoadNode, "y"));
Player_Ship.Speed :=
Ship_Speed'Val(Integer'Value(Get_Attribute(LoadNode, "speed")));
Player_Ship.Upgrade_Module :=
Integer'Value(Get_Attribute(LoadNode, "upgrademodule"));
Player_Ship.Destination_X :=
Integer'Value(Get_Attribute(LoadNode, "destinationx"));
Player_Ship.Destination_Y :=
Integer'Value(Get_Attribute(LoadNode, "destinationy"));
Player_Ship.Repair_Module :=
Integer'Value(Get_Attribute(LoadNode, "repairpriority"));
Player_Ship.Home_Base :=
Integer'Value(Get_Attribute(LoadNode, "homebase"));
Player_Ship.Modules.Clear;
Player_Ship.Cargo.Clear;
Player_Ship.Crew.Clear;
ChildNodes := Child_Nodes(LoadNode);
Load_Ship_Loop :
for I in 0 .. Length(ChildNodes) - 1 loop
ChildNode := Item(ChildNodes, I);
if Node_Name(ChildNode) = "module" then
declare
ModuleData: Node_List;
Name, ProtoIndex: Unbounded_String;
DataIndex: Positive;
Weight: Natural := 0;
Durability, MaxDurability, UpgradeProgress: Integer := 0;
UpgradeAction: Ship_Upgrade := NONE;
Data: Data_Array;
ModuleNode: Node;
MType: Module_Type_2;
Owners: Natural_Container.Vector;
begin
Name := To_Unbounded_String(Get_Attribute(ChildNode, "name"));
ProtoIndex :=
To_Unbounded_String(Get_Attribute(ChildNode, "index"));
Weight := Natural'Value(Get_Attribute(ChildNode, "weight"));
if Get_Attribute(ChildNode, "owner") /= "" then
Owners.Append
(Natural'Value(Get_Attribute(ChildNode, "owner")));
else
ModuleData := Child_Nodes(ChildNode);
Load_Owners_Loop :
for K in 0 .. Length(ModuleData) - 1 loop
ModuleNode := Item(ModuleData, K);
if Node_Name(ModuleNode) = "owner" then
Owners.Append
(Integer'Value(Get_Attribute(ModuleNode, "value")));
end if;
end loop Load_Owners_Loop;
end if;
Durability :=
Integer'Value(Get_Attribute(ChildNode, "durability"));
MaxDurability :=
Integer'Value(Get_Attribute(ChildNode, "maxdurability"));
if Get_Attribute(ChildNode, "upgradeaction") /= "" then
UpgradeAction :=
Ship_Upgrade'Val
(Integer'Value
(Get_Attribute(ChildNode, "upgradeaction")));
end if;
if Get_Attribute(ChildNode, "upgradeprogress") /= "" then
UpgradeProgress :=
Integer'Value(Get_Attribute(ChildNode, "upgradeprogress"));
end if;
if Get_Attribute(ChildNode, "mtype") /= "" then
case Modules_List(ProtoIndex)
.MType is -- backward compatybility
when MEDICAL_ROOM =>
MType := MEDICAL_ROOM;
when TRAINING_ROOM =>
MType := TRAINING_ROOM;
when ENGINE =>
MType := ENGINE;
when CABIN =>
MType := CABIN;
when COCKPIT =>
MType := COCKPIT;
when TURRET =>
MType := TURRET;
when GUN =>
MType := GUN;
when CARGO =>
MType := CARGO_ROOM;
when HULL =>
MType := HULL;
when ARMOR =>
MType := ARMOR;
when BATTERING_RAM =>
MType := BATTERING_RAM;
when HARPOON_GUN =>
MType := HARPOON_GUN;
when others =>
MType :=
Module_Type_2'Value
(Get_Attribute(ChildNode, "mtype"));
end case;
else
case Modules_List(ProtoIndex).MType is
when ALCHEMY_LAB .. GREENHOUSE =>
MType := WORKSHOP;
when MEDICAL_ROOM =>
MType := MEDICAL_ROOM;
when TRAINING_ROOM =>
MType := TRAINING_ROOM;
when ENGINE =>
MType := ENGINE;
when CABIN =>
MType := CABIN;
when COCKPIT =>
MType := COCKPIT;
when TURRET =>
MType := TURRET;
when GUN =>
MType := GUN;
when CARGO =>
MType := CARGO_ROOM;
when HULL =>
MType := HULL;
when ARMOR =>
MType := ARMOR;
when BATTERING_RAM =>
MType := BATTERING_RAM;
when HARPOON_GUN =>
MType := HARPOON_GUN;
when others =>
MType := ANY;
end case;
end if;
case MType is
when ANY =>
Data := (others => 0);
ModuleData := Child_Nodes(ChildNode);
DataIndex := 1;
Load_Module_Data_Loop :
for K in 0 .. Length(ModuleData) - 1 loop
ModuleNode := Item(ModuleData, K);
if Node_Name(ModuleNode) = "data" then
Data(DataIndex) :=
Integer'Value(Get_Attribute(ModuleNode, "value"));
DataIndex := DataIndex + 1;
end if;
end loop Load_Module_Data_Loop;
Player_Ship.Modules.Append
(New_Item =>
(M_Type => ANY, Name => Name,
Proto_Index => ProtoIndex, Weight => Weight,
Durability => Durability,
Max_Durability => MaxDurability, Owner => Owners,
Upgrade_Progress => UpgradeProgress,
Upgrade_Action => UpgradeAction, Data => Data));
when ENGINE =>
declare
FuelUsage, Power: Positive;
Disabled: Boolean;
begin
ModuleData := Child_Nodes(ChildNode);
DataIndex := 1;
Load_Engine_Data_Loop :
for K in 0 .. Length(ModuleData) - 1 loop
ModuleNode := Item(ModuleData, K);
if Node_Name(ModuleNode) = "data" then
case DataIndex is
when 1 =>
FuelUsage :=
Integer'Value
(Get_Attribute(ModuleNode, "value"));
when 2 =>
Power :=
Integer'Value
(Get_Attribute(ModuleNode, "value"));
when 3 =>
if Get_Attribute(ModuleNode, "value") =
"0" then
Disabled := False;
else
Disabled := True;
end if;
when others =>
null;
end case;
DataIndex := DataIndex + 1;
end if;
end loop Load_Engine_Data_Loop;
Player_Ship.Modules.Append
(New_Item =>
(M_Type => ENGINE, Name => Name,
Proto_Index => ProtoIndex, Weight => Weight,
Durability => Durability,
Max_Durability => MaxDurability, Owner => Owners,
Upgrade_Progress => UpgradeProgress,
Upgrade_Action => UpgradeAction,
Fuel_Usage => FuelUsage, Power => Power,
Disabled => Disabled));
end;
when CABIN =>
declare
Cleanliness, Quality: Natural;
begin
ModuleData := Child_Nodes(ChildNode);
DataIndex := 1;
Load_Cabin_Data_Loop :
for K in 0 .. Length(ModuleData) - 1 loop
ModuleNode := Item(ModuleData, K);
if Node_Name(ModuleNode) = "data" then
case DataIndex is
when 1 =>
Cleanliness :=
Integer'Value
(Get_Attribute(ModuleNode, "value"));
when 2 =>
Quality :=
Integer'Value
(Get_Attribute(ModuleNode, "value"));
when others =>
null;
end case;
DataIndex := DataIndex + 1;
end if;
end loop Load_Cabin_Data_Loop;
Player_Ship.Modules.Append
(New_Item =>
(M_Type => CABIN, Name => Name,
Proto_Index => ProtoIndex, Weight => Weight,
Durability => Durability,
Max_Durability => MaxDurability, Owner => Owners,
Upgrade_Progress => UpgradeProgress,
Upgrade_Action => UpgradeAction,
Cleanliness => Cleanliness, Quality => Quality));
end;
when COCKPIT =>
Player_Ship.Modules.Append
(New_Item =>
(M_Type => COCKPIT, Name => Name,
Proto_Index => ProtoIndex, Weight => Weight,
Durability => Durability,
Max_Durability => MaxDurability, Owner => Owners,
Upgrade_Progress => UpgradeProgress,
Upgrade_Action => UpgradeAction));
when WORKSHOP =>
declare
CraftingIndex: Unbounded_String;
CraftingTime, CraftingAmount: Natural;
begin
ModuleData := Child_Nodes(ChildNode);
DataIndex := 1;
Load_Workshop_Data_Loop :
for K in 0 .. Length(ModuleData) - 1 loop
ModuleNode := Item(ModuleData, K);
if Node_Name(ModuleNode) = "data" then
case DataIndex is
when 1 =>
CraftingIndex :=
To_Unbounded_String
(Get_Attribute(ModuleNode, "value"));
if CraftingIndex =
To_Unbounded_String("0") then
CraftingIndex := Null_Unbounded_String;
end if;
when 2 =>
CraftingTime :=
Integer'Value
(Get_Attribute(ModuleNode, "value"));
when 3 =>
CraftingAmount :=
Integer'Value
(Get_Attribute(ModuleNode, "value"));
when others =>
null;
end case;
DataIndex := DataIndex + 1;
end if;
end loop Load_Workshop_Data_Loop;
Player_Ship.Modules.Append
(New_Item =>
(M_Type => WORKSHOP, Name => Name,
Proto_Index => ProtoIndex, Weight => Weight,
Durability => Durability,
Max_Durability => MaxDurability, Owner => Owners,
Upgrade_Progress => UpgradeProgress,
Upgrade_Action => UpgradeAction,
Crafting_Index => CraftingIndex,
Crafting_Time => CraftingTime,
Crafting_Amount => CraftingAmount));
end;
when MEDICAL_ROOM =>
Player_Ship.Modules.Append
(New_Item =>
(M_Type => MEDICAL_ROOM, Name => Name,
Proto_Index => ProtoIndex, Weight => Weight,
Durability => Durability,
Max_Durability => MaxDurability, Owner => Owners,
Upgrade_Progress => UpgradeProgress,
Upgrade_Action => UpgradeAction));
when TRAINING_ROOM =>
declare
TrainedSkill: Natural;
begin
ModuleData := Child_Nodes(ChildNode);
DataIndex := 1;
Load_Training_Room_Data_Loop :
for K in 0 .. Length(ModuleData) - 1 loop
ModuleNode := Item(ModuleData, K);
if Node_Name(ModuleNode) = "data" and
DataIndex = 1 then
TrainedSkill :=
Integer'Value
(Get_Attribute(ModuleNode, "value"));
DataIndex := DataIndex + 1;
end if;
end loop Load_Training_Room_Data_Loop;
Player_Ship.Modules.Append
(New_Item =>
(M_Type => TRAINING_ROOM, Name => Name,
Proto_Index => ProtoIndex, Weight => Weight,
Durability => Durability,
Max_Durability => MaxDurability, Owner => Owners,
Upgrade_Progress => UpgradeProgress,
Upgrade_Action => UpgradeAction,
Trained_Skill => TrainedSkill));
end;
when TURRET =>
declare
GunIndex: Natural;
begin
ModuleData := Child_Nodes(ChildNode);
DataIndex := 1;
Load_Turret_Data_Loop :
for K in 0 .. Length(ModuleData) - 1 loop
ModuleNode := Item(ModuleData, K);
if Node_Name(ModuleNode) = "data" and
DataIndex = 1 then
GunIndex :=
Integer'Value
(Get_Attribute(ModuleNode, "value"));
DataIndex := DataIndex + 1;
end if;
end loop Load_Turret_Data_Loop;
Player_Ship.Modules.Append
(New_Item =>
(M_Type => TURRET, Name => Name,
Proto_Index => ProtoIndex, Weight => Weight,
Durability => Durability,
Max_Durability => MaxDurability, Owner => Owners,
Upgrade_Progress => UpgradeProgress,
Upgrade_Action => UpgradeAction,
Gun_Index => GunIndex));
end;
when GUN =>
declare
Damage, AmmoIndex: Natural;
begin
ModuleData := Child_Nodes(ChildNode);
DataIndex := 1;
Load_Gun_Data_Loop :
for K in 0 .. Length(ModuleData) - 1 loop
ModuleNode := Item(ModuleData, K);
if Node_Name(ModuleNode) = "data" then
case DataIndex is
when 1 =>
AmmoIndex :=
Integer'Value
(Get_Attribute(ModuleNode, "value"));
when 2 =>
Damage :=
Integer'Value
(Get_Attribute(ModuleNode, "value"));
when others =>
null;
end case;
DataIndex := DataIndex + 1;
end if;
end loop Load_Gun_Data_Loop;
Player_Ship.Modules.Append
(New_Item =>
(M_Type => GUN, Name => Name,
Proto_Index => ProtoIndex, Weight => Weight,
Durability => Durability,
Max_Durability => MaxDurability, Owner => Owners,
Upgrade_Progress => UpgradeProgress,
Upgrade_Action => UpgradeAction,
Damage => Damage, Ammo_Index => AmmoIndex));
end;
when CARGO_ROOM =>
Player_Ship.Modules.Append
(New_Item =>
(M_Type => CARGO_ROOM, Name => Name,
Proto_Index => ProtoIndex, Weight => Weight,
Durability => Durability,
Max_Durability => MaxDurability, Owner => Owners,
Upgrade_Progress => UpgradeProgress,
Upgrade_Action => UpgradeAction));
when HULL =>
declare
InstalledModules, MaxModules: Natural;
begin
ModuleData := Child_Nodes(ChildNode);
DataIndex := 1;
Load_Hull_Data_Loop :
for K in 0 .. Length(ModuleData) - 1 loop
ModuleNode := Item(ModuleData, K);
if Node_Name(ModuleNode) = "data" then
case DataIndex is
when 1 =>
InstalledModules :=
Integer'Value
(Get_Attribute(ModuleNode, "value"));
when 2 =>
MaxModules :=
Integer'Value
(Get_Attribute(ModuleNode, "value"));
when others =>
null;
end case;
DataIndex := DataIndex + 1;
end if;
end loop Load_Hull_Data_Loop;
Player_Ship.Modules.Append
(New_Item =>
(M_Type => HULL, Name => Name,
Proto_Index => ProtoIndex, Weight => Weight,
Durability => Durability,
Max_Durability => MaxDurability, Owner => Owners,
Upgrade_Progress => UpgradeProgress,
Upgrade_Action => UpgradeAction,
Installed_Modules => InstalledModules,
Max_Modules => MaxModules));
end;
when ARMOR =>
Player_Ship.Modules.Append
(New_Item =>
(M_Type => ARMOR, Name => Name,
Proto_Index => ProtoIndex, Weight => Weight,
Durability => Durability,
Max_Durability => MaxDurability, Owner => Owners,
Upgrade_Progress => UpgradeProgress,
Upgrade_Action => UpgradeAction));
when BATTERING_RAM =>
declare
Damage: Natural;
begin
ModuleData := Child_Nodes(ChildNode);
DataIndex := 1;
Load_Battering_Ram_Data_Loop :
for K in 0 .. Length(ModuleData) - 1 loop
ModuleNode := Item(ModuleData, K);
if Node_Name(ModuleNode) = "data" and
DataIndex = 1 then
Damage :=
Integer'Value
(Get_Attribute(ModuleNode, "value"));
DataIndex := DataIndex + 1;
end if;
end loop Load_Battering_Ram_Data_Loop;
Player_Ship.Modules.Append
(New_Item =>
(M_Type => BATTERING_RAM, Name => Name,
Proto_Index => ProtoIndex, Weight => Weight,
Durability => Durability,
Max_Durability => MaxDurability, Owner => Owners,
Upgrade_Progress => UpgradeProgress,
Upgrade_Action => UpgradeAction,
Damage2 => Damage, Cooling_Down => False));
end;
when HARPOON_GUN =>
declare
Duration, HarpoonIndex: Natural;
begin
ModuleData := Child_Nodes(ChildNode);
DataIndex := 1;
Load_Harpoon_Gun_Data_Loop :
for K in 0 .. Length(ModuleData) - 1 loop
ModuleNode := Item(ModuleData, K);
if Node_Name(ModuleNode) = "data" then
case DataIndex is
when 1 =>
HarpoonIndex :=
Integer'Value
(Get_Attribute(ModuleNode, "value"));
when 2 =>
Duration :=
Integer'Value
(Get_Attribute(ModuleNode, "value"));
when others =>
null;
end case;
DataIndex := DataIndex + 1;
end if;
end loop Load_Harpoon_Gun_Data_Loop;
Player_Ship.Modules.Append
(New_Item =>
(M_Type => HARPOON_GUN, Name => Name,
Proto_Index => ProtoIndex, Weight => Weight,
Durability => Durability,
Max_Durability => MaxDurability, Owner => Owners,
Upgrade_Progress => UpgradeProgress,
Upgrade_Action => UpgradeAction,
Duration => Duration,
Harpoon_Index => HarpoonIndex));
end;
end case;
end;
elsif Node_Name(ChildNode) = "cargo" then
declare
Amount: Positive;
Name, ProtoIndex: Unbounded_String;
Durability, Price: Natural;
begin
ProtoIndex :=
To_Unbounded_String(Get_Attribute(ChildNode, "index"));
Amount := Positive'Value(Get_Attribute(ChildNode, "amount"));
Name := To_Unbounded_String(Get_Attribute(ChildNode, "name"));
Durability :=
Natural'Value(Get_Attribute(ChildNode, "durability"));
Price :=
(if Get_Attribute(ChildNode, "price")'Length > 0 then
Natural'Value(Get_Attribute(ChildNode, "price"))
else 0);
Player_Ship.Cargo.Append
(New_Item =>
(ProtoIndex => ProtoIndex, Amount => Amount, Name => Name,
Durability => Durability, Price => Price));
end;
elsif Node_Name(ChildNode) = "member" then
declare
MemberData: Node_List;
Name, ItemName, FactionIndex, ItemIndex: Unbounded_String;
Gender: String(1 .. 1);
Health, Tired, Hunger, Thirst, Index, Level, Experience,
Loyalty, Price: Natural;
Skills: Skills_Container.Vector;
Attributes: Mob_Attributes
(1 ..
Positive
(AttributesData_Container.Length
(Container => Attributes_List)));
Order, PreviousOrder: Crew_Orders;
Orders: Natural_Array(1 .. 12);
Inventory: Inventory_Container.Vector;
Equipment: Equipment_Array;
OrderTime, ContractLength: Integer;
Amount, Durability, EquipmentIndex, PriorityIndex,
HomeBase: Positive;
Payment, Morale: Attributes_Array;
MemberNode: Node;
Attribute_Index: Positive := 1;
begin
Skills.Clear;
Attributes := (others => <>);
Inventory.Clear;
Name := To_Unbounded_String(Get_Attribute(ChildNode, "name"));
Gender := Get_Attribute(ChildNode, "gender");
Health := Integer'Value(Get_Attribute(ChildNode, "health"));
Tired := Integer'Value(Get_Attribute(ChildNode, "tired"));
Hunger := Integer'Value(Get_Attribute(ChildNode, "hunger"));
Thirst := Integer'Value(Get_Attribute(ChildNode, "thirst"));
Order :=
Crew_Orders'Val
(Integer'Value(Get_Attribute(ChildNode, "order")));
PreviousOrder :=
Crew_Orders'Val
(Integer'Value(Get_Attribute(ChildNode, "previousorder")));
Orders := (others => 0);
Equipment := (others => 0);
OrderTime :=
Integer'Value(Get_Attribute(ChildNode, "ordertime"));
EquipmentIndex := 1;
MemberData := Child_Nodes(ChildNode);
PriorityIndex := 1;
Payment(1) :=
Natural'Value(Get_Attribute(ChildNode, "dailypay"));
Payment(2) :=
Natural'Value(Get_Attribute(ChildNode, "tradepay"));
ContractLength :=
Integer'Value(Get_Attribute(ChildNode, "contractlength"));
Morale(1) :=
Natural'Value(Get_Attribute(ChildNode, "moralelevel"));
Morale(2) :=
Natural'Value(Get_Attribute(ChildNode, "moralepoints"));
Loyalty := Natural'Value(Get_Attribute(ChildNode, "loyalty"));
Load_Crew_Loop :
for K in 0 .. Length(MemberData) - 1 loop
MemberNode := Item(MemberData, K);
if Node_Name(MemberNode) = "skill" then
Index :=
Integer'Value(Get_Attribute(MemberNode, "index"));
Level :=
Integer'Value(Get_Attribute(MemberNode, "level"));
Experience :=
(if Get_Attribute(MemberNode, "experience") /= "" then
Integer'Value
(Get_Attribute(MemberNode, "experience"))
else 0);
Skills.Append(New_Item => (Index, Level, Experience));
elsif Node_Name(MemberNode) = "priority" then
Orders(PriorityIndex) :=
Integer'Value(Get_Attribute(MemberNode, "value"));
PriorityIndex := PriorityIndex + 1;
elsif Node_Name(MemberNode) = "attribute" then
Level :=
Integer'Value(Get_Attribute(MemberNode, "level"));
Experience :=
(if Get_Attribute(MemberNode, "experience") /= "" then
Integer'Value
(Get_Attribute(MemberNode, "experience"))
else 0);
Attributes(Attribute_Index) := (Level, Experience);
Attribute_Index := Attribute_Index + 1;
elsif Node_Name(MemberNode) = "item" then
ItemIndex :=
To_Unbounded_String(Get_Attribute(MemberNode, "index"));
Amount :=
Integer'Value(Get_Attribute(MemberNode, "amount"));
ItemName :=
To_Unbounded_String(Get_Attribute(MemberNode, "name"));
Durability :=
Integer'Value(Get_Attribute(MemberNode, "durability"));
Price :=
(if Get_Attribute(MemberNode, "price")'Length > 0 then
Integer'Value(Get_Attribute(MemberNode, "price"))
else 0);
Inventory.Append
(New_Item =>
(ProtoIndex => ItemIndex, Amount => Amount,
Name => ItemName, Durability => Durability,
Price => Price));
elsif Node_Name(MemberNode) = "equipment" then
Equipment(EquipmentIndex) :=
Natural'Value(Get_Attribute(MemberNode, "index"));
EquipmentIndex := EquipmentIndex + 1;
end if;
end loop Load_Crew_Loop;
HomeBase :=
(if Get_Attribute(ChildNode, "homebase") /= "" then
Natural'Value(Get_Attribute(ChildNode, "homebase"))
else Player_Ship.Home_Base);
FactionIndex :=
(if Get_Attribute(ChildNode, "faction") /= "" then
To_Unbounded_String(Get_Attribute(ChildNode, "faction"))
else Sky_Bases(HomeBase).Owner);
Player_Ship.Crew.Append
(New_Item =>
(Amount_Of_Attributes => Attributes_Amount,
Amount_Of_Skills => Skills_Amount, Name => Name,
Gender => Gender(1), Health => Health, Tired => Tired,
Skills => Skills, Hunger => Hunger, Thirst => Thirst,
Order => Order, PreviousOrder => PreviousOrder,
OrderTime => OrderTime, Orders => Orders,
Attributes => Attributes, Inventory => Inventory,
Equipment => Equipment, Payment => Payment,
ContractLength => ContractLength, Morale => Morale,
Loyalty => Loyalty, HomeBase => HomeBase,
Faction => FactionIndex));
end;
end if;
end loop Load_Ship_Loop;
end LoadPlayerShip;
end Ships.SaveLoad;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with AMF.Internals.Elements;
with AMF.Internals.Extents;
with AMF.Internals.Factories;
with AMF.Internals.Helpers;
with AMF.Internals.Links;
package body AMF.Internals.AMF_URI_Stores is
-----------------------
-- Convert_To_String --
-----------------------
overriding function Convert_To_String
(Self : not null access AMF_URI_Store;
Data_Type : not null access AMF.CMOF.Data_Types.CMOF_Data_Type'Class;
Value : League.Holders.Holder)
return League.Strings.Universal_String
is
The_Package : constant AMF.CMOF.Packages.CMOF_Package_Access
:= Data_Type.Get_Package;
begin
return
Self.Get_Factory
(The_Package.Get_URI.Value).Convert_To_String (Data_Type, Value);
end Convert_To_String;
------------
-- Create --
------------
overriding function Create
(Self : not null access AMF_URI_Store;
Meta_Class : not null access AMF.CMOF.Classes.CMOF_Class'Class)
return not null AMF.Elements.Element_Access
is
The_Package : constant AMF.CMOF.Packages.CMOF_Package_Access
:= Meta_Class.Get_Package;
begin
return Self.Get_Factory (The_Package.Get_URI.Value).Create (Meta_Class);
end Create;
------------------------
-- Create_From_String --
------------------------
overriding function Create_From_String
(Self : not null access AMF_URI_Store;
Data_Type : not null access AMF.CMOF.Data_Types.CMOF_Data_Type'Class;
Image : League.Strings.Universal_String)
return League.Holders.Holder
is
The_Package : constant AMF.CMOF.Packages.CMOF_Package_Access
:= Data_Type.Get_Package;
begin
return
Self.Get_Factory
(The_Package.Get_URI.Value).Create_From_String (Data_Type, Image);
end Create_From_String;
-----------------
-- Create_Link --
-----------------
overriding function Create_Link
(Self : not null access AMF_URI_Store;
Association :
not null access AMF.CMOF.Associations.CMOF_Association'Class;
First_Element : not null AMF.Elements.Element_Access;
Second_Element : not null AMF.Elements.Element_Access)
return not null AMF.Links.Link_Access
is
pragma Unreferenced (Self);
begin
return
AMF.Internals.Links.Proxy
(AMF.Internals.Links.Create_Link
(AMF.Internals.Elements.Element_Base'Class
(Association.all).Element,
AMF.Internals.Helpers.To_Element (First_Element),
AMF.Internals.Helpers.To_Element (Second_Element)));
end Create_Link;
-----------------
-- Get_Factory --
-----------------
overriding function Get_Factory
(Self : not null access AMF_URI_Store;
Metamodel_URI : League.Strings.Universal_String)
return AMF.Factories.Factory_Access
is
use type AMF.Factories.Factory_Access;
Position : constant String_Factory_Maps.Cursor
:= Self.Factories.Find (Metamodel_URI);
Factory : AMF.Factories.Factory_Access;
begin
-- Lookup factory in the map.
if String_Factory_Maps.Has_Element (Position) then
return String_Factory_Maps.Element (Position);
end if;
-- Create factory.
Factory :=
AMF.Internals.Factories.Create_Factory (Metamodel_URI, Self.Id);
if Factory /= null then
-- If factory is created register mapping of all its packages.
declare
Packages :
constant AMF.CMOF.Packages.Collections.Set_Of_CMOF_Package
:= Factory.Get_Package;
begin
for J in 1 .. Packages.Length loop
Self.Factories.Insert
(Packages.Element (J).Get_URI.Value, Factory);
end loop;
end;
end if;
return Factory;
end Get_Factory;
------------
-- Get_Id --
------------
overriding function Get_Id
(Self : not null access AMF_URI_Store;
Element : not null AMF.Elements.Element_Access)
return League.Strings.Universal_String is
begin
return
AMF.Internals.Extents.Get_Id
(Self.Id, AMF.Internals.Helpers.To_Element (Element));
end Get_Id;
-----------------
-- Get_Package --
-----------------
overriding function Get_Package
(Self : not null access constant AMF_URI_Store)
return AMF.CMOF.Packages.Collections.Set_Of_CMOF_Package
is
pragma Unreferenced (Self);
begin
return AMF.Internals.Factories.Get_Packages;
end Get_Package;
------------
-- Set_Id --
------------
overriding procedure Set_Id
(Self : not null access AMF_URI_Store;
Element : not null AMF.Elements.Element_Access;
Id : League.Strings.Universal_String) is
begin
AMF.Internals.Extents.Set_Id
(Self.Id, AMF.Internals.Helpers.To_Element (Element), Id);
end Set_Id;
end AMF.Internals.AMF_URI_Stores;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2014-2015, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Ada.Containers.Hashed_Maps;
with League.String_Vectors;
with League.Strings.Hash;
with Matreshka.Servlet_HTTP_Requests;
with Matreshka.Servlet_Registrations;
package Matreshka.Servlet_Dispatchers is
type Abstract_Dispatcher is limited interface;
type Dispatcher_Access is access all Abstract_Dispatcher'Class;
not overriding procedure Dispatch
(Self : not null access constant Abstract_Dispatcher;
Request : in out
Matreshka.Servlet_HTTP_Requests.Abstract_HTTP_Servlet_Request'Class;
Path : League.String_Vectors.Universal_String_Vector;
Index : Positive;
Servlet : in out
Matreshka.Servlet_Registrations.Servlet_Registration_Access)
is abstract;
-- Dispatches request. Path is full path and Index is segment of path that
-- must be dispatched by the current dispatcher. Servlet parameter is set
-- to servlet registration to process request. Request parameter is
-- modified by setting of indices of context/servlet/path segments.
type Context_Dispatcher is limited new Abstract_Dispatcher with private;
procedure Add_Mapping
(Self : not null access Context_Dispatcher'Class;
Servlet :
not null Matreshka.Servlet_Registrations.Servlet_Registration_Access;
URL_Pattern : League.Strings.Universal_String;
Success : out Boolean);
-- Adds mapping by parsing given URL_Pattern. Sets Success to True when
-- mapping is added successfully. Sets Success to False when mapping is
-- exists.
private
package Dispatcher_Maps is
new Ada.Containers.Hashed_Maps
(League.Strings.Universal_String,
Dispatcher_Access,
League.Strings.Hash,
League.Strings."=");
------------------------
-- Segment_Dispatcher --
------------------------
-- Segment dispatcher dispatches request to one of children segments of
-- path.
type Segment_Dispatcher is limited new Abstract_Dispatcher with record
Children : Dispatcher_Maps.Map;
end record;
overriding procedure Dispatch
(Self : not null access constant Segment_Dispatcher;
Request : in out
Matreshka.Servlet_HTTP_Requests.Abstract_HTTP_Servlet_Request'Class;
Path : League.String_Vectors.Universal_String_Vector;
Index : Positive;
Servlet : in out
Matreshka.Servlet_Registrations.Servlet_Registration_Access);
------------------------
-- Servlet_Dispatcher --
------------------------
-- Servlet dispatcher dispatches request to servlet checking for exact and
-- longest path-prefix mappings.
type Servlet_Dispatcher is new Segment_Dispatcher with record
Exact_Servlet :
Matreshka.Servlet_Registrations.Servlet_Registration_Access;
Mapping_Servlet :
Matreshka.Servlet_Registrations.Servlet_Registration_Access;
end record;
overriding procedure Dispatch
(Self : not null access constant Servlet_Dispatcher;
Request : in out
Matreshka.Servlet_HTTP_Requests.Abstract_HTTP_Servlet_Request'Class;
Path : League.String_Vectors.Universal_String_Vector;
Index : Positive;
Servlet : in out
Matreshka.Servlet_Registrations.Servlet_Registration_Access);
------------------------
-- Context_Dispatcher --
------------------------
package Extension_Maps is
new Ada.Containers.Hashed_Maps
(League.Strings.Universal_String,
Matreshka.Servlet_Registrations.Servlet_Registration_Access,
League.Strings.Hash,
League.Strings."=",
Matreshka.Servlet_Registrations."=");
type Context_Dispatcher is limited new Segment_Dispatcher with record
Root_Servlet :
Matreshka.Servlet_Registrations.Servlet_Registration_Access;
Default_Servlet :
Matreshka.Servlet_Registrations.Servlet_Registration_Access;
Extension_Servlets : Extension_Maps.Map;
end record;
overriding procedure Dispatch
(Self : not null access constant Context_Dispatcher;
Request : in out
Matreshka.Servlet_HTTP_Requests.Abstract_HTTP_Servlet_Request'Class;
Path : League.String_Vectors.Universal_String_Vector;
Index : Positive;
Servlet : in out
Matreshka.Servlet_Registrations.Servlet_Registration_Access);
end Matreshka.Servlet_Dispatchers;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.