commit
stringlengths 40
40
| old_file
stringlengths 2
205
| new_file
stringlengths 2
205
| old_contents
stringlengths 0
32.9k
| new_contents
stringlengths 1
38.9k
| subject
stringlengths 3
9.4k
| message
stringlengths 6
9.84k
| lang
stringlengths 3
13
| license
stringclasses 13
values | repos
stringlengths 6
115k
|
---|---|---|---|---|---|---|---|---|---|
d9519c302f28ffa2c155498a5540fca212cae8af
|
src/util-properties-bundles.adb
|
src/util-properties-bundles.adb
|
-----------------------------------------------------------------------
-- properties -- Generic name/value property management
-- Copyright (C) 2001, 2002, 2003, 2006, 2008, 2009, 2010, 2011 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Unchecked_Deallocation;
with Ada.Unchecked_Conversion;
with Ada.Directories;
with Ada.Containers.Vectors;
with Ada.Strings.Fixed;
with Util.Log.Loggers;
with Util.Files;
with Util.Strings.Maps;
package body Util.Properties.Bundles is
use Util.Log;
Log : constant Loggers.Logger := Loggers.Create ("Util.Properties.Bundles");
procedure Free is
new Ada.Unchecked_Deallocation (Manager'Class,
Bundle_Manager_Access);
-- Implementation of the Bundle
-- (this allows to decouples the implementation from the API)
package Interface_P is
type Manager is new Util.Properties.Interface_P.Manager with private;
type Manager_Object_Access is access all Manager;
-- Returns TRUE if the property exists.
function Exists (Self : in Manager; Name : in Value)
return Boolean;
-- Returns the property value. Raises an exception if not found.
function Get (Self : in Manager; Name : in Value)
return Value;
procedure Insert (Self : in out Manager; Name : in Value;
Item : in Value);
-- Set the value of the property. The property is created if it
-- does not exists.
procedure Set (Self : in out Manager; Name : in Value;
Item : in Value);
-- Remove the property given its name.
procedure Remove (Self : in out Manager; Name : in Value);
-- Iterate over the properties and execute the given procedure passing the
-- property name and its value.
procedure Iterate (Self : in Manager;
Process : access procedure (Name, Item : Value));
procedure Load_Properties (Self : in out Manager;
File : in String);
-- Deep copy of properties stored in 'From' to 'To'.
function Create_Copy (Self : in Manager)
return Util.Properties.Interface_P.Manager_Access;
procedure Delete (Self : in Manager;
Obj : in out Util.Properties.Interface_P.Manager_Access);
function Get_Names (Self : in Manager;
Prefix : in String) return Name_Array;
procedure Add_Bundle (Self : in out Manager;
Props : in Util.Properties.Manager_Access);
private
use type Util.Properties.Manager_Access;
package PropertyList is new Ada.Containers.Vectors
(Element_Type => Util.Properties.Manager_Access,
Index_Type => Natural,
"=" => "=");
type Manager is new Util.Properties.Interface_P.Manager with record
List : PropertyList.Vector;
Props : aliased Util.Properties.Manager;
end record;
procedure Free is
new Ada.Unchecked_Deallocation (Manager,
Manager_Object_Access);
end Interface_P;
procedure Add_Bundle (Self : in out Manager;
Props : in Manager_Access) is
use type Util.Properties.Interface_P.Manager_Access;
begin
Interface_P.Manager'Class (Self.Impl.all).Add_Bundle (Props);
end Add_Bundle;
procedure Initialize (Object : in out Manager) is
use Util.Properties.Interface_P;
begin
Object.Impl := new Util.Properties.Bundles.Interface_P.Manager;
Object.Impl.Count := 1;
end Initialize;
procedure Adjust (Object : in out Manager) is
use Util.Properties.Interface_P;
begin
if Object.Impl /= null then
Object.Impl.Count := Object.Impl.Count + 1;
else
Object.Impl := new Util.Properties.Bundles.Interface_P.Manager;
Object.Impl.Count := 1;
end if;
end Adjust;
-- ------------------------------
-- Initialize the bundle factory and specify where the property files are stored.
-- ------------------------------
procedure Initialize (Factory : in out Loader;
Path : in String) is
begin
Log.Info ("Initialize bundle factory to load from {0}", Path);
Factory.Path := To_Unbounded_String (Path);
end Initialize;
-- ------------------------------
-- Load the bundle with the given name and for the given locale name.
-- ------------------------------
procedure Load_Bundle (Factory : in out Loader;
Name : in String;
Locale : in String;
Bundle : out Manager'Class) is
Found : Boolean := False;
begin
Log.Info ("Load bundle {0} for language {1}", Name, Locale);
Find_Bundle (Factory, Name, Locale, Bundle, Found);
if not Found then
Load_Bundle (Factory, Name, Found);
if not Found then
Log.Error ("Bundle {0} not found", Name);
raise NO_BUNDLE with "No bundle '" & Name & "'";
end if;
Find_Bundle (Factory, Name, Locale, Bundle, Found);
if not Found then
Log.Error ("Bundle {0} not found", Name);
raise NO_BUNDLE with "No bundle '" & Name & "'";
end if;
end if;
end Load_Bundle;
-- ------------------------------
-- Find the bundle with the given name and for the given locale name.
-- ------------------------------
procedure Find_Bundle (Factory : in out Loader;
Name : in String;
Locale : in String;
Bundle : out Manager'Class;
Found : out Boolean) is
use Ada.Strings;
use type Util.Properties.Manager_Access;
Loc_Name : constant String := '_' & Locale;
Last_Pos : Integer := Loc_Name'Last;
begin
Log.Info ("Looking for bundle {0} and language {1}", Name, Locale);
Found := False;
Factory.Lock.Read;
declare
Pos : Bundle_Map.Cursor;
begin
while Last_Pos + 1 >= Loc_Name'First loop
declare
Bundle_Name : aliased constant String
:= Name & Loc_Name (Loc_Name'First .. Last_Pos);
begin
Log.Debug ("Searching for {0}", Bundle_Name);
Pos := Factory.Bundles.Find (Bundle_Name'Unrestricted_Access);
if Bundle_Map.Has_Element (Pos) then
Bundle.Finalize;
Bundle.Impl := Bundle_Map.Element (Pos).Impl;
Bundle.Impl.Count := Bundle.Impl.Count + 1;
Found := True;
exit;
end if;
end;
if Last_Pos > Loc_Name'First then
Last_Pos := Fixed.Index (Loc_Name, "_", Last_Pos - 1, Backward) - 1;
else
Last_Pos := Last_Pos - 1;
end if;
end loop;
exception
when others =>
Factory.Lock.Release_Read;
raise;
end;
Factory.Lock.Release_Read;
end Find_Bundle;
-- ------------------------------
-- Load the bundle with the given name and for the given locale name.
-- ------------------------------
procedure Load_Bundle (Factory : in out Loader;
Name : in String;
Found : out Boolean) is
use Ada.Directories;
use Ada.Strings;
use Util.Strings;
use Ada.Containers;
use Util.Strings.String_Set;
use Bundle_Map;
procedure Process_File (Name : in String;
File_Path : in String);
Path : constant String := To_String (Factory.Path);
Pattern : constant String := Name & "*.properties";
Names : Util.Strings.String_Set.Set;
Files : Util.Strings.Maps.Map;
Iter : Util.Strings.Maps.Cursor;
procedure Process_File (Name : in String;
File_Path : in String) is
Bundle : constant Bundle_Manager_Access := new Manager;
Bundle_Name : constant Name_Access
:= new String '(Name (Name'First .. Name'Last - 11));
begin
Log.Debug ("Loading file {0}", File_Path);
Interface_P.Manager'Class (Bundle.Impl.all).Load_Properties (File_Path);
Factory.Bundles.Include (Key => Bundle_Name, New_Item => Bundle);
Found := True;
Names.Insert (Bundle_Name);
end Process_File;
begin
Log.Info ("Reading bundle {1} in directory {0}", Path, Name);
Found := False;
Util.Files.Find_Files_Path (Pattern => Pattern,
Path => Path,
Into => Files);
Factory.Lock.Write;
begin
Iter := Files.First;
while Util.Strings.Maps.Has_Element (Iter) loop
Util.Strings.Maps.Query_Element (Iter, Process_File'Access);
Util.Strings.Maps.Next (Iter);
end loop;
-- Link the property files to implement the localization default rules.
while Names.Length > 0 loop
declare
Name_Pos : String_Set.Cursor := Names.First;
Bundle_Name : constant Name_Access := String_Set.Element (Name_Pos);
Idx : Natural := Fixed.Index (Bundle_Name.all, "_", Backward);
Bundle_Pos : constant Bundle_Map.Cursor := Factory.Bundles.Find (Bundle_Name);
Bundle : constant Bundle_Manager_Access := Element (Bundle_Pos);
begin
Names.Delete (Name_Pos);
-- Associate the property bundle to the first existing parent
-- Ex: message_fr_CA -> message_fr
-- message_fr_CA -> message
while Idx > 0 loop
declare
Name : aliased constant String
:= Bundle_Name (Bundle_Name'First .. Idx - 1);
Pos : constant Bundle_Map.Cursor
:= Factory.Bundles.Find (Name'Unchecked_Access);
begin
if Bundle_Map.Has_Element (Pos) then
Bundle.Add_Bundle (Bundle_Map.Element (Pos).all'Access);
Idx := 0;
else
Idx := Fixed.Index (Bundle_Name.all, "_", Idx - 1, Backward);
end if;
end;
end loop;
end;
end loop;
exception
when others =>
Factory.Lock.Release_Write;
raise;
end;
Factory.Lock.Release_Write;
exception
when Name_Error =>
Log.Error ("Cannot read directory: {0}", Path);
end Load_Bundle;
-- Implementation of the Bundle
-- (this allows to decouples the implementation from the API)
package body Interface_P is
use PropertyList;
-- ------------------------------
-- Returns TRUE if the property exists.
-- ------------------------------
function Exists (Self : in Manager; Name : in Value)
return Boolean is
Iter : Cursor := Self.List.First;
begin
if Self.Props.Exists (Name) then
return True;
end if;
while Has_Element (Iter) loop
if Element (Iter).Exists (Name) then
return True;
end if;
Iter := Next (Iter);
end loop;
return False;
end Exists;
-- ------------------------------
-- Returns the property value. Raises an exception if not found.
-- ------------------------------
function Get (Self : in Manager; Name : in Value)
return Value is
begin
return Self.Props.Get (Name);
exception
when NO_PROPERTY =>
declare
Iter : Cursor := Self.List.First;
begin
while Has_Element (Iter) loop
begin
return Element (Iter).all.Get (Name);
exception
when NO_PROPERTY =>
Iter := Next (Iter);
end;
end loop;
end;
raise;
end Get;
procedure Load_Properties (Self : in out Manager;
File : in String) is
begin
Self.Props.Load_Properties (File);
end Load_Properties;
procedure Insert (Self : in out Manager;
Name : in Value;
Item : in Value) is
pragma Unreferenced (Self);
pragma Unreferenced (Name);
pragma Unreferenced (Item);
begin
raise NOT_WRITEABLE with "Bundle is readonly";
end Insert;
-- ------------------------------
-- Set the value of the property. The property is created if it
-- does not exists.
-- ------------------------------
procedure Set (Self : in out Manager;
Name : in Value;
Item : in Value) is
begin
raise NOT_WRITEABLE with "Bundle is readonly";
end Set;
-- ------------------------------
-- Remove the property given its name.
-- ------------------------------
procedure Remove (Self : in out Manager; Name : in Value) is
begin
raise NOT_WRITEABLE with "Bundle is readonly";
end Remove;
-- Iterate over the properties and execute the given procedure passing the
-- property name and its value.
procedure Iterate (Self : in Manager;
Process : access procedure (Name, Item : Value)) is
begin
raise Program_Error with "Iterate is not implemented on Bundle";
end Iterate;
-- ------------------------------
-- Deep copy of properties stored in 'From' to 'To'.
-- ------------------------------
function Create_Copy (Self : in Manager)
return Util.Properties.Interface_P.Manager_Access is
pragma Unreferenced (Self);
begin
return null;
end Create_Copy;
procedure Delete (Self : in Manager;
Obj : in out Util.Properties.Interface_P.Manager_Access) is
pragma Unreferenced (Self);
Item : Manager_Object_Access := Manager (Obj.all)'Access;
begin
Free (Item);
end Delete;
function Get_Names (Self : in Manager;
Prefix : in String) return Name_Array is
Result : Name_Array (1 .. 2);
Iter : constant Cursor := Self.List.First;
begin
while Has_Element (Iter) loop
declare
M : constant Util.Properties.Manager_Access := Element (Iter);
N : constant Name_Array := M.Get_Names (Prefix);
begin
return N;
end;
end loop;
return Result;
end Get_Names;
procedure Add_Bundle (Self : in out Manager;
Props : in Util.Properties.Manager_Access) is
begin
Self.List.Append (Props);
end Add_Bundle;
end Interface_P;
-- ------------------------------
-- Clear the bundle cache
-- ------------------------------
procedure Clear_Cache (Factory : in out Loader) is
use Util.Strings;
use Bundle_Map;
function To_String_Access is
new Ada.Unchecked_Conversion (Source => Util.Strings.Name_Access,
Target => Ada.Strings.Unbounded.String_Access);
begin
Log.Info ("Clearing bundle cache");
Factory.Lock.Write;
loop
declare
Pos : Bundle_Map.Cursor := Factory.Bundles.First;
Name : Ada.Strings.Unbounded.String_Access;
Node : Bundle_Manager_Access;
begin
exit when not Has_Element (Pos);
Node := Element (Pos);
Name := To_String_Access (Key (Pos));
Factory.Bundles.Delete (Pos);
Free (Node);
Free (Name);
end;
end loop;
Factory.Lock.Release_Write;
end Clear_Cache;
-- ------------------------------
-- Finalize the bundle loader and clear the cache
-- ------------------------------
procedure Finalize (Factory : in out Loader) is
begin
Clear_Cache (Factory);
end Finalize;
end Util.Properties.Bundles;
|
-----------------------------------------------------------------------
-- properties -- Generic name/value property management
-- Copyright (C) 2001, 2002, 2003, 2006, 2008, 2009, 2010, 2011, 2012 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Unchecked_Deallocation;
with Ada.Unchecked_Conversion;
with Ada.Directories;
with Ada.Containers.Vectors;
with Ada.Strings.Fixed;
with Util.Log.Loggers;
with Util.Files;
with Util.Strings.Maps;
package body Util.Properties.Bundles is
use Util.Log;
Log : constant Loggers.Logger := Loggers.Create ("Util.Properties.Bundles");
procedure Free is
new Ada.Unchecked_Deallocation (Manager'Class,
Bundle_Manager_Access);
-- Implementation of the Bundle
-- (this allows to decouples the implementation from the API)
package Interface_P is
type Manager is new Util.Properties.Interface_P.Manager with private;
type Manager_Object_Access is access all Manager;
-- Returns TRUE if the property exists.
function Exists (Self : in Manager; Name : in Value)
return Boolean;
-- Returns the property value. Raises an exception if not found.
function Get (Self : in Manager; Name : in Value)
return Value;
procedure Insert (Self : in out Manager; Name : in Value;
Item : in Value);
-- Set the value of the property. The property is created if it
-- does not exists.
procedure Set (Self : in out Manager; Name : in Value;
Item : in Value);
-- Remove the property given its name.
procedure Remove (Self : in out Manager; Name : in Value);
-- Iterate over the properties and execute the given procedure passing the
-- property name and its value.
procedure Iterate (Self : in Manager;
Process : access procedure (Name, Item : Value));
procedure Load_Properties (Self : in out Manager;
File : in String);
-- Deep copy of properties stored in 'From' to 'To'.
function Create_Copy (Self : in Manager)
return Util.Properties.Interface_P.Manager_Access;
procedure Delete (Self : in Manager;
Obj : in out Util.Properties.Interface_P.Manager_Access);
function Get_Names (Self : in Manager;
Prefix : in String) return Name_Array;
procedure Add_Bundle (Self : in out Manager;
Props : in Util.Properties.Manager_Access);
private
use type Util.Properties.Manager_Access;
package PropertyList is new Ada.Containers.Vectors
(Element_Type => Util.Properties.Manager_Access,
Index_Type => Natural,
"=" => "=");
type Manager is new Util.Properties.Interface_P.Manager with record
List : PropertyList.Vector;
Props : aliased Util.Properties.Manager;
end record;
procedure Free is
new Ada.Unchecked_Deallocation (Manager,
Manager_Object_Access);
end Interface_P;
procedure Add_Bundle (Self : in out Manager;
Props : in Manager_Access) is
use type Util.Properties.Interface_P.Manager_Access;
begin
Interface_P.Manager'Class (Self.Impl.all).Add_Bundle (Props);
end Add_Bundle;
procedure Initialize (Object : in out Manager) is
use Util.Properties.Interface_P;
begin
Object.Impl := new Util.Properties.Bundles.Interface_P.Manager;
Object.Impl.Count := 1;
end Initialize;
procedure Adjust (Object : in out Manager) is
use Util.Properties.Interface_P;
begin
if Object.Impl /= null then
Object.Impl.Count := Object.Impl.Count + 1;
else
Object.Impl := new Util.Properties.Bundles.Interface_P.Manager;
Object.Impl.Count := 1;
end if;
end Adjust;
-- ------------------------------
-- Initialize the bundle factory and specify where the property files are stored.
-- ------------------------------
procedure Initialize (Factory : in out Loader;
Path : in String) is
begin
Log.Info ("Initialize bundle factory to load from {0}", Path);
Factory.Path := To_Unbounded_String (Path);
end Initialize;
-- ------------------------------
-- Load the bundle with the given name and for the given locale name.
-- ------------------------------
procedure Load_Bundle (Factory : in out Loader;
Name : in String;
Locale : in String;
Bundle : out Manager'Class) is
Found : Boolean := False;
begin
Log.Info ("Load bundle {0} for language {1}", Name, Locale);
Find_Bundle (Factory, Name, Locale, Bundle, Found);
if not Found then
Load_Bundle (Factory, Name, Found);
if not Found then
Log.Error ("Bundle {0} not found", Name);
raise NO_BUNDLE with "No bundle '" & Name & "'";
end if;
Find_Bundle (Factory, Name, Locale, Bundle, Found);
if not Found then
Log.Error ("Bundle {0} not found", Name);
raise NO_BUNDLE with "No bundle '" & Name & "'";
end if;
end if;
end Load_Bundle;
-- ------------------------------
-- Find the bundle with the given name and for the given locale name.
-- ------------------------------
procedure Find_Bundle (Factory : in out Loader;
Name : in String;
Locale : in String;
Bundle : out Manager'Class;
Found : out Boolean) is
use Ada.Strings;
use type Util.Properties.Manager_Access;
Loc_Name : constant String := '_' & Locale;
Last_Pos : Integer := Loc_Name'Last;
begin
Log.Info ("Looking for bundle {0} and language {1}", Name, Locale);
Found := False;
Factory.Lock.Read;
declare
Pos : Bundle_Map.Cursor;
begin
while Last_Pos + 1 >= Loc_Name'First loop
declare
Bundle_Name : aliased constant String
:= Name & Loc_Name (Loc_Name'First .. Last_Pos);
begin
Log.Debug ("Searching for {0}", Bundle_Name);
Pos := Factory.Bundles.Find (Bundle_Name'Unrestricted_Access);
if Bundle_Map.Has_Element (Pos) then
Bundle.Finalize;
Bundle.Impl := Bundle_Map.Element (Pos).Impl;
Bundle.Impl.Count := Bundle.Impl.Count + 1;
Found := True;
exit;
end if;
end;
if Last_Pos > Loc_Name'First then
Last_Pos := Fixed.Index (Loc_Name, "_", Last_Pos - 1, Backward) - 1;
else
Last_Pos := Last_Pos - 1;
end if;
end loop;
exception
when others =>
Factory.Lock.Release_Read;
raise;
end;
Factory.Lock.Release_Read;
end Find_Bundle;
-- ------------------------------
-- Load the bundle with the given name and for the given locale name.
-- ------------------------------
procedure Load_Bundle (Factory : in out Loader;
Name : in String;
Found : out Boolean) is
use Ada.Directories;
use Ada.Strings;
use Util.Strings;
use Ada.Containers;
use Util.Strings.String_Set;
use Bundle_Map;
procedure Process_File (Name : in String;
File_Path : in String;
Done : out Boolean);
Path : constant String := To_String (Factory.Path);
Pattern : constant String := Name & "*.properties";
Names : Util.Strings.String_Set.Set;
procedure Process_File (Name : in String;
File_Path : in String;
Done : out Boolean) is
subtype Cursor is Bundle_Map.Cursor;
Base_Name : aliased constant String := Name (Name'First .. Name'Last - 11);
Pos : constant Cursor := Factory.Bundles.Find (Base_Name'Unchecked_Access);
Bundle_Name : Name_Access;
Bundle : Bundle_Manager_Access;
begin
Log.Debug ("Loading file {0}", File_Path);
if Bundle_Map.Has_Element (Pos) then
Bundle := Bundle_Map.Element (Pos);
else
Bundle := new Manager;
Bundle_Name := new String '(Base_Name);
Factory.Bundles.Include (Key => Bundle_Name, New_Item => Bundle);
Names.Insert (Bundle_Name);
end if;
Interface_P.Manager'Class (Bundle.Impl.all).Load_Properties (File_Path);
Found := True;
Done := False;
end Process_File;
begin
Log.Info ("Reading bundle {1} in directory {0}", Path, Name);
Found := False;
Factory.Lock.Write;
begin
Util.Files.Iterate_Files_Path (Pattern => Pattern,
Path => Path,
Process => Process_File'Access,
Going => Ada.Strings.Backward);
-- Link the property files to implement the localization default rules.
while Names.Length > 0 loop
declare
Name_Pos : String_Set.Cursor := Names.First;
Bundle_Name : constant Name_Access := String_Set.Element (Name_Pos);
Idx : Natural := Fixed.Index (Bundle_Name.all, "_", Backward);
Bundle_Pos : constant Bundle_Map.Cursor := Factory.Bundles.Find (Bundle_Name);
Bundle : constant Bundle_Manager_Access := Element (Bundle_Pos);
begin
Names.Delete (Name_Pos);
-- Associate the property bundle to the first existing parent
-- Ex: message_fr_CA -> message_fr
-- message_fr_CA -> message
while Idx > 0 loop
declare
Name : aliased constant String
:= Bundle_Name (Bundle_Name'First .. Idx - 1);
Pos : constant Bundle_Map.Cursor
:= Factory.Bundles.Find (Name'Unchecked_Access);
begin
if Bundle_Map.Has_Element (Pos) then
Bundle.Add_Bundle (Bundle_Map.Element (Pos).all'Access);
Idx := 0;
else
Idx := Fixed.Index (Bundle_Name.all, "_", Idx - 1, Backward);
end if;
end;
end loop;
end;
end loop;
exception
when others =>
Factory.Lock.Release_Write;
raise;
end;
Factory.Lock.Release_Write;
exception
when Name_Error =>
Log.Error ("Cannot read directory: {0}", Path);
end Load_Bundle;
-- Implementation of the Bundle
-- (this allows to decouples the implementation from the API)
package body Interface_P is
use PropertyList;
-- ------------------------------
-- Returns TRUE if the property exists.
-- ------------------------------
function Exists (Self : in Manager; Name : in Value)
return Boolean is
Iter : Cursor := Self.List.First;
begin
if Self.Props.Exists (Name) then
return True;
end if;
while Has_Element (Iter) loop
if Element (Iter).Exists (Name) then
return True;
end if;
Iter := Next (Iter);
end loop;
return False;
end Exists;
-- ------------------------------
-- Returns the property value. Raises an exception if not found.
-- ------------------------------
function Get (Self : in Manager; Name : in Value)
return Value is
begin
return Self.Props.Get (Name);
exception
when NO_PROPERTY =>
declare
Iter : Cursor := Self.List.First;
begin
while Has_Element (Iter) loop
begin
return Element (Iter).all.Get (Name);
exception
when NO_PROPERTY =>
Iter := Next (Iter);
end;
end loop;
end;
raise;
end Get;
procedure Load_Properties (Self : in out Manager;
File : in String) is
begin
Self.Props.Load_Properties (File);
end Load_Properties;
procedure Insert (Self : in out Manager;
Name : in Value;
Item : in Value) is
pragma Unreferenced (Self);
pragma Unreferenced (Name);
pragma Unreferenced (Item);
begin
raise NOT_WRITEABLE with "Bundle is readonly";
end Insert;
-- ------------------------------
-- Set the value of the property. The property is created if it
-- does not exists.
-- ------------------------------
procedure Set (Self : in out Manager;
Name : in Value;
Item : in Value) is
begin
raise NOT_WRITEABLE with "Bundle is readonly";
end Set;
-- ------------------------------
-- Remove the property given its name.
-- ------------------------------
procedure Remove (Self : in out Manager; Name : in Value) is
begin
raise NOT_WRITEABLE with "Bundle is readonly";
end Remove;
-- Iterate over the properties and execute the given procedure passing the
-- property name and its value.
procedure Iterate (Self : in Manager;
Process : access procedure (Name, Item : Value)) is
begin
raise Program_Error with "Iterate is not implemented on Bundle";
end Iterate;
-- ------------------------------
-- Deep copy of properties stored in 'From' to 'To'.
-- ------------------------------
function Create_Copy (Self : in Manager)
return Util.Properties.Interface_P.Manager_Access is
pragma Unreferenced (Self);
begin
return null;
end Create_Copy;
procedure Delete (Self : in Manager;
Obj : in out Util.Properties.Interface_P.Manager_Access) is
pragma Unreferenced (Self);
Item : Manager_Object_Access := Manager (Obj.all)'Access;
begin
Free (Item);
end Delete;
function Get_Names (Self : in Manager;
Prefix : in String) return Name_Array is
Result : Name_Array (1 .. 2);
Iter : constant Cursor := Self.List.First;
begin
while Has_Element (Iter) loop
declare
M : constant Util.Properties.Manager_Access := Element (Iter);
N : constant Name_Array := M.Get_Names (Prefix);
begin
return N;
end;
end loop;
return Result;
end Get_Names;
procedure Add_Bundle (Self : in out Manager;
Props : in Util.Properties.Manager_Access) is
begin
Self.List.Append (Props);
end Add_Bundle;
end Interface_P;
-- ------------------------------
-- Clear the bundle cache
-- ------------------------------
procedure Clear_Cache (Factory : in out Loader) is
use Util.Strings;
use Bundle_Map;
function To_String_Access is
new Ada.Unchecked_Conversion (Source => Util.Strings.Name_Access,
Target => Ada.Strings.Unbounded.String_Access);
begin
Log.Info ("Clearing bundle cache");
Factory.Lock.Write;
loop
declare
Pos : Bundle_Map.Cursor := Factory.Bundles.First;
Name : Ada.Strings.Unbounded.String_Access;
Node : Bundle_Manager_Access;
begin
exit when not Has_Element (Pos);
Node := Element (Pos);
Name := To_String_Access (Key (Pos));
Factory.Bundles.Delete (Pos);
Free (Node);
Free (Name);
end;
end loop;
Factory.Lock.Release_Write;
end Clear_Cache;
-- ------------------------------
-- Finalize the bundle loader and clear the cache
-- ------------------------------
procedure Finalize (Factory : in out Loader) is
begin
Clear_Cache (Factory);
end Finalize;
end Util.Properties.Bundles;
|
Add support for resource bundle overloading - load the property files in the reverse order for the search path this allows to have in a directory a set of bundle files that override some but not all of the messages defined in the bundle files
|
Add support for resource bundle overloading
- load the property files in the reverse order for the search path
this allows to have in a directory a set of bundle files that
override some but not all of the messages defined in the bundle
files
|
Ada
|
apache-2.0
|
flottokarotto/ada-util,Letractively/ada-util,flottokarotto/ada-util,Letractively/ada-util
|
71024c54c6685826f84cf8a97067a89bb0f75300
|
src/el-contexts-tls.ads
|
src/el-contexts-tls.ads
|
-----------------------------------------------------------------------
-- EL.Contexts.TLS -- EL context and Thread Local Support
-- Copyright (C) 2015 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 EL.Contexts.Default;
-- == EL TLS Context ==
-- The <tt>TLS_Context</tt> type defines an expression context that associates itself to
-- a per-thread context information. By declaring a variable with this type, the expression
-- context is associated with the current thread and it can be retrieved at any time by using the
-- <tt>Current</tt> function. As soon as the variable is finalized, the current thread context
-- is updated.
--
-- The expression context may be declared as follows:
--
-- Context : EL.Contexts.TLS.TLS_Context;
--
-- And at any time, a function or procedure that needs to evaluate an expression can use it:
--
-- Expr : EL.Expressions.Expression;
-- ...
-- Value : Util.Beans.Objects.Object := Expr.Get_Value (EL.Contexts.TLS.Current.all);
--
package EL.Contexts.TLS is
-- ------------------------------
-- TLS Context
-- ------------------------------
-- Context information for expression evaluation.
type TLS_Context is new EL.Contexts.Default.Default_Context with private;
-- Get the current EL context associated with the current thread.
function Current return EL.Contexts.ELContext_Access;
private
type TLS_Context is new EL.Contexts.Default.Default_Context with record
Previous : EL.Contexts.ELContext_Access;
end record;
-- Initialize and setup a new per-thread EL context.
overriding
procedure Initialize (Obj : in out TLS_Context);
-- Restore the previouse per-thread EL context.
overriding
procedure Finalize (Obj : in out TLS_Context);
end EL.Contexts.TLS;
|
Declare the TLS package for thread local context support
|
Declare the TLS package for thread local context support
|
Ada
|
apache-2.0
|
stcarrez/ada-el
|
|
1c56ba76fb3e0fbfd4c8eafd8851153d95eb450b
|
samples/serialize_xml.adb
|
samples/serialize_xml.adb
|
with Ada.Text_IO;
with Util.Serialize.IO.XML;
with Util.Streams.Texts;
procedure Serialize_Xml is
Output : aliased Util.Streams.Texts.Print_Stream;
Stream : Util.Serialize.IO.XML.Output_Stream;
begin
Output.Initialize (Size => 10000);
Stream.Initialize (Output => Output'Unchecked_Access);
-- Stream.Start_Document;
Stream.Start_Entity ("person");
Stream.Write_Entity ("name", "Harry Potter");
Stream.Write_Entity ("gender", "male");
Stream.Write_Entity ("age", 17);
Stream.End_Entity ("person");
-- Stream.End_Document;
Ada.Text_IO.Put_Line (Util.Streams.Texts.To_String (Output));
end Serialize_Xml;
|
Add example for XML serialization
|
Add example for XML serialization
|
Ada
|
apache-2.0
|
stcarrez/ada-util,stcarrez/ada-util
|
|
6a51467d9d65c4af03ace0c4389f2d26506cd5bf
|
src/asis/a4g-a_sinput.adb
|
src/asis/a4g-a_sinput.adb
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . A _ S I N P U T --
-- --
-- B o d y --
-- --
-- Copyright (C) 1995-2010, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
with Ada.Characters.Handling; use Ada.Characters.Handling;
with System.WCh_Con; use System.WCh_Con;
with Asis.Set_Get; use Asis.Set_Get;
with Atree; use Atree;
with Opt; use Opt;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
with Widechar; use Widechar;
package body A4G.A_Sinput is
use ASCII;
-- Make control characters visible
-----------------------
-- Local subprograms --
-----------------------
procedure Skip_Comment (P : in out Source_Ptr);
-- When P is set on the first '-' of a comment, this procedure resets
-- the value of P to the first character of the group of control
-- characters signifying the end of line containing the comment
-- initially indicated by P.
--
-- This procedure should not be used for the last comment in the
-- group of comments following a compilation unit in a compilation.
procedure Skip_String (P : in out Source_Ptr);
-- When P set on the first quoter of a string literal (it may be '"' or
-- '%', this procedure resets the value of P to the first character
-- after the literal.
-------------------------
-- A_Get_Column_Number --
-------------------------
function A_Get_Column_Number (P : Source_Ptr) return Source_Ptr is
Sindex : constant Source_File_Index := Get_Source_File_Index (P);
Src : constant Source_Buffer_Ptr := Source_Text (Sindex);
S : Source_Ptr;
Result : Source_Ptr := 0;
begin
S := Line_Start (P);
while S <= P loop
if Is_Start_Of_Wide_Char_For_ASIS (Src, S) then
Skip_Wide_For_ASIS (Src, S);
else
S := S + 1;
end if;
Result := Result + 1;
end loop;
return Result;
end A_Get_Column_Number;
-----------------------
-- Comment_Beginning --
-----------------------
function Comment_Beginning (Line_Image : Text_Buffer) return Source_Ptr is
Line_Image_Start : constant Source_Ptr := Line_Image'First;
Line_Image_End : constant Source_Ptr := Line_Image'Last;
Scanner_Pos : Source_Ptr;
String_Delimiter : Standard.Character;
begin
Scanner_Pos := Line_Image_Start - 1;
Scan_The_Line : while Scanner_Pos < Line_Image_End loop
Scanner_Pos := Scanner_Pos + 1;
case Line_Image (Scanner_Pos) is
when '"' | '%' =>
if not ((Scanner_Pos - 1) >= Line_Image_Start and then
Line_Image (Scanner_Pos - 1) = '''
and then
(Scanner_Pos + 1) <= Line_Image_End and then
Line_Image (Scanner_Pos + 1) = ''')
then
-- We have to awoid considering character literals '"'
-- '%' as string brackets
String_Delimiter := Line_Image (Scanner_Pos);
Skip_String_Literal : loop
Scanner_Pos := Scanner_Pos + 1;
if Line_Image (Scanner_Pos) = String_Delimiter then
-- we are in a legal Ada source, therefore:
if Scanner_Pos < Line_Image'Last and then
Line_Image (Scanner_Pos + 1) = String_Delimiter
then
-- Delimiter as character inside the literal.
Scanner_Pos := Scanner_Pos + 1;
else
-- End of the literal.
exit Skip_String_Literal;
end if;
end if;
end loop Skip_String_Literal;
end if;
when '-' =>
if (Scanner_Pos < Line_Image'Last) and then
(Line_Image (Scanner_Pos + 1) = '-')
then
return Scanner_Pos;
end if;
when others =>
null;
end case;
end loop Scan_The_Line;
-- There wasn't any comment if we reach this point.
return No_Location;
end Comment_Beginning;
--------------------
-- Exp_Name_Image --
--------------------
function Exp_Name_Image (Name : Node_Id) return String is
Prefix_Node : Node_Id;
Selector_Node : Node_Id;
begin
if Nkind (Name) = N_Identifier or else
Nkind (Name) = N_Defining_Identifier
then
-- ????? See E729-A04!
return Identifier_Image (Name);
end if;
if Nkind (Name) = N_Defining_Program_Unit_Name then
Prefix_Node := Sinfo.Name (Name);
Selector_Node := Defining_Identifier (Name);
else
-- Nkind (Name) = N_Expanded_Name
Prefix_Node := Prefix (Name);
Selector_Node := Selector_Name (Name);
end if;
return Exp_Name_Image (Prefix_Node)
& '.'
& Identifier_Image (Selector_Node); -- ???
end Exp_Name_Image;
-------------------
-- Get_Character --
-------------------
function Get_Character (P : Source_Ptr) return Character is
Sindex : constant Source_File_Index := Get_Source_File_Index (P);
Src : constant Source_Buffer_Ptr := Source_Text (Sindex);
begin
return Src (P);
end Get_Character;
------------------
-- Get_Location --
------------------
function Get_Location (E : Asis.Element) return Source_Ptr is
begin
return Sloc (Node (E));
end Get_Location;
-------------------------
-- Get_Num_Literal_End --
-------------------------
function Get_Num_Literal_End (P : Source_Ptr) return Source_Ptr is
Sindex : constant Source_File_Index := Get_Source_File_Index (P);
Src : constant Source_Buffer_Ptr := Source_Text (Sindex);
S : Source_Ptr;
B_Char : Character;
begin
-- Src (P) is the leading digit of a numeric literal
S := P + 1;
loop
if Is_Hexadecimal_Digit (Src (S)) or else Src (S) = '_' then
S := S + 1;
elsif Src (S) = '#' or else Src (S) = ':' then
-- based literal: 16#E#E1 or 016#offf#
-- J.2 (3): "The number sign characters (#) of a based_literal
-- can be replaced by colons (:) provided that the replacement
-- is done for both occurrences. But in case of a colon, we
-- have to make sure that we indeed have a based literal, but not
-- a decimal literal immediatelly followed by an assignment sign,
-- see G119-012:
--
-- SPLIT_INDEX:INTEGER RANGE 1..80:=1;
if Src (S) = ':' and then Src (S + 1) = '=' then
S := S - 1;
exit;
end if;
B_Char := Src (S);
-- and now - looking for trailing '#' or ':':
S := S + 1;
while Src (S) /= B_Char loop
S := S + 1;
end loop;
if Src (S + 1) = 'E' or else
Src (S + 1) = 'e'
then
-- this means something like 5#1234.1234#E2
S := S + 2;
else
exit;
end if;
elsif Src (S) = '+'
or else
Src (S) = '-'
then -- 12E+34 or 12+34?
if Src (S - 1) = 'E'
or else
Src (S - 1) = 'e'
then
-- it is the sign of the exponent
S := S + 1;
else
S := S - 1; -- to go back in the literal
exit;
end if;
elsif Src (S) = '.' then -- 3.14 or 3..14?
if Is_Hexadecimal_Digit (Src (S + 1)) then
S := S + 1;
else
S := S - 1; -- to go back in the literal
exit;
end if;
else -- for sure, we already are outside the literal
S := S - 1; -- to go back in the literal
exit;
end if;
end loop;
return S;
end Get_Num_Literal_End;
--------------------
-- Get_String_End --
--------------------
function Get_String_End (P : Source_Ptr) return Source_Ptr is
Sindex : constant Source_File_Index := Get_Source_File_Index (P);
Src : constant Source_Buffer_Ptr := Source_Text (Sindex);
S : Source_Ptr;
Quote : Character;
begin
-- Src (P) is the leading quotation of the non-nul string constant
-- which can be either '"' OR '%' (J.2 (2)).
Quote := Src (P);
S := P + 1;
loop
if Src (S) = Quote and then Src (S + 1) = Quote then
S := S + 2;
elsif Src (S) /= Quote then
if Is_Start_Of_Wide_Char_For_ASIS (Src, S) then
Skip_Wide_For_ASIS (Src, S);
else
S := S + 1;
end if;
else
-- S points to the trailing quotation of the constant
exit;
end if;
end loop;
return S;
end Get_String_End;
-------------------
-- Get_Wide_Word --
-------------------
function Get_Wide_Word
(P_Start : Source_Ptr;
P_End : Source_Ptr)
return Wide_String
is
Sindex : constant Source_File_Index := Get_Source_File_Index (P_Start);
Src : constant Source_Buffer_Ptr := Source_Text (Sindex);
Result : Wide_String (1 .. Positive (P_End - P_Start + 1));
Last_Idx : Natural := 0;
Next_Ch : Char_Code;
S : Source_Ptr;
Success : Boolean;
pragma Unreferenced (Success);
begin
S := P_Start;
while S <= P_End loop
Last_Idx := Last_Idx + 1;
if Is_Start_Of_Wide_Char_For_ASIS (Src, S) then
Scan_Wide (Src, S, Next_Ch, Success);
Result (Last_Idx) := Wide_Character'Val (Next_Ch);
else
Result (Last_Idx) := To_Wide_Character (Src (S));
S := S + 1;
end if;
end loop;
return Result (1 .. Last_Idx);
end Get_Wide_Word;
-----------------
-- Get_Wide_Ch --
-----------------
function Get_Wide_Ch (S : Source_Ptr) return Wide_Character is
Sindex : constant Source_File_Index := Get_Source_File_Index (S);
Src : constant Source_Buffer_Ptr := Source_Text (Sindex);
S1 : Source_Ptr := S;
Ch : Char_Code;
Result : Wide_Character;
Success : Boolean;
pragma Unreferenced (Success);
begin
if Is_Start_Of_Wide_Char_For_ASIS (Src, S1) then
Scan_Wide (Src, S1, Ch, Success);
Result := Wide_Character'Val (Ch);
else
Result := To_Wide_Character (Src (S1));
end if;
return Result;
end Get_Wide_Ch;
------------------
-- Get_Word_End --
------------------
function Get_Word_End
(P : Source_Ptr;
In_Word : In_Word_Condition)
return Source_Ptr
is
S : Source_Ptr;
begin
S := P;
while In_Word (S + 1) loop
S := S + 1;
end loop;
return S;
end Get_Word_End;
----------------------
-- Identifier_Image --
----------------------
function Identifier_Image (Ident : Node_Id) return String is
Image_Start : Source_Ptr;
Image_End : Source_Ptr;
begin
Image_Start := Sloc (Ident);
Image_End := Get_Word_End (P => Image_Start,
In_Word => In_Identifier'Access);
-- See E729-A04!!!
return To_String (Get_Wide_Word (Image_Start, Image_End));
end Identifier_Image;
-------------------
-- In_Identifier --
-------------------
function In_Identifier (P : Source_Ptr) return Boolean is
Sindex : constant Source_File_Index := Get_Source_File_Index (P);
Src : constant Source_Buffer_Ptr := Source_Text (Sindex);
Char : Character;
Result : Boolean := True;
begin
Char := Src (P);
if Char = ' ' or else
Char = '&' or else
Char = ''' or else
Char = '(' or else
Char = ')' or else
Char = '*' or else
Char = '+' or else
Char = ',' or else
Char = '-' or else
Char = '.' or else
Char = '/' or else
Char = ':' or else
Char = ';' or else
Char = '<' or else
Char = '=' or else
Char = '>' or else
Char = '|' or else
Char = '!' or else
Char = ASCII.LF or else
Char = ASCII.FF or else
Char = ASCII.HT or else
Char = ASCII.VT or else
Char = ASCII.CR
then
Result := False;
end if;
return Result;
end In_Identifier;
-----------------
-- Is_EOL_Char --
-----------------
function Is_EOL_Char (Ch : Character) return Boolean is
Result : Boolean := False;
begin
Result :=
Ch = ASCII.CR
or else
Ch = ASCII.LF
or else
Ch = ASCII.FF
or else
Ch = ASCII.VT;
return Result;
end Is_EOL_Char;
------------------------------------
-- Is_Start_Of_Wide_Char_For_ASIS --
------------------------------------
function Is_Start_Of_Wide_Char_For_ASIS
(S : Source_Buffer_Ptr;
P : Source_Ptr;
C : Source_Ptr := No_Location)
return Boolean
is
Result : Boolean := False;
begin
if C /= No_Location and then P > C then
-- We are in comment, so we can not have bracket encoding
if Wide_Character_Encoding_Method /= WCEM_Brackets then
Result := Is_Start_Of_Wide_Char (S, P);
end if;
else
Result := Is_Start_Of_Wide_Char (S, P);
if not Result then
Result := P <= S'Last - 2
and then S (P) = '['
and then S (P + 1) = '"'
and then (S (P + 2) in '0' .. '9'
or else
S (P + 2) in 'a' .. 'f'
or else
S (P + 2) in 'A' .. 'F');
end if;
end if;
return Result;
end Is_Start_Of_Wide_Char_For_ASIS;
---------------------
-- Next_Identifier --
---------------------
function Next_Identifier (P : Source_Ptr) return Source_Ptr is
Sindex : constant Source_File_Index := Get_Source_File_Index (P);
Src : constant Source_Buffer_Ptr := Source_Text (Sindex);
S : Source_Ptr;
begin
S := P + 1;
while not Is_Letter (Src (S)) loop
if Src (S) = '-' and then Src (S + 1) = '-' then
Skip_Comment (S);
else
S := S + 1;
end if;
end loop;
return S;
end Next_Identifier;
---------------------
-- Number_Of_Lines --
---------------------
function Number_Of_Lines (E : Asis.Element) return Integer is
SFI : constant Source_File_Index :=
Get_Source_File_Index (Get_Location (E));
begin
-- return Integer (Num_Source_Lines (SFI) + Line_Offset (SFI));
return Integer (Num_Source_Lines (SFI));
end Number_Of_Lines;
--------------------
-- Operator_Image --
--------------------
function Operator_Image (Node : Node_Id) return String is
S_Start : constant Source_Ptr := Sloc (Node);
-- S_Start points to the leading character of a given operator symbol.
Sindex : constant Source_File_Index :=
Get_Source_File_Index (S_Start);
Src : constant Source_Buffer_Ptr := Source_Text (Sindex);
S_End : Source_Ptr := S_Start;
-- should be set as pointing to the last character of a given
-- operator symbol.
Ch : Character;
begin
Ch := Src (S_Start);
if Ch = 'A' or else Ch = 'a' -- "abs" or "and"
or else Ch = 'M' or else Ch = 'm' -- "mod"
or else Ch = 'N' or else Ch = 'n' -- "not"
or else Ch = 'R' or else Ch = 'r' -- "rem"
or else Ch = 'X' or else Ch = 'x' -- "xor"
then
S_End := S_Start + 2;
elsif Ch = 'O' or else Ch = 'o' then -- "or"
S_End := S_Start + 1;
elsif Ch = '=' -- "="
or else Ch = '+' -- "+"
or else Ch = '-' -- "-"
or else Ch = '&' -- "&"
then
S_End := S_Start;
elsif Ch = '/' -- "/=" or "/"?
or else Ch = '<' -- "<=" or "<"?
or else Ch = '>' -- ">=" or ">"?
or else Ch = '*' -- "**" or "*"?
then
Ch := Src (S_Start + 1);
if Ch = '=' or else -- "/=", "<=" or ">="
Ch = '*' -- "**"
then
S_End := S_Start + 1;
else
S_End := S_Start;
-- "<", ">", "*" or "/"
end if;
end if;
return (1 => '"') & String (Src (S_Start .. S_End)) & (1 => '"');
end Operator_Image;
-------------------------
-- Rightmost_Non_Blank --
-------------------------
function Rightmost_Non_Blank (P : Source_Ptr) return Source_Ptr is
S : Source_Ptr := P;
Sindex : constant Source_File_Index := Get_Source_File_Index (P);
Src : constant Source_Buffer_Ptr := Source_Text (Sindex);
begin
loop
if Src (S) = '-' and then Src (S + 1) = '-' then
Skip_Comment (S);
elsif Is_Graphic (Src (S)) and then Src (S) /= ' ' then
exit;
else
S := S + 1;
end if;
end loop;
return S;
end Rightmost_Non_Blank;
------------------------------
-- Search_Beginning_Of_Word --
------------------------------
function Search_Beginning_Of_Word (S : Source_Ptr) return Source_Ptr is
SFI : constant Source_File_Index := Get_Source_File_Index (S);
Src : constant Source_Buffer_Ptr := Source_Text (SFI);
S_P : Source_Ptr;
begin
S_P := S;
while S_P >= Source_First (SFI)
and then (Src (S_P) in 'A' .. 'Z' or else
Src (S_P) in 'a' .. 'z' or else
Src (S_P) in '0' .. '9' or else
Src (S_P) = '_')
loop
S_P := S_P - 1;
end loop;
return S_P + 1;
end Search_Beginning_Of_Word;
------------------------
-- Search_End_Of_Word --
------------------------
function Search_End_Of_Word (S : Source_Ptr) return Source_Ptr is
S_P : Source_Ptr := S;
SFI : constant Source_File_Index := Get_Source_File_Index (S);
Src : constant Source_Buffer_Ptr := Source_Text (SFI);
Char : Character;
begin
Char := Src (S_P);
while not (Char = ' ' or else
Char = '&' or else
Char = ''' or else
Char = '(' or else
Char = ')' or else
Char = '*' or else
Char = '+' or else
Char = ',' or else
Char = '-' or else
Char = '.' or else
Char = '/' or else
Char = ':' or else
Char = ';' or else
Char = '<' or else
Char = '=' or else
Char = '>' or else
Char = '|' or else
Char = '!' or else
Char = ASCII.LF or else
Char = ASCII.FF or else
Char = ASCII.HT or else
Char = ASCII.VT or else
Char = ASCII.CR)
loop
S_P := S_P + 1;
Char := Src (S_P);
end loop;
S_P := S_P - 1;
return S_P;
end Search_End_Of_Word;
-----------------------------
-- Search_Left_Parenthesis --
-----------------------------
function Search_Left_Parenthesis (S : Source_Ptr) return Source_Ptr is
S_P : Source_Ptr := S - 1;
SFI : constant Source_File_Index := Get_Source_File_Index (S);
Src : constant Source_Buffer_Ptr := Source_Text (SFI);
begin
loop
case Src (S_P) is
when '(' =>
return S_P;
when CR | LF =>
declare
TempS : Source_Ptr := Line_Start (S_P);
begin
while (Src (TempS) /= '-' or else
Src (TempS + 1) /= '-')
and then
TempS < S_P
loop
TempS := TempS + 1;
end loop;
S_P := TempS - 1;
end;
when others =>
S_P := S_P - 1;
end case;
end loop;
end Search_Left_Parenthesis;
----------------------
-- Search_Next_Word --
----------------------
function Search_Next_Word (S : Source_Ptr) return Source_Ptr is
S_P : Source_Ptr := S + 1;
SFI : constant Source_File_Index := Get_Source_File_Index (S);
Src : constant Source_Buffer_Ptr := Source_Text (SFI);
begin
loop
case Src (S_P) is
when ' ' | HT | CR | LF =>
S_P := S_P + 1;
when '-' =>
if Src (S_P + 1) = '-' then
Skip_Comment (S_P);
else
return S_P;
end if;
when others =>
return S_P;
end case;
end loop;
end Search_Next_Word;
----------------------
-- Search_Prev_Word --
----------------------
function Search_Prev_Word (S : Source_Ptr) return Source_Ptr is
S_P : Source_Ptr := S - 1;
SFI : constant Source_File_Index := Get_Source_File_Index (S);
Src : constant Source_Buffer_Ptr := Source_Text (SFI);
begin
loop
case Src (S_P) is
when ' ' | HT =>
S_P := S_P - 1;
when CR | LF =>
declare
TempS : Source_Ptr := Line_Start (S_P);
begin
while (Src (TempS) /= '-' or else
Src (TempS + 1) /= '-')
and then
TempS < S_P
loop
TempS := TempS + 1;
end loop;
S_P := TempS - 1;
end;
when others =>
return S_P;
end case;
end loop;
end Search_Prev_Word;
----------------------------
-- Search_Prev_Word_Start --
----------------------------
function Search_Prev_Word_Start (S : Source_Ptr) return Source_Ptr is
begin
return Search_Beginning_Of_Word (Search_Prev_Word (S));
end Search_Prev_Word_Start;
-----------------------------
-- Search_Rightmost_Symbol --
-----------------------------
function Search_Rightmost_Symbol
(P : Source_Ptr;
Char : Character := ';')
return Source_Ptr
is
S : Source_Ptr := P;
-- the location to be returned, the search is started from P
Sindex : constant Source_File_Index := Get_Source_File_Index (P);
Src : constant Source_Buffer_Ptr := Source_Text (Sindex);
begin
while Src (S) /= Char loop
if Src (S) = '-' and then Src (S + 1) = '-' then
Skip_Comment (S);
elsif (Src (S) = '"' or else Src (S) = '%')
and then
not (Src (S - 1) = ''' and then Src (S + 1) = ''')
then
Skip_String (S);
else
S := S + 1;
end if;
end loop;
return S;
end Search_Rightmost_Symbol;
-----------------
-- Skip_String --
-----------------
procedure Skip_String (P : in out Source_Ptr) is
Sindex : constant Source_File_Index := Get_Source_File_Index (P);
Src : constant Source_Buffer_Ptr := Source_Text (Sindex);
Quoter : constant Character := Src (P);
begin
-- we are in the beginning of a legal string literal in a legal
-- Ada program. So we do not have to be careful with all
-- the checks:
while not (Src (P) = Quoter and then Src (P + 1) /= Quoter) loop
P := P + 1;
end loop;
P := P + 1;
end Skip_String;
------------------
-- Skip_Comment --
------------------
procedure Skip_Comment (P : in out Source_Ptr) is
Sindex : constant Source_File_Index := Get_Source_File_Index (P);
Src : constant Source_Buffer_Ptr := Source_Text (Sindex);
begin
if Src (P) = '-' and then Src (P + 1) = '-' then
P := P + 2;
while not (Src (P) = VT or else
Src (P) = CR or else
Src (P) = LF or else
Src (P) = FF)
loop
P := P + 1;
end loop;
end if;
end Skip_Comment;
------------------------
-- Skip_Wide_For_ASIS --
------------------------
procedure Skip_Wide_For_ASIS
(S : Source_Buffer_Ptr;
P : in out Source_Ptr)
is
Old_P : constant Source_Ptr := P;
Old_Wide_Character_Encoding_Method : WC_Encoding_Method;
begin
Skip_Wide (S, P);
if P = Old_P + 1 then
-- We have a bracket encoding, but the encoding method is different
-- from WCEM_Brackets
P := P - 1;
Old_Wide_Character_Encoding_Method := Wide_Character_Encoding_Method;
Wide_Character_Encoding_Method := WCEM_Brackets;
Skip_Wide (S, P);
Wide_Character_Encoding_Method := Old_Wide_Character_Encoding_Method;
end if;
end Skip_Wide_For_ASIS;
------------------------------
-- Source_Locations_To_Span --
------------------------------
function Source_Locations_To_Span
(Span_Beg : Source_Ptr;
Span_End : Source_Ptr)
return Span
is
Sp : Span;
begin
Sp.First_Line := Line_Number (Get_Physical_Line_Number (Span_Beg));
Sp.First_Column := Character_Position (A_Get_Column_Number (Span_Beg));
Sp.Last_Line := Line_Number (Get_Physical_Line_Number (Span_End));
Sp.Last_Column := Character_Position (A_Get_Column_Number (Span_End));
return Sp;
end Source_Locations_To_Span;
-----------------------
-- Wide_String_Image --
-----------------------
function Wide_String_Image (Node : Node_Id) return Wide_String is
S_Start : constant Source_Ptr := Sloc (Node);
-- S_Start points to the leading quote of a given string literal.
Sindex : constant Source_File_Index :=
Get_Source_File_Index (S_Start);
Src : constant Source_Buffer_Ptr := Source_Text (Sindex);
S_End : Source_Ptr := S_Start + 1;
-- should be set as pointing to the last character of a
-- string literal; empty and non-empty literals are processed
-- in the same way - we simply take a literal as it is from the
-- Source Buffer
Quote : constant Character := Src (S_Start);
-- Quoter may be '"' or '%'!
begin
loop
if Src (S_End) = Quote and then
Src (S_End + 1) = Quote
then
-- doubled string quote as an element of a given string
S_End := S_End + 2;
elsif Src (S_End) /= Quote then
-- "usial" string element
S_End := S_End + 1;
else
-- S_End points to the trailing quote of a given string
exit;
end if;
end loop;
declare
Result : Wide_String (1 .. Positive (S_End - S_Start + 1));
Last_Idx : Natural := 0;
Next_Ch : Char_Code;
S : Source_Ptr;
Success : Boolean;
pragma Unreferenced (Success);
begin
S := S_Start;
while S <= S_End loop
Last_Idx := Last_Idx + 1;
if Is_Start_Of_Wide_Char_For_ASIS (Src, S) then
Scan_Wide (Src, S, Next_Ch, Success);
Result (Last_Idx) := Wide_Character'Val (Next_Ch);
else
Result (Last_Idx) := To_Wide_Character (Src (S));
S := S + 1;
end if;
end loop;
return Result (1 .. Last_Idx);
end;
end Wide_String_Image;
end A4G.A_Sinput;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
stcarrez/dynamo,stcarrez/dynamo,stcarrez/dynamo
|
|
79f5e14556ed4d82acdea75908f7f26616e3b8fb
|
src/asis/asis-data_decomposition-set_get.adb
|
src/asis/asis-data_decomposition-set_get.adb
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A S I S . D A T A _ D E C O M P O S I T I O N . S E T _ G E T --
-- --
-- B o d y --
-- --
-- Copyright (C) 1995-2009, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
with System; use System;
with Asis.Declarations; use Asis.Declarations;
with Asis.Definitions; use Asis.Definitions;
with Asis.Elements; use Asis.Elements;
with Asis.Extensions; use Asis.Extensions;
with Asis.Iterator; use Asis.Iterator;
with Asis.Set_Get; use Asis.Set_Get;
with Asis.Data_Decomposition.Aux; use Asis.Data_Decomposition.Aux;
with A4G.Contt; use A4G.Contt;
with Atree; use Atree;
with Sinfo; use Sinfo;
with Einfo; use Einfo;
with Nlists; use Nlists;
with Uintp; use Uintp;
package body Asis.Data_Decomposition.Set_Get is
-----------------------
-- Local subprograms --
-----------------------
procedure Set_Derived_Type_Components (E : Asis.Element);
-- Provided that E is a derived type definition, this procedure sets in
-- Asis_Element_Table the defining identifiers of the components of the
-- corresponding type. (For inherited components it sets the corresponding
-- implicit names)
--------------------
-- Component_Name --
--------------------
function Component_Name (Comp : RC) return Asis.Defining_Name is
begin
return Comp.Component_Name;
end Component_Name;
---------------
-- Dimension --
---------------
function Dimension (Comp : AC) return ASIS_Natural
is
begin
return Comp.Dimension;
end Dimension;
---------------------------
-- Get_Array_Type_Entity --
---------------------------
function Get_Array_Type_Entity (Comp : AC) return Entity_Id is
Result : Entity_Id;
pragma Warnings (Off, Result);
begin
-- ???!!! This is a trick needed to reset the right tree!
-- ???!!! Should be replaced by a proper tree handling for
-- ???!!! array components
Result := Node (Comp.Parent_Array_Type);
Result := Comp.Array_Type_Entity;
return Result;
end Get_Array_Type_Entity;
---------------------
-- Get_Comp_Entity --
---------------------
function Get_Comp_Entity (Comp : RC) return Entity_Id is
begin
return R_Node (Component_Name (Comp));
end Get_Comp_Entity;
-----------------------
-- Get_Record_Entity --
-----------------------
function Get_Record_Entity (Comp : RC) return Entity_Id is
Result : Entity_Id;
begin
Result := R_Node (Parent_Record_Type (Comp));
while Nkind (Result) /= N_Full_Type_Declaration loop
Result := Parent (Result);
end loop;
Result := Defining_Identifier (Result);
return Result;
end Get_Record_Entity;
---------------------
-- Get_Type_Entity --
---------------------
function Get_Type_Entity (Comp : RC) return Node_Id is
Result : Node_Id;
begin
Result := Etype (R_Node (Component_Name (Comp)));
if Ekind (Result) = E_Private_Type then
Result := Full_View (Result);
end if;
return Result;
end Get_Type_Entity;
-------------------
-- Is_Array_Comp --
-------------------
function Is_Array_Comp (Comp : AC) return Boolean is
begin
return Comp.Is_Array_Comp;
end Is_Array_Comp;
function Is_Array_Comp (Comp : RC) return Boolean is
begin
return Comp.Is_Array_Comp;
end Is_Array_Comp;
--------------------
-- Is_Record_Comp --
--------------------
function Is_Record_Comp (Comp : AC) return Boolean is
begin
return Comp.Is_Record_Comp;
end Is_Record_Comp;
function Is_Record_Comp (Comp : RC) return Boolean is
begin
return Comp.Is_Record_Comp;
end Is_Record_Comp;
-----------------------
-- Parent_Array_Type --
-----------------------
function Parent_Array_Type (Comp : AC) return Asis.Declaration is
begin
return Comp.Parent_Array_Type;
end Parent_Array_Type;
---------------------
-- Parent_Discrims --
---------------------
function Parent_Discrims (Comp : AC) return Discrim_List is
begin
if Comp.Parent_Discrims = null then
return Null_Discrims;
else
return Comp.Parent_Discrims.all;
end if;
end Parent_Discrims;
function Parent_Discrims (Comp : RC) return Discrim_List is
begin
if Comp.Parent_Discrims = null then
return Null_Discrims;
else
return Comp.Parent_Discrims.all;
end if;
end Parent_Discrims;
------------------------
-- Parent_Record_Type --
------------------------
function Parent_Record_Type (Comp : RC) return Asis.Declaration is
begin
return Comp.Parent_Record_Type;
end Parent_Record_Type;
-------------------------
-- Set_Array_Componnet --
-------------------------
function Set_Array_Componnet
(Array_Type_Definition : Element;
Enclosing_Record_Component : Record_Component := Nil_Record_Component;
Parent_Indication : Element := Nil_Element;
Parent_Discriminants : Discrim_List := Null_Discrims;
Parent_First_Bit_Offset : ASIS_Natural := 0;
Dynamic_Array : Boolean := False)
return Array_Component
is
Comp_Node : Node_Id;
Comp_Type_Entity : Node_Id;
Result : Array_Component := Nil_Array_Component;
Enclosing_Array_Type : Element;
Array_Entity : Entity_Id := Empty;
-- This should be a type entity defining the enclosed
-- array type. This may be an implicit type created by the compiler,
-- but the point is that in should contain real ranges for
-- this component
Dim : Asis.ASIS_Positive;
Tmp_Node : Node_Id;
Comp_Size : ASIS_Natural;
begin
Result.Parent_Array_Type := Array_Type_Definition;
Result.Parent_Component_Name :=
Component_Name (Enclosing_Record_Component);
Comp_Node := Node (Array_Type_Definition);
Comp_Type_Entity := Defining_Identifier (Parent (Comp_Node));
if Ekind (Comp_Type_Entity) in Object_Kind then
-- Array definition as a part of an object definition, here we have
-- an anonymous array type
Comp_Type_Entity := Etype (Etype (Comp_Type_Entity));
Array_Entity := Comp_Type_Entity;
end if;
Comp_Type_Entity := Component_Type (Comp_Type_Entity);
if Ekind (Comp_Type_Entity) = E_Private_Type then
Comp_Type_Entity := Full_View (Comp_Type_Entity);
end if;
Result.Is_Record_Comp := Is_Record_Type (Comp_Type_Entity);
Result.Is_Array_Comp := Is_Array_Type (Comp_Type_Entity);
if not Is_Nil (Enclosing_Record_Component) then
Array_Entity := R_Node (Enclosing_Record_Component.Component_Name);
Array_Entity := Etype (Array_Entity);
elsif not Is_Nil (Parent_Indication) then
Enclosing_Array_Type := Enclosing_Element (Parent_Indication);
Enclosing_Array_Type := Enclosing_Element (Enclosing_Array_Type);
Enclosing_Array_Type := Enclosing_Element (Enclosing_Array_Type);
Array_Entity := Defining_Identifier (R_Node (Enclosing_Array_Type));
Array_Entity := Component_Type (Array_Entity);
elsif No (Array_Entity) then
Enclosing_Array_Type := Enclosing_Element (Array_Type_Definition);
Array_Entity := Defining_Identifier (R_Node (Enclosing_Array_Type));
end if;
if Ekind (Array_Entity) = E_Private_Type then
Array_Entity := Full_View (Array_Entity);
end if;
Result.Array_Type_Entity := Array_Entity;
-- Computing dimentions and lengths:
Tmp_Node := First_Index (Array_Entity);
Dim := ASIS_Positive (List_Length (List_Containing (Tmp_Node)));
Result.Dimension := Dim;
Result.Length := (others => 0);
for I in 1 .. Dim loop
if Dynamic_Array then
Result.Length (I) := 0;
else
Result.Length (I) := Get_Length (Typ => Array_Entity,
Sub => I,
Discs => Parent_Discriminants);
end if;
end loop;
Comp_Size := ASIS_Natural (UI_To_Int (
Get_Component_Size (Array_Entity)));
Result.Position := Parent_First_Bit_Offset / Storage_Unit;
Result.First_Bit := Parent_First_Bit_Offset mod Storage_Unit;
Result.Last_Bit := Result.First_Bit + Comp_Size - 1;
Result.Size := Comp_Size;
Set_Parent_Discrims (Result, Parent_Discriminants);
Result.Parent_Context := Get_Current_Cont;
Result.Obtained := A_OS_Time;
return Result;
end Set_Array_Componnet;
------------------------------
-- Set_All_Named_Components --
------------------------------
procedure Set_All_Named_Components (E : Element) is
Discr_Part : Element;
begin
if Asis.Elements.Type_Kind (E) = A_Derived_Type_Definition then
Set_Derived_Type_Components (E);
else
Discr_Part := Discriminant_Part (Enclosing_Element (E));
Set_Named_Components (Discr_Part, New_List);
Set_Named_Components (E, Append);
end if;
end Set_All_Named_Components;
---------------------------------
-- Set_Derived_Type_Components --
---------------------------------
procedure Set_Derived_Type_Components (E : Asis.Element) is
Discr_Part : constant Asis.Element :=
Discriminant_Part (Enclosing_Element (E));
Impl_Comps : constant Asis.Element_List :=
Implicit_Inherited_Declarations (E);
begin
Set_Named_Components (Discr_Part, New_List);
for J in Impl_Comps'Range loop
Asis_Element_Table.Append (Names (Impl_Comps (J)) (1));
end loop;
end Set_Derived_Type_Components;
--------------------------
-- Set_Named_Components --
--------------------------
procedure Set_Named_Components (E : Element; List_Kind : List_Kinds) is
Control : Traverse_Control := Continue;
State : No_State := Not_Used;
procedure Set_Def_Name
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out No_State);
-- If Element is of A_Defining_Identifier kind, this procedure stores
-- it in the Asis Element Table. Used as Pre-Operation
procedure Set_Def_Name
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out No_State)
is
begin
pragma Unreferenced (Control);
pragma Unreferenced (State);
if Int_Kind (Element) /= A_Defining_Identifier then
return;
end if;
Asis_Element_Table.Append (Element);
end Set_Def_Name;
procedure Create_Name_List is new Traverse_Element (
State_Information => No_State,
Pre_Operation => Set_Def_Name,
Post_Operation => No_Op);
begin
if List_Kind = New_List then
Asis_Element_Table.Init;
end if;
if Is_Nil (E) then
return;
end if;
Create_Name_List
(Element => E,
Control => Control,
State => State);
end Set_Named_Components;
-------------------------
-- Set_Parent_Discrims --
-------------------------
procedure Set_Parent_Discrims (Comp : in out AC; Discs : Discrim_List) is
begin
if Discs = Null_Discrims then
Comp.Parent_Discrims := null;
else
Comp.Parent_Discrims := new Discrim_List'(Discs);
end if;
end Set_Parent_Discrims;
----------------------------
-- Set_Record_Type_Entity --
----------------------------
procedure Set_Record_Type_Entity (AC : Array_Component) is
begin
Record_Type_Entity := Get_Array_Type_Entity (AC);
Record_Type_Entity := Component_Type (Record_Type_Entity);
end Set_Record_Type_Entity;
procedure Set_Record_Type_Entity (RC : Record_Component) is
begin
Record_Type_Entity := R_Node (Component_Name (RC));
Record_Type_Entity := Etype (Record_Type_Entity);
end Set_Record_Type_Entity;
procedure Set_Record_Type_Entity is
begin
Record_Type_Entity :=
Defining_Identifier (Parent (R_Node (Parent_Type_Definition)));
end Set_Record_Type_Entity;
--------------------------------
-- Set_Parent_Type_Definition --
--------------------------------
procedure Set_Parent_Type_Definition (E : Element) is
begin
Parent_Type_Definition := E;
end Set_Parent_Type_Definition;
--------------------------------------
-- Set_Record_Components_From_Names --
--------------------------------------
procedure Set_Record_Components_From_Names
(Parent_First_Bit : ASIS_Natural := 0;
Data_Stream : Portable_Data := Nil_Portable_Data;
Discriminants : Boolean := False)
is
New_Comp : Asis.List_Index;
Component_Name : Element;
Comp_Entity : Node_Id;
Discs : constant Discrim_List :=
Build_Discrim_List_If_Data_Presented
(Rec => Record_Type_Entity,
Data => Data_Stream,
Ignore_Discs => Discriminants);
Comp_Type_Entity : Node_Id;
Comp_First_Bit_Offset : ASIS_Natural;
Comp_Position : ASIS_Natural;
Comp_Size : ASIS_Natural;
begin
Record_Component_Table.Init;
for I in 1 .. Asis_Element_Table.Last loop
Component_Name := Def_N_Table (I);
Comp_Entity := Node (Component_Name);
if Discs = Null_Discrims or else
Component_Present (Comp_Entity, Discs)
then
Record_Component_Table.Increment_Last;
New_Comp := Record_Component_Table.Last;
RC_Table (New_Comp).Parent_Record_Type := Parent_Type_Definition;
RC_Table (New_Comp).Component_Name := Component_Name;
Comp_Type_Entity := Etype (Comp_Entity);
if Ekind (Comp_Type_Entity) = E_Private_Type then
Comp_Type_Entity := Full_View (Comp_Type_Entity);
end if;
RC_Table (New_Comp).Is_Record_Comp :=
Is_Record_Type (Comp_Type_Entity);
RC_Table (New_Comp).Is_Array_Comp :=
Is_Array_Type (Comp_Type_Entity);
if Discs = Null_Discrims then
RC_Table (New_Comp).Parent_Discrims := null;
else
RC_Table (New_Comp).Parent_Discrims :=
new Discrim_List'(Discs);
end if;
Comp_First_Bit_Offset := Parent_First_Bit +
ASIS_Natural (UI_To_Int (
Get_Component_Bit_Offset (Comp_Entity, Discs)));
Comp_Position := Comp_First_Bit_Offset / Storage_Unit;
Comp_Size := ASIS_Natural (UI_To_Int
(Get_Esize (Comp_Entity, Discs)));
RC_Table (New_Comp).Position := Comp_Position;
RC_Table (New_Comp).First_Bit :=
Comp_First_Bit_Offset mod Storage_Unit;
RC_Table (New_Comp).Last_Bit :=
RC_Table (New_Comp).First_Bit + Comp_Size - 1;
RC_Table (New_Comp).Size := Comp_Size;
RC_Table (New_Comp).Parent_Context := Get_Current_Cont;
RC_Table (New_Comp).Obtained := A_OS_Time;
end if;
end loop;
end Set_Record_Components_From_Names;
end Asis.Data_Decomposition.Set_Get;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
stcarrez/dynamo,stcarrez/dynamo,stcarrez/dynamo
|
|
5198fe9e85063f88dfac725487f62ed140a2d8cb
|
src/sys/encoders/util-encoders-uri.adb
|
src/sys/encoders/util-encoders-uri.adb
|
-----------------------------------------------------------------------
-- util-encoders-uri -- Encode and decode URI using percent encoding
-- Copyright (C) 2022 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Encoders.Base16;
package body Util.Encoders.URI is
-- ------------------------------
-- Compute the length of the encoded URI string with percent encoding
-- and with the given encoding array. Characters for which the `Encoding` array
-- returns True are encoded using %HEXDIGIT HEXDIGIT.
-- Returns the length of encoded string.
-- ------------------------------
function Encoded_Length (URI : in String;
Encoding : in Encoding_Array := HREF_STRICT) return Natural is
Length : Natural := 0;
begin
for C of URI loop
if Encoding (C) then
Length := Length + 3;
else
Length := Length + 1;
end if;
end loop;
return Length;
end Encoded_Length;
-- ------------------------------
-- Encode the string using URI percent encoding.
-- Characters for which the `Encoding` array returns True are encoded
-- using %HEXDIGIT HEXDIGIT. Returns the percent encoded string.
-- ------------------------------
function Encode (URI : in String;
Encoding : in Encoding_Array := HREF_STRICT) return String is
Length : constant Natural := Encoded_Length (URI, Encoding);
Result : String (1 .. Length);
Write_Pos : Positive := 1;
begin
for C of URI loop
if Encoding (C) then
Result (Write_Pos) := '%';
Result (Write_Pos + 1) := Base16.To_Hex_High (C);
Result (Write_Pos + 2) := Base16.To_Hex_Low (C);
Write_Pos := Write_Pos + 3;
else
Result (Write_Pos) := C;
Write_Pos := Write_Pos + 1;
end if;
end loop;
return Result;
end Encode;
-- ------------------------------
-- Decode the percent encoded URI string.
-- ------------------------------
function Decode (URI : in String) return String is
Result : String (1 .. URI'Length);
Read_Pos : Natural := URI'First;
Write_Pos : Natural := Result'First - 1;
C : Character;
begin
while Read_Pos <= URI'Last loop
C := URI (Read_Pos);
if C = '%' and Read_Pos + 2 <= URI'Last then
C := Base16.From_Hex (URI (Read_Pos + 1), URI (Read_Pos + 2));
Read_Pos := Read_Pos + 3;
else
Read_Pos := Read_Pos + 1;
end if;
Write_Pos := Write_Pos + 1;
Result (Write_Pos) := C;
end loop;
return Result (1 .. Write_Pos);
end Decode;
end Util.Encoders.URI;
|
Implement the Encode and Decode functions
|
Implement the Encode and Decode functions
|
Ada
|
apache-2.0
|
stcarrez/ada-util,stcarrez/ada-util
|
|
abbd98f5de0ac239514bb9e645f377270b6b835a
|
regtests/util-tests.adb
|
regtests/util-tests.adb
|
-----------------------------------------------------------------------
-- AUnit utils - Helper for writing unit tests
-- Copyright (C) 2009, 2010 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 GNAT.Command_Line;
with AUnit.Assertions;
with AUnit.Reporter.Text;
with AUnit.Run;
with Util.Measures;
with Ada.Command_Line;
with Ada.Directories;
with Ada.IO_Exceptions;
with Ada.Text_IO;
with Util.Properties;
with Util.Files;
package body Util.Tests is
use AUnit.Assertions;
Test_Properties : Util.Properties.Manager;
-- ------------------------------
-- Get a path to access a test file.
-- ------------------------------
function Get_Path (File : String) return String is
Dir : constant String := Get_Parameter ("test.dir", ".");
begin
return Dir & "/" & File;
end Get_Path;
-- ------------------------------
-- Get a path to create a test file.
-- ------------------------------
function Get_Test_Path (File : String) return String is
Dir : constant String := Get_Parameter ("test.result.dir", ".");
begin
return Dir & "/" & File;
end Get_Test_Path;
-- ------------------------------
-- Get a test configuration parameter.
-- ------------------------------
function Get_Parameter (Name : String;
Default : String := "") return String is
begin
return Test_Properties.Get (Name, Default);
end Get_Parameter;
-- ------------------------------
-- Check that the value matches what we expect.
-- ------------------------------
procedure Assert_Equals (Expect, Value : in Integer;
Message : in String := "Test failed";
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
begin
Assert (Condition => Expect = Value,
Message => Message & ": expecting '"
& Integer'Image (Expect) & "'"
& " value was '"
& Integer'Image (Value) & "'",
Source => Source,
Line => Line);
end Assert_Equals;
-- ------------------------------
-- Check that the value matches what we expect.
-- ------------------------------
procedure Assert_Equals (Expect, Value : in String;
Message : in String := "Test failed";
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
begin
Assert (Condition => Expect = Value,
Message => Message & ": expecting '" & Expect & "'"
& " value was '" & Value & "'",
Source => Source,
Line => Line);
end Assert_Equals;
-- ------------------------------
-- Check that the value matches what we expect.
-- ------------------------------
procedure Assert_Equals (Expect : in String;
Value : in Unbounded_String;
Message : in String := "Test failed";
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
begin
Assert_Equals (Expect => Expect,
Value => To_String (Value),
Message => Message,
Source => Source,
Line => Line);
end Assert_Equals;
-- ------------------------------
-- Check that two files are equal. This is intended to be used by
-- tests that create files that are then checked against patterns.
-- ------------------------------
procedure Assert_Equal_Files (Expect : in String;
Test : in String;
Message : in String := "Test failed";
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
use Util.Files;
Expect_File : Unbounded_String;
Test_File : Unbounded_String;
Same : Boolean;
begin
if not Ada.Directories.Exists (Expect) then
Assert (False, "Expect file '" & Expect & "' does not exist",
Source => Source, Line => Line);
end if;
Read_File (Path => Expect,
Into => Expect_File);
Read_File (Path => Test,
Into => Test_File);
-- Check file sizes
Assert_Equals (Expect => Length (Expect_File),
Value => Length (Test_File),
Message => Message & ": Invalid file sizes",
Source => Source,
Line => Line);
Same := Expect_File = Test_File;
if Same then
return;
end if;
end Assert_Equal_Files;
-- ------------------------------
-- The main testsuite program. This launches the tests, collects the
-- results, create performance logs and set the program exit status
-- according to the testsuite execution status.
-- ------------------------------
procedure Harness (Name : in String) is
use type AUnit.Status;
use GNAT.Command_Line;
function Runner is new AUnit.Run.Test_Runner_With_Status (Suite);
Reporter : AUnit.Reporter.Text.Text_Reporter;
Perf : aliased Util.Measures.Measure_Set;
Result : AUnit.Status;
begin
loop
case Getopt ("config") is
when 'c' =>
declare
Name : constant String := Get_Argument;
begin
Test_Properties.Load_Properties (Name);
exception
when Ada.IO_Exceptions.Name_Error =>
Ada.Text_IO.Put_Line ("Cannot find configuration file: " & Name);
Ada.Command_Line.Set_Exit_Status (2);
return;
end;
when others =>
exit;
end case;
end loop;
declare
S : Util.Measures.Stamp;
begin
Util.Measures.Set_Current (Perf'Unchecked_Access);
Result := Runner (Reporter, True);
Util.Measures.Report (Perf, S, "Testsuite execution");
Util.Measures.Write (Perf, "Test measures", Name);
end;
-- Program exit status reflects the testsuite result
if Result /= AUnit.Success then
Ada.Command_Line.Set_Exit_Status (1);
else
Ada.Command_Line.Set_Exit_Status (0);
end if;
end Harness;
end Util.Tests;
|
-----------------------------------------------------------------------
-- AUnit utils - Helper for writing unit tests
-- Copyright (C) 2009, 2010 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 GNAT.Command_Line;
with AUnit.Assertions;
with AUnit.Reporter.Text;
with AUnit.Run;
with Util.Measures;
with Ada.Command_Line;
with Ada.Directories;
with Ada.IO_Exceptions;
with Ada.Text_IO;
with Util.Properties;
with Util.Files;
package body Util.Tests is
use AUnit.Assertions;
Test_Properties : Util.Properties.Manager;
-- When a test uses external test files to match a result against a well
-- defined content, it can be difficult to maintain those external files.
-- The <b>Assert_Equal_Files</b> can automatically maintain the reference
-- file by updating it with the lastest test result.
--
-- Of course, using this mode means the test does not validate anything.
Update_Test_Files : Boolean := False;
-- ------------------------------
-- Get a path to access a test file.
-- ------------------------------
function Get_Path (File : String) return String is
Dir : constant String := Get_Parameter ("test.dir", ".");
begin
return Dir & "/" & File;
end Get_Path;
-- ------------------------------
-- Get a path to create a test file.
-- ------------------------------
function Get_Test_Path (File : String) return String is
Dir : constant String := Get_Parameter ("test.result.dir", ".");
begin
return Dir & "/" & File;
end Get_Test_Path;
-- ------------------------------
-- Get a test configuration parameter.
-- ------------------------------
function Get_Parameter (Name : String;
Default : String := "") return String is
begin
return Test_Properties.Get (Name, Default);
end Get_Parameter;
-- ------------------------------
-- Check that the value matches what we expect.
-- ------------------------------
procedure Assert_Equals (Expect, Value : in Integer;
Message : in String := "Test failed";
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
begin
Assert (Condition => Expect = Value,
Message => Message & ": expecting '"
& Integer'Image (Expect) & "'"
& " value was '"
& Integer'Image (Value) & "'",
Source => Source,
Line => Line);
end Assert_Equals;
-- ------------------------------
-- Check that the value matches what we expect.
-- ------------------------------
procedure Assert_Equals (Expect, Value : in String;
Message : in String := "Test failed";
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
begin
Assert (Condition => Expect = Value,
Message => Message & ": expecting '" & Expect & "'"
& " value was '" & Value & "'",
Source => Source,
Line => Line);
end Assert_Equals;
-- ------------------------------
-- Check that the value matches what we expect.
-- ------------------------------
procedure Assert_Equals (Expect : in String;
Value : in Unbounded_String;
Message : in String := "Test failed";
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
begin
Assert_Equals (Expect => Expect,
Value => To_String (Value),
Message => Message,
Source => Source,
Line => Line);
end Assert_Equals;
-- ------------------------------
-- Check that two files are equal. This is intended to be used by
-- tests that create files that are then checked against patterns.
-- ------------------------------
procedure Assert_Equal_Files (Expect : in String;
Test : in String;
Message : in String := "Test failed";
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) is
use Util.Files;
Expect_File : Unbounded_String;
Test_File : Unbounded_String;
Same : Boolean;
begin
if not Ada.Directories.Exists (Expect) then
Assert (False, "Expect file '" & Expect & "' does not exist",
Source => Source, Line => Line);
end if;
Read_File (Path => Expect,
Into => Expect_File);
Read_File (Path => Test,
Into => Test_File);
-- Check file sizes
Assert_Equals (Expect => Length (Expect_File),
Value => Length (Test_File),
Message => Message & ": Invalid file sizes",
Source => Source,
Line => Line);
Same := Expect_File = Test_File;
if Same then
return;
end if;
exception
when others =>
if Update_Test_Files then
Ada.Directories.Copy_File (Source_Name => Test,
Target_Name => Expect);
end if;
end Assert_Equal_Files;
-- ------------------------------
-- The main testsuite program. This launches the tests, collects the
-- results, create performance logs and set the program exit status
-- according to the testsuite execution status.
-- ------------------------------
procedure Harness (Name : in String) is
use type AUnit.Status;
use GNAT.Command_Line;
use Ada.Text_IO;
function Runner is new AUnit.Run.Test_Runner_With_Status (Suite);
procedure Help;
procedure Help is
begin
Put_Line ("Test harness: " & Name);
Put ("Usage: harness [-config file.properties] ");
Put_Line ("[-update]");
Put_Line ("-config file Specify a test configuration file");
Put_Line ("-update Update the test reference files if a file");
Put_Line (" is missing or the test generates another output");
Put_Line (" (See Asset_Equals_File)");
Ada.Command_Line.Set_Exit_Status (2);
end Help;
Reporter : AUnit.Reporter.Text.Text_Reporter;
Perf : aliased Util.Measures.Measure_Set;
Result : AUnit.Status;
begin
loop
case Getopt ("hu c: config: update help") is
when ASCII.NUL =>
exit;
when 'c' =>
declare
Name : constant String := Parameter;
begin
Test_Properties.Load_Properties (Name);
exception
when Ada.IO_Exceptions.Name_Error =>
Ada.Text_IO.Put_Line ("Cannot find configuration file: " & Name);
Ada.Command_Line.Set_Exit_Status (2);
return;
end;
when 'u' =>
Update_Test_Files := True;
when others =>
Help;
return;
end case;
end loop;
declare
S : Util.Measures.Stamp;
begin
Util.Measures.Set_Current (Perf'Unchecked_Access);
Result := Runner (Reporter, True);
Util.Measures.Report (Perf, S, "Testsuite execution");
Util.Measures.Write (Perf, "Test measures", Name);
end;
-- Program exit status reflects the testsuite result
if Result /= AUnit.Success then
Ada.Command_Line.Set_Exit_Status (1);
else
Ada.Command_Line.Set_Exit_Status (0);
end if;
exception
when Invalid_Switch =>
Put_Line ("Invalid Switch " & Full_Switch);
Help;
return;
when Invalid_Parameter =>
Put_Line ("No parameter for " & Full_Switch);
Help;
return;
end Harness;
end Util.Tests;
|
Add help usage for the test harness tool Add -update option to update the test reference files when new tests are added or when a test changes
|
Add help usage for the test harness tool
Add -update option to update the test reference files
when new tests are added or when a test changes
|
Ada
|
apache-2.0
|
flottokarotto/ada-util,Letractively/ada-util,flottokarotto/ada-util,Letractively/ada-util,stcarrez/ada-util,stcarrez/ada-util
|
153221f611b9b7e985725deacb1b84b0ab7a6e1f
|
mat/src/mat-types.adb
|
mat/src/mat-types.adb
|
-----------------------------------------------------------------------
-- mat-types -- Global types
-- Copyright (C) 2014 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 MAT.Types is
-- ------------------------------
-- Return an hexadecimal string representation of the value.
-- ------------------------------
function Hex_Image (Value : in Uint32;
Length : in Positive := 8) return String is
use type Interfaces.Unsigned_32;
Conversion : constant String (1 .. 16) := "0123456789ABCDEF";
S : String (1 .. Length) := (others => '0');
P : Uint32 := Value;
N : Uint32;
I : Positive := Length;
begin
while P /= 0 loop
N := P mod 16;
P := P / 16;
S (I) := Conversion (Natural (N + 1));
exit when I = 1;
I := I - 1;
end loop;
return S;
end Hex_Image;
end MAT.Types;
|
Implement the Hex_Image operation
|
Implement the Hex_Image operation
|
Ada
|
apache-2.0
|
stcarrez/mat,stcarrez/mat,stcarrez/mat
|
|
63ac7924796922fd38c2a80729ca3b4d18314aff
|
src/gen-model-stypes.adb
|
src/gen-model-stypes.adb
|
-----------------------------------------------------------------------
-- gen-model-stypes -- Simple data type definitions
-- Copyright (C) 2021 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 Gen.Model.Stypes is
-- ------------------------------
-- Get the value identified by the name.
-- If the name cannot be found, the method should return the Null object.
-- ------------------------------
overriding
function Get_Value (From : Stype_Definition;
Name : String) return Util.Beans.Objects.Object is
begin
if Name = "parent" then
return Util.Beans.Objects.To_Object (From.Parent_Type);
elsif Name = "name" then
return Util.Beans.Objects.To_Object (From.Type_Name);
elsif Name = "isEnum" then
return Util.Beans.Objects.To_Object (False);
elsif Name = "isDiscrete" or Name = "isNewDiscrete" then
return Util.Beans.Objects.To_Object (True);
elsif Name = "sqlType" then
return Util.Beans.Objects.To_Object (Mappings.Get_Type_Name (From.Sql_Type));
else
return Mappings.Mapping_Definition (From).Get_Value (Name);
end if;
end Get_Value;
-- ------------------------------
-- Prepare the generation of the model.
-- ------------------------------
overriding
procedure Prepare (O : in out Stype_Definition) is
begin
O.Target := O.Type_Name;
end Prepare;
-- ------------------------------
-- Initialize the table definition instance.
-- ------------------------------
overriding
procedure Initialize (O : in out Stype_Definition) is
begin
null;
end Initialize;
-- ------------------------------
-- Create an simple type with its parent type.
-- ------------------------------
function Create_Stype (Name : in Unbounded_String;
Parent : in Unbounded_String) return Stype_Definition_Access is
Stype : constant Stype_Definition_Access := new Stype_Definition;
begin
Stype.Set_Name (Name);
declare
Pos : constant Natural := Index (Stype.Name, ".", Ada.Strings.Backward);
begin
Stype.Parent_Type := Parent;
if Pos > 0 then
Stype.Pkg_Name := Unbounded_Slice (Stype.Name, 1, Pos - 1);
Stype.Type_Name := Unbounded_Slice (Stype.Name, Pos + 1, Length (Stype.Name));
Stype.Nullable_Type := "Nullable_" & Stype.Type_Name;
-- Stype.Target := Stype.Name;
else
Stype.Pkg_Name := To_Unbounded_String ("ADO");
Stype.Type_Name := Stype.Name;
-- Stype.Target := Stype.Name;
end if;
end;
return Stype;
end Create_Stype;
end Gen.Model.Stypes;
|
Implement the new package operations
|
Implement the new package operations
|
Ada
|
apache-2.0
|
stcarrez/dynamo,stcarrez/dynamo,stcarrez/dynamo
|
|
022aa6a514b442952fbc6cd2792f9a12987d2fc9
|
src/wiki-render-html.adb
|
src/wiki-render-html.adb
|
-----------------------------------------------------------------------
-- wiki-render-html -- Wiki HTML renderer
-- Copyright (C) 2011, 2012, 2013, 2014, 2015 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Strings;
package body Wiki.Render.Html is
-- use Wiki.Documents;
-- ------------------------------
-- Set the output writer.
-- ------------------------------
procedure Set_Writer (Document : in out Html_Renderer;
Writer : in Wiki.Writers.Html_Writer_Type_Access) is
begin
Document.Writer := Writer;
end Set_Writer;
-- ------------------------------
-- Add a section header in the document.
-- ------------------------------
overriding
procedure Add_Header (Document : in out Html_Renderer;
Header : in Unbounded_Wide_Wide_String;
Level : in Positive) is
begin
Document.Close_Paragraph;
Document.Add_Blockquote (0);
case Level is
when 1 =>
Document.Writer.Write_Wide_Element ("h1", Header);
when 2 =>
Document.Writer.Write_Wide_Element ("h2", Header);
when 3 =>
Document.Writer.Write_Wide_Element ("h3", Header);
when 4 =>
Document.Writer.Write_Wide_Element ("h4", Header);
when 5 =>
Document.Writer.Write_Wide_Element ("h5", Header);
when 6 =>
Document.Writer.Write_Wide_Element ("h6", Header);
when others =>
Document.Writer.Write_Wide_Element ("h3", Header);
end case;
end Add_Header;
-- ------------------------------
-- Add a line break (<br>).
-- ------------------------------
overriding
procedure Add_Line_Break (Document : in out Html_Renderer) is
begin
-- Document.Writer.Write_Raw ("<br />");
Document.Writer.Write ("<br />");
end Add_Line_Break;
-- ------------------------------
-- Add a paragraph (<p>). Close the previous paragraph if any.
-- The paragraph must be closed at the next paragraph or next header.
-- ------------------------------
overriding
procedure Add_Paragraph (Document : in out Html_Renderer) is
begin
Document.Close_Paragraph;
Document.Need_Paragraph := True;
end Add_Paragraph;
-- ------------------------------
-- Add a blockquote (<blockquote>). The level indicates the blockquote nested level.
-- The blockquote must be closed at the next header.
-- ------------------------------
overriding
procedure Add_Blockquote (Document : in out Html_Renderer;
Level : in Natural) is
begin
if Document.Quote_Level /= Level then
Document.Close_Paragraph;
Document.Need_Paragraph := True;
end if;
while Document.Quote_Level < Level loop
Document.Writer.Start_Element ("blockquote");
Document.Quote_Level := Document.Quote_Level + 1;
end loop;
while Document.Quote_Level > Level loop
Document.Writer.End_Element ("blockquote");
Document.Quote_Level := Document.Quote_Level - 1;
end loop;
end Add_Blockquote;
-- ------------------------------
-- Add a list item (<li>). Close the previous paragraph and list item if any.
-- The list item will be closed at the next list item, next paragraph or next header.
-- ------------------------------
overriding
procedure Add_List_Item (Document : in out Html_Renderer;
Level : in Positive;
Ordered : in Boolean) is
begin
if Document.Has_Paragraph then
Document.Writer.End_Element ("p");
Document.Has_Paragraph := False;
end if;
if Document.Has_Item then
Document.Writer.End_Element ("li");
Document.Has_Item := False;
end if;
Document.Need_Paragraph := False;
Document.Open_Paragraph;
while Document.Current_Level < Level loop
if Ordered then
Document.Writer.Start_Element ("ol");
else
Document.Writer.Start_Element ("ul");
end if;
Document.Current_Level := Document.Current_Level + 1;
Document.List_Styles (Document.Current_Level) := Ordered;
end loop;
end Add_List_Item;
procedure Close_Paragraph (Document : in out Html_Renderer) is
begin
if Document.Has_Paragraph then
Document.Writer.End_Element ("p");
end if;
if Document.Has_Item then
Document.Writer.End_Element ("li");
end if;
while Document.Current_Level > 0 loop
if Document.List_Styles (Document.Current_Level) then
Document.Writer.End_Element ("ol");
else
Document.Writer.End_Element ("ul");
end if;
Document.Current_Level := Document.Current_Level - 1;
end loop;
Document.Has_Paragraph := False;
Document.Has_Item := False;
end Close_Paragraph;
procedure Open_Paragraph (Document : in out Html_Renderer) is
begin
if Document.Need_Paragraph then
Document.Writer.Start_Element ("p");
Document.Has_Paragraph := True;
Document.Need_Paragraph := False;
end if;
if Document.Current_Level > 0 and not Document.Has_Item then
Document.Writer.Start_Element ("li");
Document.Has_Item := True;
end if;
end Open_Paragraph;
-- ------------------------------
-- Add an horizontal rule (<hr>).
-- ------------------------------
overriding
procedure Add_Horizontal_Rule (Document : in out Html_Renderer) is
begin
Document.Close_Paragraph;
Document.Add_Blockquote (0);
Document.Writer.Start_Element ("hr");
Document.Writer.End_Element ("hr");
end Add_Horizontal_Rule;
-- ------------------------------
-- Add a link.
-- ------------------------------
overriding
procedure Add_Link (Document : in out Html_Renderer;
Name : in Unbounded_Wide_Wide_String;
Link : in Unbounded_Wide_Wide_String;
Language : in Unbounded_Wide_Wide_String;
Title : in Unbounded_Wide_Wide_String) is
begin
Document.Open_Paragraph;
Document.Writer.Start_Element ("a");
if Length (Title) > 0 then
Document.Writer.Write_Wide_Attribute ("title", Title);
end if;
if Length (Language) > 0 then
Document.Writer.Write_Wide_Attribute ("lang", Language);
end if;
Document.Writer.Write_Wide_Attribute ("href", Link);
Document.Writer.Write_Wide_Text (Name);
Document.Writer.End_Element ("a");
end Add_Link;
-- ------------------------------
-- Add an image.
-- ------------------------------
overriding
procedure Add_Image (Document : in out Html_Renderer;
Link : in Unbounded_Wide_Wide_String;
Alt : in Unbounded_Wide_Wide_String;
Position : in Unbounded_Wide_Wide_String;
Description : in Unbounded_Wide_Wide_String) is
pragma Unreferenced (Position);
begin
Document.Open_Paragraph;
Document.Writer.Start_Element ("img");
if Length (Alt) > 0 then
Document.Writer.Write_Wide_Attribute ("alt", Alt);
end if;
if Length (Description) > 0 then
Document.Writer.Write_Wide_Attribute ("longdesc", Description);
end if;
Document.Writer.Write_Wide_Attribute ("src", Link);
Document.Writer.End_Element ("img");
end Add_Image;
-- ------------------------------
-- Add a quote.
-- ------------------------------
overriding
procedure Add_Quote (Document : in out Html_Renderer;
Quote : in Unbounded_Wide_Wide_String;
Link : in Unbounded_Wide_Wide_String;
Language : in Unbounded_Wide_Wide_String) is
begin
Document.Open_Paragraph;
Document.Writer.Start_Element ("q");
if Length (Language) > 0 then
Document.Writer.Write_Wide_Attribute ("lang", Language);
end if;
if Length (Link) > 0 then
Document.Writer.Write_Wide_Attribute ("cite", Link);
end if;
Document.Writer.Write_Wide_Text (Quote);
Document.Writer.End_Element ("q");
end Add_Quote;
HTML_BOLD : aliased constant String := "b";
HTML_ITALIC : aliased constant String := "i";
HTML_CODE : aliased constant String := "tt";
HTML_SUPERSCRIPT : aliased constant String := "sup";
HTML_SUBSCRIPT : aliased constant String := "sub";
HTML_STRIKEOUT : aliased constant String := "del";
-- HTML_UNDERLINE : aliased constant String := "ins";
HTML_PREFORMAT : aliased constant String := "pre";
type String_Array_Access is array (Documents.Format_Type) of Util.Strings.Name_Access;
HTML_ELEMENT : constant String_Array_Access :=
(Documents.BOLD => HTML_BOLD'Access,
Documents.ITALIC => HTML_ITALIC'Access,
Documents.CODE => HTML_CODE'Access,
Documents.SUPERSCRIPT => HTML_SUPERSCRIPT'Access,
Documents.SUBSCRIPT => HTML_SUBSCRIPT'Access,
Documents.STRIKEOUT => HTML_STRIKEOUT'Access,
Documents.PREFORMAT => HTML_PREFORMAT'Access);
-- ------------------------------
-- Add a text block with the given format.
-- ------------------------------
overriding
procedure Add_Text (Document : in out Html_Renderer;
Text : in Unbounded_Wide_Wide_String;
Format : in Wiki.Documents.Format_Map) is
begin
Document.Open_Paragraph;
for I in Format'Range loop
if Format (I) then
Document.Writer.Start_Element (HTML_ELEMENT (I).all);
end if;
end loop;
Document.Writer.Write_Wide_Text (Text);
for I in reverse Format'Range loop
if Format (I) then
Document.Writer.End_Element (HTML_ELEMENT (I).all);
end if;
end loop;
end Add_Text;
-- ------------------------------
-- Add a text block that is pre-formatted.
-- ------------------------------
procedure Add_Preformatted (Document : in out Html_Renderer;
Text : in Unbounded_Wide_Wide_String;
Format : in Unbounded_Wide_Wide_String) is
begin
Document.Close_Paragraph;
if Format = "html" then
Document.Writer.Write (Text);
else
Document.Writer.Start_Element ("pre");
Document.Writer.Write_Wide_Text (Text);
Document.Writer.End_Element ("pre");
end if;
end Add_Preformatted;
-- ------------------------------
-- Finish the document after complete wiki text has been parsed.
-- ------------------------------
overriding
procedure Finish (Document : in out Html_Renderer) is
begin
Document.Close_Paragraph;
Document.Add_Blockquote (0);
end Finish;
end Wiki.Render.Html;
|
Implement the HTML renderer
|
Implement the HTML renderer
|
Ada
|
apache-2.0
|
stcarrez/ada-wiki,stcarrez/ada-wiki
|
|
be60c247771279b8feed76e5e5494f8720ad9bf7
|
src/wiki-render-text.ads
|
src/wiki-render-text.ads
|
-----------------------------------------------------------------------
-- wiki-render-text -- Wiki Text renderer
-- Copyright (C) 2011, 2012, 2013, 2015 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Wide_Wide_Unbounded;
with Wiki.Documents;
with Wiki.Writers;
-- == Text Renderer ==
-- The <tt>Text_Renderer</tt> allows to render a wiki document into a text content.
-- The formatting rules are ignored except for the paragraphs and sections.
package Wiki.Render.Text is
use Ada.Strings.Wide_Wide_Unbounded;
-- ------------------------------
-- Wiki to Text renderer
-- ------------------------------
type Text_Renderer is new Wiki.Documents.Document_Reader with private;
-- Set the output writer.
procedure Set_Writer (Document : in out Text_Renderer;
Writer : in Wiki.Writers.Writer_Type_Access);
-- Add a section header in the document.
overriding
procedure Add_Header (Document : in out Text_Renderer;
Header : in Unbounded_Wide_Wide_String;
Level : in Positive);
-- Add a line break (<br>).
overriding
procedure Add_Line_Break (Document : in out Text_Renderer);
-- Add a paragraph (<p>). Close the previous paragraph if any.
-- The paragraph must be closed at the next paragraph or next header.
overriding
procedure Add_Paragraph (Document : in out Text_Renderer);
-- Add a blockquote (<blockquote>). The level indicates the blockquote nested level.
-- The blockquote must be closed at the next header.
overriding
procedure Add_Blockquote (Document : in out Text_Renderer;
Level : in Natural);
-- Add a list item (<li>). Close the previous paragraph and list item if any.
-- The list item will be closed at the next list item, next paragraph or next header.
overriding
procedure Add_List_Item (Document : in out Text_Renderer;
Level : in Positive;
Ordered : in Boolean);
-- Add an horizontal rule (<hr>).
overriding
procedure Add_Horizontal_Rule (Document : in out Text_Renderer);
-- Add a link.
overriding
procedure Add_Link (Document : in out Text_Renderer;
Name : in Unbounded_Wide_Wide_String;
Link : in Unbounded_Wide_Wide_String;
Language : in Unbounded_Wide_Wide_String;
Title : in Unbounded_Wide_Wide_String);
-- Add an image.
overriding
procedure Add_Image (Document : in out Text_Renderer;
Link : in Unbounded_Wide_Wide_String;
Alt : in Unbounded_Wide_Wide_String;
Position : in Unbounded_Wide_Wide_String;
Description : in Unbounded_Wide_Wide_String);
-- Add a quote.
overriding
procedure Add_Quote (Document : in out Text_Renderer;
Quote : in Unbounded_Wide_Wide_String;
Link : in Unbounded_Wide_Wide_String;
Language : in Unbounded_Wide_Wide_String);
-- Add a text block with the given format.
overriding
procedure Add_Text (Document : in out Text_Renderer;
Text : in Unbounded_Wide_Wide_String;
Format : in Wiki.Documents.Format_Map);
-- Add a text block that is pre-formatted.
procedure Add_Preformatted (Document : in out Text_Renderer;
Text : in Unbounded_Wide_Wide_String;
Format : in Unbounded_Wide_Wide_String);
-- Finish the document after complete wiki text has been parsed.
overriding
procedure Finish (Document : in out Text_Renderer);
private
procedure Close_Paragraph (Document : in out Text_Renderer);
procedure Open_Paragraph (Document : in out Text_Renderer);
type Text_Renderer is new Wiki.Documents.Document_Reader with record
Writer : Wiki.Writers.Writer_Type_Access := null;
Format : Wiki.Documents.Format_Map := (others => False);
Has_Paragraph : Boolean := False;
Need_Paragraph : Boolean := False;
Empty_Line : Boolean := True;
end record;
end Wiki.Render.Text;
|
Define the Wiki.Render.Text package with the Text_Renderer type and the operations for the wiki rendering
|
Define the Wiki.Render.Text package with the Text_Renderer type and
the operations for the wiki rendering
|
Ada
|
apache-2.0
|
stcarrez/ada-wiki,stcarrez/ada-wiki
|
|
79c3b35c13d4922d3860d15adc4692fcd1e5d4ba
|
src/asis/a4g-a_osint.adb
|
src/asis/a4g-a_osint.adb
|
------------------------------------------------------------------------------
-- --
-- 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;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
stcarrez/dynamo,stcarrez/dynamo,stcarrez/dynamo
|
|
f0e8b7d4d61901ad0a0b67648f79a7a7be59212e
|
awa/plugins/awa-workspaces/regtests/awa-workspaces-tests.adb
|
awa/plugins/awa-workspaces/regtests/awa-workspaces-tests.adb
|
-----------------------------------------------------------------------
-- awa-workspaces-tests -- Unit tests for workspaces and invitations
-- Copyright (C) 2017 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 Util.Test_Caller;
with Util.Strings;
with ADO;
with ASF.Requests.Mockup;
with ASF.Responses.Mockup;
with ASF.Principals;
with ASF.Helpers.Beans;
with ASF.Tests;
with AWA.Users.Models;
with AWA.Services.Contexts;
with AWA.Tests.Helpers.Users;
with Security.Contexts;
with AWA.Workspaces.Beans;
package body AWA.Workspaces.Tests is
use Ada.Strings.Unbounded;
use AWA.Tests;
function Get_Invitation_Bean is
new ASF.Helpers.Beans.Get_Request_Bean (Element_Type => Beans.Invitation_Bean,
Element_Access => Beans.Invitation_Bean_Access);
package Caller is new Util.Test_Caller (Test, "Workspaces.Beans");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test AWA.Workspaces.Beans.Send",
Test_Invite_User'Access);
end Add_Tests;
-- ------------------------------
-- Get some access on the blog as anonymous users.
-- ------------------------------
procedure Verify_Anonymous (T : in out Test;
Key : in String) is
Request : ASF.Requests.Mockup.Request;
Reply : ASF.Responses.Mockup.Response;
begin
ASF.Tests.Do_Get (Request, Reply, "/auth/invitation.html", "invitation-view.html");
ASF.Tests.Assert_Contains (T, "Blog posts", Reply, "This invitation is invalid");
ASF.Tests.Do_Get (Request, Reply, "/auth/invitation.html?key=test", "invitation-bad.html");
ASF.Tests.Assert_Contains (T, "Tag - test", Reply, "Blog tag page is invalid");
ASF.Tests.Do_Get (Request, Reply, "/auth/invitation.html?key=x" & key,
"invitation-bad2.html");
ASF.Tests.Assert_Contains (T, "The post you are looking for does not exist",
Reply, "Blog post missing page is invalid");
if Key = "" then
return;
end if;
ASF.Tests.Do_Get (Request, Reply, "/auth/invitation.html?key=" & Key, "invitation-ok.html");
ASF.Tests.Assert_Contains (T, "post-title", Reply, "Blog post page is invalid");
end Verify_Anonymous;
-- ------------------------------
-- Test sending an invitation.
-- ------------------------------
procedure Test_Invite_User (T : in out Test) is
use type ADO.Identifier;
use type AWA.Workspaces.Beans.Invitation_Bean_Access;
Request : ASF.Requests.Mockup.Request;
Reply : ASF.Responses.Mockup.Response;
Invite : AWA.Workspaces.Beans.Invitation_Bean_Access;
begin
AWA.Tests.Helpers.Users.Login ("[email protected]", Request);
Request.Set_Parameter ("email", "[email protected]");
Request.Set_Parameter ("message", "I invite you to this application");
Request.Set_Parameter ("send", "1");
Request.Set_Parameter ("invite", "1");
ASF.Tests.Do_Post (Request, Reply, "/workspaces/invite.html", "invite.html");
T.Assert (Reply.Get_Status = ASF.Responses.SC_OK,
"Invalid response after invitation creation");
-- Verify the invitation by looking at the inviteUser bean.
Invite := Get_Invitation_Bean (Request, "inviteUser");
T.Assert (Invite /= null, "Null inviteUser bean");
T.Assert (Invite.Get_Id /= ADO.NO_IDENTIFIER, "The invite ID is invalid");
T.Assert (not Invite.Get_Access_Key.Is_Null, "The invite access key is null");
end Test_Invite_User;
end AWA.Workspaces.Tests;
|
Add new tests for the invitation in a workspace
|
Add new tests for the invitation in a workspace
|
Ada
|
apache-2.0
|
stcarrez/ada-awa,stcarrez/ada-awa,stcarrez/ada-awa,stcarrez/ada-awa
|
|
e7e55a0ac7aabdf42e86137880f41cf952da6d6c
|
src/util-strings-sets.ads
|
src/util-strings-sets.ads
|
-----------------------------------------------------------------------
-- Util-strings-sets -- Set of strings
-- Copyright (C) 2011 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Hash;
with Ada.Containers.Indefinite_Hashed_Sets;
-- The <b>Util.Strings.Sets</b> package provides an instantiation
-- of a hashed set with Strings.
package Util.Strings.Sets is new Ada.Containers.Indefinite_Hashed_Sets
(Element_Type => String,
Hash => Ada.Strings.Hash,
Equivalent_Elements => "=");
|
Define the set of string package
|
Define the set of string package
|
Ada
|
apache-2.0
|
Letractively/ada-util,flottokarotto/ada-util,flottokarotto/ada-util,Letractively/ada-util
|
|
7f4043dd81a889bd097e48ef602271799da1854c
|
src/security-auth-openid.ads
|
src/security-auth-openid.ads
|
-----------------------------------------------------------------------
-- security-openid -- OpenID 2.0 Support
-- Copyright (C) 2009, 2010, 2011, 2012 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.
-----------------------------------------------------------------------
-- == OpenID ==
-- The <b>Security.OpenID</b> package implements an authentication framework based
-- on OpenID 2.0.
--
-- See OpenID Authentication 2.0 - Final
-- http://openid.net/specs/openid-authentication-2_0.html
--
-- There are basically two steps that an application must implement:
--
-- * <b>Discovery</b>: to resolve and use the OpenID provider and redirect the user to the
-- provider authentication form.
-- * <b>Verify</b>: to decode the authentication and check its result.
--
-- [http://ada-security.googlecode.com/svn/wiki/OpenID.png]
--
-- The authentication process is the following:
--
-- * The application should redirect the user to the authentication URL.
-- * The OpenID provider authenticate the user and redirects the user to the callback CB.
-- * The association is decoded from the callback parameter.
-- * The <b>Verify</b> procedure is called with the association to check the result and
-- obtain the authentication results.
--
-- === Initialization ===
-- The initialization process must be done before each two steps (discovery and verify).
-- The OpenID manager must be declared and configured.
--
-- Mgr : Security.OpenID.Manager;
--
-- For the configuration, the <b>Initialize</b> procedure is called to configure
-- the OpenID realm and set the OpenID return callback URL. The return callback
-- must be a valid URL that is based on the realm. Example:
--
-- Mgr.Initialize (Name => "http://app.site.com/auth",
-- Return_To => "http://app.site.com/auth/verify");
--
-- After this initialization, the OpenID manager can be used in the authentication process.
--
-- === Discovery: creating the authentication URL ===
-- The first step is to create an authentication URL to which the user must be redirected.
-- In this step, we have to create an OpenID manager, discover the OpenID provider,
-- do the association and get an <b>End_Point</b>. The OpenID provider is specified as an
-- URL, below is an example for Google OpenID:
--
-- Provider : constant String := "https://www.google.com/accounts/o8/id";
-- OP : Security.OpenID.End_Point;
-- Assoc : constant Security.OpenID.Association_Access := new Security.OpenID.Association;
--
-- The following steps are performed:
--
-- * The <b>Discover</b> procedure is called to retrieve from the OpenID provider the XRDS
-- stream and identify the provider. An <b>End_Point</b> is returned in <tt>OP</tt>.
-- * The <b>Associate</b> procedure is called to make the association with the <b>End_Point</b>.
-- The <b>Association</b> record holds session, and authentication.
--
-- Mgr.Discover (Provider, OP); -- Yadis discovery (get the XRDS file).
-- Mgr.Associate (OP, Assoc.all);-- Associate and get an end-point with a key.
--
-- After this first step, you must manage to save the association in the HTTP session.
-- Then you must redirect to the authentication URL that is obtained by using:
--
-- Auth_URL : constant String := Mgr.Get_Authentication_URL (OP, Assoc.all);
--
-- === Verify: acknowledge the authentication in the callback URL ===
-- The second step is done when the user has finished the authentication successfully or not.
-- For this step, the application must get back the association that was saved in the session.
-- It must also prepare a parameters object that allows the OpenID framework to get the
-- URI parameters from the return callback.
--
-- Assoc : Association_Access := ...; -- Get the association saved in the session.
-- Auth : OpenID.Authentication;
-- Params : Auth_Params;
--
-- The OpenID manager must be initialized and the <b>Verify</b> procedure is called with
-- the association, parameters and the authentication result. The <b>Get_Status</b> function
-- must be used to check that the authentication succeeded.
--
-- Mgr.Verify (Assoc.all, Params, Auth);
-- if Security.OpenID.Get_Status (Auth) = Security.OpenID.AUTHENTICATED then ... -- Success.
--
-- === Principal creation ===
-- After the user is successfully authenticated, a user principal can be created and saved in
-- the session. The user principal can then be used to assign permissions to that user and
-- enforce the application permissions using the security policy manger.
--
-- P : Security.OpenID.Principal_Access := Security.OpenID.Create_Principal (Auth);
--
private package Security.Auth.OpenID is
-- ------------------------------
-- OpenID Manager
-- ------------------------------
-- The <b>Manager</b> provides the core operations for the OpenID process.
type Manager is new Security.Auth.Manager with private;
-- Initialize the authentication realm.
overriding
procedure Initialize (Realm : in out Manager;
Params : in Parameters'Class;
Provider : in String := PROVIDER_OPENID);
-- Discover the OpenID provider that must be used to authenticate the user.
-- The <b>Name</b> can be an URL or an alias that identifies the provider.
-- A cached OpenID provider can be returned.
-- Read the XRDS document from the URI and initialize the OpenID provider end point.
-- (See OpenID Section 7.3 Discovery)
overriding
procedure Discover (Realm : in out Manager;
Name : in String;
Result : out End_Point);
-- Associate the application (relying party) with the OpenID provider.
-- The association can be cached.
-- (See OpenID Section 8 Establishing Associations)
overriding
procedure Associate (Realm : in out Manager;
OP : in End_Point;
Result : out Association);
overriding
function Get_Authentication_URL (Realm : in Manager;
OP : in End_Point;
Assoc : in Association) return String;
-- Verify the authentication result
overriding
procedure Verify (Realm : in out Manager;
Assoc : in Association;
Request : in Parameters'Class;
Result : out Authentication);
-- Verify the authentication result
procedure Verify_Discovered (Realm : in out Manager;
Assoc : in Association;
Request : in Parameters'Class;
Result : out Authentication);
-- Verify the signature part of the result
procedure Verify_Signature (Realm : in Manager;
Assoc : in Association;
Request : in Parameters'Class;
Result : in out Authentication);
-- Extract from the XRDS content the OpenID provider URI.
-- The default implementation is very basic as it returns the first <URI>
-- available in the stream without validating the XRDS document.
-- Raises the <b>Invalid_End_Point</b> exception if the URI cannot be found.
procedure Extract_XRDS (Realm : in out Manager;
Content : in String;
Result : out End_Point);
private
type Manager is new Security.Auth.Manager with record
Return_To : Unbounded_String;
Realm : Unbounded_String;
end record;
end Security.Auth.OpenID;
|
Refactor the OpenID authentication to be based on the generic authentication framework
|
Refactor the OpenID authentication to be based on the generic authentication framework
|
Ada
|
apache-2.0
|
stcarrez/ada-security
|
|
28396d1ed839e14d88f11c605d168d7eaa356df7
|
testutil/ahven/ahven-xml_runner.adb
|
testutil/ahven/ahven-xml_runner.adb
|
--
-- Copyright (c) 2007-2009 Tero Koskinen <[email protected]>
--
-- 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.
--
with Ada.Text_IO;
with Ada.Strings;
with Ada.Strings.Fixed;
with Ada.Strings.Maps;
with Ahven.Runner;
with Ahven_Compat;
with Ahven.AStrings;
package body Ahven.XML_Runner is
use Ada.Text_IO;
use Ada.Strings.Fixed;
use Ada.Strings.Maps;
use Ahven.Results;
use Ahven.Framework;
use Ahven.AStrings;
function Filter_String (Str : String) return String;
function Filter_String
(Str : String;
Map : Character_Mapping)
return String;
procedure Print_Test_Pass (File : File_Type;
Parent_Test : String;
Info : Result_Info);
procedure Print_Test_Failure (File : File_Type;
Parent_Test : String;
Info : Result_Info);
procedure Print_Test_Error (File : File_Type;
Parent_Test : String;
Info : Result_Info);
procedure Print_Test_Case (Collection : Result_Collection;
Dir : String);
procedure Print_Log_File (File : File_Type; Filename : String);
procedure Print_Attribute (File : File_Type; Attr : String;
Value : String);
procedure Start_Testcase_Tag (File : File_Type;
Parent : String; Name : String;
Execution_Time : String);
procedure End_Testcase_Tag (File : File_Type);
function Create_Name (Dir : String; Name : String) return String;
function Filter_String (Str : String) return String is
Result : String (Str'First .. Str'First + 6 * Str'Length);
Pos : Natural := Str'First;
begin
for I in Str'Range loop
if Str (I) = ''' then
Result (Pos .. Pos + 6 - 1) := "'";
Pos := Pos + 6;
elsif Str (I) = '<' then
Result (Pos .. Pos + 4 - 1) := "<";
Pos := Pos + 4;
elsif Str (I) = '>' then
Result (Pos .. Pos + 4 - 1) := ">";
Pos := Pos + 4;
elsif Str (I) = '&' then
Result (Pos .. Pos + 5 - 1) := "&";
Pos := Pos + 5;
else
Result (Pos) := Str (I);
Pos := Pos + 1;
end if;
end loop;
return Result (Result'First .. Pos - 1);
end Filter_String;
function Filter_String
(Str : String;
Map : Character_Mapping)
return String
is
begin
return Translate (Source => Str,
Mapping => Map);
end Filter_String;
procedure Print_Attribute (File : File_Type; Attr : String;
Value : String) is
begin
Put (File, Attr & "=" & '"' & Value & '"');
end Print_Attribute;
procedure Start_Testcase_Tag (File : File_Type;
Parent : String; Name : String;
Execution_Time : String) is
begin
Put (File, "<testcase ");
Print_Attribute (File, "classname", Filter_String (Parent));
Put (File, " ");
Print_Attribute (File, "name", Filter_String (Name));
Put (File, " ");
Print_Attribute (File, "time", Filter_String (Execution_Time));
Put_Line (File, ">");
end Start_Testcase_Tag;
procedure End_Testcase_Tag (File : File_Type) is
begin
Put_Line (File, "</testcase>");
end End_Testcase_Tag;
function Create_Name (Dir : String; Name : String) return String
is
function Filename (Test : String) return String is
Map : Ada.Strings.Maps.Character_Mapping;
begin
Map := To_Mapping (From => " '/\<>:|?*()" & '"',
To => "-___________" & '_');
return "TEST-" & Filter_String (Test, Map) & ".xml";
end Filename;
begin
if Dir'Length > 0 then
return Dir & Ahven_Compat.Directory_Separator & Filename (Name);
else
return Filename (Name);
end if;
end Create_Name;
procedure Print_Test_Pass (File : File_Type;
Parent_Test : String;
Info : Result_Info) is
Exec_Time : constant String :=
Trim (Duration'Image (Get_Execution_Time (Info)), Ada.Strings.Both);
begin
Start_Testcase_Tag
(File => File,
Parent => Parent_Test,
Name => Get_Routine_Name (Info),
Execution_Time => Exec_Time);
if Length (Get_Output_File (Info)) > 0 then
Put (File, "<system-out>");
Print_Log_File (File, To_String (Get_Output_File (Info)));
Put_Line (File, "</system-out>");
end if;
End_Testcase_Tag (File);
end Print_Test_Pass;
procedure Print_Test_Skipped (File : File_Type;
Parent_Test : String;
Info : Result_Info) is
Exec_Time : constant String :=
Trim (Duration'Image (Get_Execution_Time (Info)), Ada.Strings.Both);
begin
Start_Testcase_Tag
(File => File,
Parent => Parent_Test,
Name => Get_Routine_Name (Info),
Execution_Time => Exec_Time);
Put (File, "<skipped ");
Print_Attribute (File, "message",
Filter_String (Trim (Get_Message (Info), Ada.Strings.Both)));
Put (File, ">");
Put_Line (File, Get_Message (Info));
Put_Line (File, "</skipped>");
End_Testcase_Tag (File);
end Print_Test_Skipped;
procedure Print_Test_Failure (File : File_Type;
Parent_Test : String;
Info : Result_Info) is
Exec_Time : constant String :=
Trim (Duration'Image (Get_Execution_Time (Info)), Ada.Strings.Both);
begin
Start_Testcase_Tag
(File => File,
Parent => Parent_Test,
Name => Get_Routine_Name (Info),
Execution_Time => Exec_Time);
Put (File, "<failure ");
Print_Attribute (File, "type",
Filter_String (Trim (Get_Message (Info), Ada.Strings.Both)));
Put (File, ">");
Put_Line (File, Get_Message (Info));
Put_Line (File, "</failure>");
if Length (Get_Output_File (Info)) > 0 then
Put (File, "<system-out>");
Print_Log_File (File, To_String (Get_Output_File (Info)));
Put_Line (File, "</system-out>");
end if;
End_Testcase_Tag (File);
end Print_Test_Failure;
procedure Print_Test_Error (File : File_Type;
Parent_Test : String;
Info : Result_Info) is
Exec_Time : constant String :=
Trim (Duration'Image (Get_Execution_Time (Info)), Ada.Strings.Both);
begin
Start_Testcase_Tag
(File => File,
Parent => Parent_Test,
Name => Get_Routine_Name (Info),
Execution_Time => Exec_Time);
Put (File, "<error ");
Print_Attribute (File, "type",
Trim (Get_Message (Info), Ada.Strings.Both));
Put (File, ">");
Put_Line (File, Get_Message (Info));
Put_Line (File, "</error>");
if Length (Get_Output_File (Info)) > 0 then
Put (File, "<system-out>");
Print_Log_File (File, To_String (Get_Output_File (Info)));
Put_Line (File, "</system-out>");
end if;
End_Testcase_Tag (File);
end Print_Test_Error;
procedure Print_Test_Case (Collection : Result_Collection;
Dir : String) is
procedure Print (Output : File_Type;
Result : Result_Collection);
-- Internal procedure to print the testcase into given file.
function Img (Value : Natural) return String is
begin
return Trim (Natural'Image (Value), Ada.Strings.Both);
end Img;
procedure Print (Output : File_Type;
Result : Result_Collection) is
Position : Result_Info_Cursor;
begin
Put_Line (Output, "<?xml version=" & '"' & "1.0" & '"' &
" encoding=" & '"' & "iso-8859-1" & '"' &
"?>");
Put (Output, "<testsuite ");
Print_Attribute (Output, "errors", Img (Error_Count (Result)));
Put (Output, " ");
Print_Attribute (Output, "failures", Img (Failure_Count (Result)));
Put (Output, " ");
Print_Attribute (Output, "skips", Img (Skipped_Count (Result)));
Put (Output, " ");
Print_Attribute (Output, "tests", Img (Test_Count (Result)));
Put (Output, " ");
Print_Attribute (Output, "time",
Trim (Duration'Image (Get_Execution_Time (Result)),
Ada.Strings.Both));
Put (Output, " ");
Print_Attribute (Output,
"name", To_String (Get_Test_Name (Result)));
Put_Line (Output, ">");
Position := First_Error (Result);
Error_Loop:
loop
exit Error_Loop when not Is_Valid (Position);
Print_Test_Error (Output,
To_String (Get_Test_Name (Result)), Data (Position));
Position := Next (Position);
end loop Error_Loop;
Position := First_Failure (Result);
Failure_Loop:
loop
exit Failure_Loop when not Is_Valid (Position);
Print_Test_Failure (Output,
To_String (Get_Test_Name (Result)), Data (Position));
Position := Next (Position);
end loop Failure_Loop;
Position := First_Pass (Result);
Pass_Loop:
loop
exit Pass_Loop when not Is_Valid (Position);
Print_Test_Pass (Output,
To_String (Get_Test_Name (Result)), Data (Position));
Position := Next (Position);
end loop Pass_Loop;
Position := First_Skipped (Result);
Skip_Loop:
loop
exit Skip_Loop when not Is_Valid (Position);
Print_Test_Skipped (Output,
To_String (Get_Test_Name (Result)), Data (Position));
Position := Next (Position);
end loop Skip_Loop;
Put_Line (Output, "</testsuite>");
end Print;
File : File_Type;
begin
if Dir = "-" then
Print (Standard_Output, Collection);
else
Create (File => File, Mode => Ada.Text_IO.Out_File,
Name => Create_Name (Dir, To_String (Get_Test_Name (Collection))));
Print (File, Collection);
Ada.Text_IO.Close (File);
end if;
end Print_Test_Case;
procedure Report_Results (Result : Result_Collection;
Dir : String) is
Position : Result_Collection_Cursor;
begin
Position := First_Child (Result);
loop
exit when not Is_Valid (Position);
if Child_Depth (Data (Position).all) = 0 then
Print_Test_Case (Data (Position).all, Dir);
else
Report_Results (Data (Position).all, Dir);
-- Handle the test cases in this collection
if Direct_Test_Count (Result) > 0 then
Print_Test_Case (Result, Dir);
end if;
end if;
Position := Next (Position);
end loop;
end Report_Results;
-- Print the log by placing the data inside CDATA block.
procedure Print_Log_File (File : File_Type; Filename : String) is
type CData_End_State is (NONE, FIRST_BRACKET, SECOND_BRACKET);
function State_Change (Old_State : CData_End_State)
return CData_End_State;
Handle : File_Type;
Char : Character := ' ';
First : Boolean := True;
-- We need to escape ]]>, this variable tracks
-- the characters, so we know when to do the escaping.
CData_Ending : CData_End_State := NONE;
function State_Change (Old_State : CData_End_State)
return CData_End_State
is
New_State : CData_End_State := NONE;
-- By default New_State will be NONE, so there is
-- no need to set it inside when blocks.
begin
case Old_State is
when NONE =>
if Char = ']' then
New_State := FIRST_BRACKET;
end if;
when FIRST_BRACKET =>
if Char = ']' then
New_State := SECOND_BRACKET;
end if;
when SECOND_BRACKET =>
if Char = '>' then
Put (File, " ");
end if;
end case;
return New_State;
end State_Change;
begin
Open (Handle, In_File, Filename);
loop
exit when End_Of_File (Handle);
Get (Handle, Char);
if First then
Put (File, "<![CDATA[");
First := False;
end if;
CData_Ending := State_Change (CData_Ending);
Put (File, Char);
if End_Of_Line (Handle) then
New_Line (File);
end if;
end loop;
Close (Handle);
if not First then
Put_Line (File, "]]>");
end if;
end Print_Log_File;
procedure Do_Report (Test_Results : Results.Result_Collection;
Args : Parameters.Parameter_Info) is
begin
Report_Results (Test_Results,
Parameters.Result_Dir (Args));
end Do_Report;
procedure Run (Suite : in out Framework.Test_Suite'Class) is
begin
Runner.Run_Suite (Suite, Do_Report'Access);
end Run;
procedure Run (Suite : Framework.Test_Suite_Access) is
begin
Run (Suite.all);
end Run;
end Ahven.XML_Runner;
|
--
-- Copyright (c) 2007-2009 Tero Koskinen <[email protected]>
--
-- 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.
--
with Ada.Text_IO;
with Ada.Strings;
with Ada.Strings.Fixed;
with Ada.Strings.Maps;
with Ahven.Runner;
with Ahven_Compat;
with Ahven.AStrings;
package body Ahven.XML_Runner is
use Ada.Text_IO;
use Ada.Strings.Fixed;
use Ada.Strings.Maps;
use Ahven.Results;
use Ahven.Framework;
use Ahven.AStrings;
function Filter_String (Str : String) return String;
function Filter_String
(Str : String;
Map : Character_Mapping)
return String;
procedure Print_Test_Pass (File : File_Type;
Parent_Test : String;
Info : Result_Info);
procedure Print_Test_Failure (File : File_Type;
Parent_Test : String;
Info : Result_Info);
procedure Print_Test_Error (File : File_Type;
Parent_Test : String;
Info : Result_Info);
procedure Print_Test_Case (Collection : Result_Collection;
Dir : String);
procedure Print_Log_File (File : File_Type; Filename : String);
procedure Print_Attribute (File : File_Type; Attr : String;
Value : String);
procedure Start_Testcase_Tag (File : File_Type;
Parent : String; Name : String;
Execution_Time : String);
procedure End_Testcase_Tag (File : File_Type);
function Create_Name (Dir : String; Name : String) return String;
function Filter_String (Str : String) return String is
Result : String (Str'First .. Str'First + 6 * Str'Length);
Pos : Natural := Str'First;
begin
for I in Str'Range loop
if Str (I) = ''' then
Result (Pos .. Pos + 6 - 1) := "'";
Pos := Pos + 6;
elsif Str (I) = '<' then
Result (Pos .. Pos + 4 - 1) := "<";
Pos := Pos + 4;
elsif Str (I) = '>' then
Result (Pos .. Pos + 4 - 1) := ">";
Pos := Pos + 4;
elsif Str (I) = '&' then
Result (Pos .. Pos + 5 - 1) := "&";
Pos := Pos + 5;
elsif Str (I) = '"' then
Result (Pos) := ''';
Pos := Pos + 1;
else
Result (Pos) := Str (I);
Pos := Pos + 1;
end if;
end loop;
return Result (Result'First .. Pos - 1);
end Filter_String;
function Filter_String
(Str : String;
Map : Character_Mapping)
return String
is
begin
return Translate (Source => Str,
Mapping => Map);
end Filter_String;
procedure Print_Attribute (File : File_Type; Attr : String;
Value : String) is
begin
Put (File, Attr & "=" & '"' & Value & '"');
end Print_Attribute;
procedure Start_Testcase_Tag (File : File_Type;
Parent : String; Name : String;
Execution_Time : String) is
begin
Put (File, "<testcase ");
Print_Attribute (File, "classname", Filter_String (Parent));
Put (File, " ");
Print_Attribute (File, "name", Filter_String (Name));
Put (File, " ");
Print_Attribute (File, "time", Filter_String (Execution_Time));
Put_Line (File, ">");
end Start_Testcase_Tag;
procedure End_Testcase_Tag (File : File_Type) is
begin
Put_Line (File, "</testcase>");
end End_Testcase_Tag;
function Create_Name (Dir : String; Name : String) return String
is
function Filename (Test : String) return String is
Map : Ada.Strings.Maps.Character_Mapping;
begin
Map := To_Mapping (From => " '/\<>:|?*()" & '"',
To => "-___________" & '_');
return "TEST-" & Filter_String (Test, Map) & ".xml";
end Filename;
begin
if Dir'Length > 0 then
return Dir & Ahven_Compat.Directory_Separator & Filename (Name);
else
return Filename (Name);
end if;
end Create_Name;
procedure Print_Test_Pass (File : File_Type;
Parent_Test : String;
Info : Result_Info) is
Exec_Time : constant String :=
Trim (Duration'Image (Get_Execution_Time (Info)), Ada.Strings.Both);
begin
Start_Testcase_Tag
(File => File,
Parent => Parent_Test,
Name => Get_Routine_Name (Info),
Execution_Time => Exec_Time);
if Length (Get_Output_File (Info)) > 0 then
Put (File, "<system-out>");
Print_Log_File (File, To_String (Get_Output_File (Info)));
Put_Line (File, "</system-out>");
end if;
End_Testcase_Tag (File);
end Print_Test_Pass;
procedure Print_Test_Skipped (File : File_Type;
Parent_Test : String;
Info : Result_Info) is
Exec_Time : constant String :=
Trim (Duration'Image (Get_Execution_Time (Info)), Ada.Strings.Both);
begin
Start_Testcase_Tag
(File => File,
Parent => Parent_Test,
Name => Get_Routine_Name (Info),
Execution_Time => Exec_Time);
Put (File, "<skipped ");
Print_Attribute (File, "message",
Filter_String (Trim (Get_Message (Info), Ada.Strings.Both)));
Put (File, ">");
Put_Line (File, Get_Message (Info));
Put_Line (File, "</skipped>");
End_Testcase_Tag (File);
end Print_Test_Skipped;
procedure Print_Test_Failure (File : File_Type;
Parent_Test : String;
Info : Result_Info) is
Exec_Time : constant String :=
Trim (Duration'Image (Get_Execution_Time (Info)), Ada.Strings.Both);
begin
Start_Testcase_Tag
(File => File,
Parent => Parent_Test,
Name => Get_Routine_Name (Info),
Execution_Time => Exec_Time);
Put (File, "<failure ");
Print_Attribute (File, "type",
Filter_String (Trim (Get_Message (Info), Ada.Strings.Both)));
Put (File, ">");
Put_Line (File, Get_Message (Info));
Put_Line (File, "</failure>");
if Length (Get_Output_File (Info)) > 0 then
Put (File, "<system-out>");
Print_Log_File (File, To_String (Get_Output_File (Info)));
Put_Line (File, "</system-out>");
end if;
End_Testcase_Tag (File);
end Print_Test_Failure;
procedure Print_Test_Error (File : File_Type;
Parent_Test : String;
Info : Result_Info) is
Exec_Time : constant String :=
Trim (Duration'Image (Get_Execution_Time (Info)), Ada.Strings.Both);
begin
Start_Testcase_Tag
(File => File,
Parent => Parent_Test,
Name => Get_Routine_Name (Info),
Execution_Time => Exec_Time);
Put (File, "<error ");
Print_Attribute (File, "type",
Trim (Get_Message (Info), Ada.Strings.Both));
Put (File, ">");
Put_Line (File, Get_Message (Info));
Put_Line (File, "</error>");
if Length (Get_Output_File (Info)) > 0 then
Put (File, "<system-out>");
Print_Log_File (File, To_String (Get_Output_File (Info)));
Put_Line (File, "</system-out>");
end if;
End_Testcase_Tag (File);
end Print_Test_Error;
procedure Print_Test_Case (Collection : Result_Collection;
Dir : String) is
procedure Print (Output : File_Type;
Result : Result_Collection);
-- Internal procedure to print the testcase into given file.
function Img (Value : Natural) return String is
begin
return Trim (Natural'Image (Value), Ada.Strings.Both);
end Img;
procedure Print (Output : File_Type;
Result : Result_Collection) is
Position : Result_Info_Cursor;
begin
Put_Line (Output, "<?xml version=" & '"' & "1.0" & '"' &
" encoding=" & '"' & "iso-8859-1" & '"' &
"?>");
Put (Output, "<testsuite ");
Print_Attribute (Output, "errors", Img (Error_Count (Result)));
Put (Output, " ");
Print_Attribute (Output, "failures", Img (Failure_Count (Result)));
Put (Output, " ");
Print_Attribute (Output, "skips", Img (Skipped_Count (Result)));
Put (Output, " ");
Print_Attribute (Output, "tests", Img (Test_Count (Result)));
Put (Output, " ");
Print_Attribute (Output, "time",
Trim (Duration'Image (Get_Execution_Time (Result)),
Ada.Strings.Both));
Put (Output, " ");
Print_Attribute (Output,
"name", To_String (Get_Test_Name (Result)));
Put_Line (Output, ">");
Position := First_Error (Result);
Error_Loop:
loop
exit Error_Loop when not Is_Valid (Position);
Print_Test_Error (Output,
To_String (Get_Test_Name (Result)), Data (Position));
Position := Next (Position);
end loop Error_Loop;
Position := First_Failure (Result);
Failure_Loop:
loop
exit Failure_Loop when not Is_Valid (Position);
Print_Test_Failure (Output,
To_String (Get_Test_Name (Result)), Data (Position));
Position := Next (Position);
end loop Failure_Loop;
Position := First_Pass (Result);
Pass_Loop:
loop
exit Pass_Loop when not Is_Valid (Position);
Print_Test_Pass (Output,
To_String (Get_Test_Name (Result)), Data (Position));
Position := Next (Position);
end loop Pass_Loop;
Position := First_Skipped (Result);
Skip_Loop:
loop
exit Skip_Loop when not Is_Valid (Position);
Print_Test_Skipped (Output,
To_String (Get_Test_Name (Result)), Data (Position));
Position := Next (Position);
end loop Skip_Loop;
Put_Line (Output, "</testsuite>");
end Print;
File : File_Type;
begin
if Dir = "-" then
Print (Standard_Output, Collection);
else
Create (File => File, Mode => Ada.Text_IO.Out_File,
Name => Create_Name (Dir, To_String (Get_Test_Name (Collection))));
Print (File, Collection);
Ada.Text_IO.Close (File);
end if;
end Print_Test_Case;
procedure Report_Results (Result : Result_Collection;
Dir : String) is
Position : Result_Collection_Cursor;
begin
Position := First_Child (Result);
loop
exit when not Is_Valid (Position);
if Child_Depth (Data (Position).all) = 0 then
Print_Test_Case (Data (Position).all, Dir);
else
Report_Results (Data (Position).all, Dir);
-- Handle the test cases in this collection
if Direct_Test_Count (Result) > 0 then
Print_Test_Case (Result, Dir);
end if;
end if;
Position := Next (Position);
end loop;
end Report_Results;
-- Print the log by placing the data inside CDATA block.
procedure Print_Log_File (File : File_Type; Filename : String) is
type CData_End_State is (NONE, FIRST_BRACKET, SECOND_BRACKET);
function State_Change (Old_State : CData_End_State)
return CData_End_State;
Handle : File_Type;
Char : Character := ' ';
First : Boolean := True;
-- We need to escape ]]>, this variable tracks
-- the characters, so we know when to do the escaping.
CData_Ending : CData_End_State := NONE;
function State_Change (Old_State : CData_End_State)
return CData_End_State
is
New_State : CData_End_State := NONE;
-- By default New_State will be NONE, so there is
-- no need to set it inside when blocks.
begin
case Old_State is
when NONE =>
if Char = ']' then
New_State := FIRST_BRACKET;
end if;
when FIRST_BRACKET =>
if Char = ']' then
New_State := SECOND_BRACKET;
end if;
when SECOND_BRACKET =>
if Char = '>' then
Put (File, " ");
end if;
end case;
return New_State;
end State_Change;
begin
Open (Handle, In_File, Filename);
loop
exit when End_Of_File (Handle);
Get (Handle, Char);
if First then
Put (File, "<![CDATA[");
First := False;
end if;
CData_Ending := State_Change (CData_Ending);
Put (File, Char);
if End_Of_Line (Handle) then
New_Line (File);
end if;
end loop;
Close (Handle);
if not First then
Put_Line (File, "]]>");
end if;
end Print_Log_File;
procedure Do_Report (Test_Results : Results.Result_Collection;
Args : Parameters.Parameter_Info) is
begin
Report_Results (Test_Results,
Parameters.Result_Dir (Args));
end Do_Report;
procedure Run (Suite : in out Framework.Test_Suite'Class) is
begin
Runner.Run_Suite (Suite, Do_Report'Access);
end Run;
procedure Run (Suite : Framework.Test_Suite_Access) is
begin
Run (Suite.all);
end Run;
end Ahven.XML_Runner;
|
Fix XML generation if a message contains a " (double quote). This terminates the attribute...
|
Fix XML generation if a message contains a " (double quote).
This terminates the attribute...
|
Ada
|
apache-2.0
|
Letractively/ada-util,flottokarotto/ada-util,Letractively/ada-util,flottokarotto/ada-util
|
90335adc119a8853c0c16f85b6e466d69606f467
|
src/asis/asis-ada_environments-containers.ads
|
src/asis/asis-ada_environments-containers.ads
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT INTERFACE COMPONENTS --
-- --
-- A S I S . A D A _ E N V I R O N M E N T S . C O N T A I N E R S --
-- --
-- S p e c --
-- --
-- Copyright (c) 1995-2006, Free Software Foundation, Inc. --
-- --
-- This specification is derived from the Ada Semantic Interface --
-- Specification Standard (ISO/IEC 15291) for use with GNAT. The copyright --
-- notice above, and the license provisions that follow apply solely to the --
-- contents of the part following the private keyword. --
-- --
-- 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- 9 package Asis.Ada_Environments.Containers
------------------------------------------------------------------------------
------------------------------------------------------------------------------
package Asis.Ada_Environments.Containers is
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Asis.Ada_Environments.Containers
--
-- If an Ada implementation supports the notion of a program library or
-- "library" as specified in Subclause 10(2) of the Ada Reference Manual,
-- then an ASIS Context value can be mapped onto one or more implementor
-- libraries represented by Containers.
--
------------------------------------------------------------------------------
-- 9.1 type Container
------------------------------------------------------------------------------
--
-- The Container abstraction is a logical collection of compilation units.
-- For example, one container might hold compilation units which include Ada
-- predefined library units, another container might hold
-- implementation-defined packages. Alternatively, there might be 26
-- containers, each holding compilation units that begin with their respective
-- letter of the alphabet. The point is that no implementation-independent
-- semantics are associated with a container; it is simply a logical
-- collection.
--
-- ASIS implementations shall minimally map the Asis.Context to a list of
-- one ASIS Container whose Name is that of the Asis.Context Name.
------------------------------------------------------------------------------
type Container is private;
Nil_Container : constant Container;
function "="
(Left : Container;
Right : Container)
return Boolean is abstract;
------------------------------------------------------------------------------
-- 9.2 type Container_List
------------------------------------------------------------------------------
type Container_List is array (List_Index range <>) of Container;
------------------------------------------------------------------------------
-- 9.3 function Defining_Containers
------------------------------------------------------------------------------
function Defining_Containers
(The_Context : Asis.Context)
return Container_List;
------------------------------------------------------------------------------
-- The_Context - Specifies the Context to define
--
-- Returns a Container_List value that defines the single environment Context.
-- Each Container will have an Enclosing_Context that Is_Identical to the
-- argument The_Context. The order of Container values in the list is not
-- defined.
--
-- Returns a minimal list of length one if the ASIS Ada implementation does
-- not support the concept of a program library. In this case, the Container
-- will have the same name as the given Context.
--
-- Raises ASIS_Inappropriate_Context if The_Context is not open.
--
------------------------------------------------------------------------------
-- 9.4 function Enclosing_Context
------------------------------------------------------------------------------
function Enclosing_Context
(The_Container : Container)
return Asis.Context;
------------------------------------------------------------------------------
-- The_Container - Specifies the Container to query
--
-- Returns the Context value associated with the Container.
--
-- Returns the Context for which the Container value was originally obtained.
-- Container values obtained through the Defining_Containers query will always
-- remember the Context from which they were defined.
--
-- Because Context is limited private, this function is only intended to be
-- used to supply a Context parameter for other queries.
--
-- Raises ASIS_Inappropriate_Container if the Container is a Nil_Container.
--
------------------------------------------------------------------------------
-- 9.5 function Library_Unit_Declaration
------------------------------------------------------------------------------
function Library_Unit_Declarations
(The_Container : Container)
return Asis.Compilation_Unit_List;
------------------------------------------------------------------------------
-- The_Container - Specifies the Container to query
--
-- Returns a list of all library_unit_declaration and
-- library_unit_renaming_declaration elements contained in the Container.
-- Individual units will appear only once in an order that is not defined.
--
-- A Nil_Compilation_Unit_List is returned if there are no declarations of
-- library units within the Container.
--
-- This query will never return a unit with A_Configuration_Compilation or
-- a Nonexistent unit kind. It will never return a unit with A_Procedure_Body
-- or A_Function_Body unit kind even though the unit is interpreted as both
-- the declaration and body of a library procedure or library function.
-- (Reference Manual 10.1.4(4).
--
-- All units in the result will have an Enclosing_Container value that
-- Is_Identical to the Container.
--
-- Raises ASIS_Inappropriate_Context if the Enclosing_Context(Container)
-- is not open.
--
------------------------------------------------------------------------------
-- 9.6 function Compilation_Unit_Bodies
------------------------------------------------------------------------------
function Compilation_Unit_Bodies
(The_Container : Container)
return Asis.Compilation_Unit_List;
------------------------------------------------------------------------------
-- The_Container - Specifies the Container to query
--
-- Returns a list of all library_unit_body and subunit elements contained in
-- the Container. Individual units will appear only once in an order that is
-- not defined.
--
-- A Nil_Compilation_Unit_List is returned if there are no bodies within the
-- Container.
--
-- This query will never return a unit with A_Configuration_Compilation or
-- a nonexistent unit kind.
--
-- All units in the result will have an Enclosing_Container value that
-- Is_Identical to the Container.
--
-- Raises ASIS_Inappropriate_Context if the Enclosing_Context(Container)
-- is not open.
--
------------------------------------------------------------------------------
-- 9.7 function Compilation_Units
------------------------------------------------------------------------------
function Compilation_Units
(The_Container : Container)
return Asis.Compilation_Unit_List;
------------------------------------------------------------------------------
-- The_Container - Specifies the Container to query
--
-- Returns a list of all compilation units contained in the Container.
-- Individual units will appear only once in an order that is not defined.
--
-- A Nil_Compilation_Unit_List is returned if there are no units within the
-- Container.
--
-- This query will never return a unit with A_Configuration_Compilation or
-- a nonexistent unit kind.
--
-- All units in the result will have an Enclosing_Container value that
-- Is_Identical to the Container.
--
-- Raises ASIS_Inappropriate_Context if the Enclosing_Context(Container)
-- is not open.
--
------------------------------------------------------------------------------
-- 9.8 function Is_Equal
------------------------------------------------------------------------------
function Is_Equal
(Left : Container;
Right : Container)
return Boolean;
------------------------------------------------------------------------------
-- Left - Specifies the first Container
-- Right - Specifies the second Container
--
-- Returns True if Left and Right designate Container values that contain the
-- same set of compilation units. The Container values may have been defined
-- from different Context values.
--
------------------------------------------------------------------------------
-- 9.9 function Is_Identical
------------------------------------------------------------------------------
function Is_Identical
(Left : Container;
Right : Container)
return Boolean;
------------------------------------------------------------------------------
-- Left - Specifies the first Container
-- Right - Specifies the second Container
--
-- Returns True if Is_Equal(Left, Right) and the Container values have been
-- defined from Is_Equal Context values.
--
------------------------------------------------------------------------------
-- 9.10 function Name
------------------------------------------------------------------------------
function Name (The_Container : Container) return Wide_String;
------------------------------------------------------------------------------
-- The_Container - Specifies the Container to name
--
-- Returns the Name value associated with the Container.
--
-- Returns a null string if the Container is a Nil_Container.
private
type Container is record
Id : Container_Id := Nil_Container_Id;
Cont_Id : Context_Id := Non_Associated;
Obtained : ASIS_OS_Time := Nil_ASIS_OS_Time;
end record;
Nil_Container : constant Container :=
(Id => Nil_Container_Id,
Cont_Id => Non_Associated,
Obtained => Nil_ASIS_OS_Time);
end Asis.Ada_Environments.Containers;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen
|
|
52cd4d422cfb7359dd39931c847fcd8d27de4a97
|
mat/src/mat.adb
|
mat/src/mat.adb
|
-----------------------------------------------------------------------
-- mat -- Memory Analysis Tool
-- Copyright (C) 2014, 2021 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Log.Loggers;
with Util.Properties;
package body MAT is
-- ------------------------------
-- Configure the logs.
-- ------------------------------
procedure Configure_Logs (Debug : in Boolean;
Dump : in Boolean;
Verbose : in Boolean) is
Log_Config : Util.Properties.Manager;
begin
Log_Config.Set ("log4j.rootCategory", "ERROR,errorConsole");
Log_Config.Set ("log4j.appender.errorConsole", "aktConsole");
Log_Config.Set ("log4j.appender.errorConsole.level", "ERROR");
Log_Config.Set ("log4j.appender.errorConsole.layout", "message");
Log_Config.Set ("log4j.appender.errorConsole.stderr", "true");
Log_Config.Set ("log4j.logger.Util", "FATAL");
Log_Config.Set ("log4j.logger.Util.Events", "ERROR");
Log_Config.Set ("log4j.logger.Keystore", "ERROR");
Log_Config.Set ("log4j.logger.AKT", "ERROR");
if Verbose or Debug or Dump then
Log_Config.Set ("log4j.logger.Util", "WARN");
Log_Config.Set ("log4j.logger.AKT", "INFO");
Log_Config.Set ("log4j.logger.Keystore.IO", "WARN");
Log_Config.Set ("log4j.logger.Keystore", "INFO");
Log_Config.Set ("log4j.rootCategory", "INFO,errorConsole,verbose");
Log_Config.Set ("log4j.appender.verbose", "Console");
Log_Config.Set ("log4j.appender.verbose.level", "INFO");
Log_Config.Set ("log4j.appender.verbose.layout", "level-message");
end if;
if Debug or Dump then
Log_Config.Set ("log4j.logger.Util.Processes", "INFO");
Log_Config.Set ("log4j.logger.AKT", "DEBUG");
Log_Config.Set ("log4j.logger.Keystore.IO", "INFO");
Log_Config.Set ("log4j.logger.Keystore", "DEBUG");
Log_Config.Set ("log4j.rootCategory", "DEBUG,errorConsole,debug");
Log_Config.Set ("log4j.appender.debug", "Console");
Log_Config.Set ("log4j.appender.debug.level", "DEBUG");
Log_Config.Set ("log4j.appender.debug.layout", "full");
end if;
if Dump then
Log_Config.Set ("log4j.logger.Keystore.IO", "DEBUG");
end if;
Util.Log.Loggers.Initialize (Log_Config);
end Configure_Logs;
end MAT;
|
Implement Configure_Logs procedure
|
Implement Configure_Logs procedure
|
Ada
|
apache-2.0
|
stcarrez/mat,stcarrez/mat,stcarrez/mat
|
|
b55aa5c54f63ddd775b7f6b32631d38e03068cd1
|
regtests/asf-converters-tests.adb
|
regtests/asf-converters-tests.adb
|
-----------------------------------------------------------------------
-- Faces Context Tests - Unit tests for ASF.Contexts.Faces
-- Copyright (C) 2010, 2011, 2012, 2013 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Calendar;
with Ada.Calendar.Formatting;
with Util.Beans.Objects.Time;
with Util.Test_Caller;
with ASF.Tests;
with ASF.Components.Html.Text;
with ASF.Converters.Dates;
package body ASF.Converters.Tests is
use Util.Tests;
use ASF.Converters.Dates;
package Caller is new Util.Test_Caller (Test, "Converters");
procedure Test_Date_Conversion (T : in out Test;
Date_Style : in Dates.Style_Type;
Time_Style : in Dates.Style_Type;
Expect : in String);
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
-- To document what is tested, register the test methods for each
-- operation that is tested.
Caller.Add_Test (Suite, "Test ASF.Converters.Dates.To_String (Date, Short)",
Test_Date_Short_Converter'Access);
Caller.Add_Test (Suite, "Test ASF.Converters.Dates.To_String (Date, Medium)",
Test_Date_Medium_Converter'Access);
Caller.Add_Test (Suite, "Test ASF.Converters.Dates.To_String (Date, Long)",
Test_Date_Long_Converter'Access);
Caller.Add_Test (Suite, "Test ASF.Converters.Dates.To_String (Date, Full)",
Test_Date_Full_Converter'Access);
Caller.Add_Test (Suite, "Test ASF.Converters.Dates.To_String (Time, Short)",
Test_Time_Short_Converter'Access);
Caller.Add_Test (Suite, "Test ASF.Converters.Dates.To_String (Time, Medium)",
Test_Time_Medium_Converter'Access);
Caller.Add_Test (Suite, "Test ASF.Converters.Dates.To_String (Time, Long)",
Test_Time_Long_Converter'Access);
end Add_Tests;
-- ------------------------------
-- Test getting an attribute from the faces context.
-- ------------------------------
procedure Test_Date_Conversion (T : in out Test;
Date_Style : in Dates.Style_Type;
Time_Style : in Dates.Style_Type;
Expect : in String) is
Ctx : aliased ASF.Contexts.Faces.Faces_Context;
UI : ASF.Components.Html.Text.UIOutput;
C : ASF.Converters.Dates.Date_Converter_Access;
D : constant Ada.Calendar.Time := Ada.Calendar.Formatting.Time_Of (2011, 11, 19,
3, 4, 5);
begin
T.Setup (Ctx);
ASF.Contexts.Faces.Set_Current (Ctx'Unchecked_Access, ASF.Tests.Get_Application.all'Access);
if Date_Style = Dates.DEFAULT then
C := ASF.Converters.Dates.Create_Date_Converter (Date => Date_Style,
Time => Time_Style,
Format => ASF.Converters.Dates.TIME,
Locale => "en",
Pattern => "");
elsif Time_Style = Dates.DEFAULT then
C := ASF.Converters.Dates.Create_Date_Converter (Date => Date_Style,
Time => Time_Style,
Format => ASF.Converters.Dates.DATE,
Locale => "en",
Pattern => "");
else
C := ASF.Converters.Dates.Create_Date_Converter (Date => Date_Style,
Time => Time_Style,
Format => ASF.Converters.Dates.BOTH,
Locale => "en",
Pattern => "");
end if;
UI.Set_Converter (C.all'Access);
declare
R : constant String := C.To_String (Ctx, UI, Util.Beans.Objects.Time.To_Object (D));
begin
Util.Tests.Assert_Equals (T, Expect, R, "Invalid date conversion");
end;
end Test_Date_Conversion;
-- ------------------------------
-- Test the date short converter.
-- ------------------------------
procedure Test_Date_Short_Converter (T : in out Test) is
begin
Test_Date_Conversion (T, ASF.Converters.Dates.SHORT, ASF.Converters.Dates.DEFAULT,
"19/11/2011");
end Test_Date_Short_Converter;
-- ------------------------------
-- Test the date medium converter.
-- ------------------------------
procedure Test_Date_Medium_Converter (T : in out Test) is
begin
Test_Date_Conversion (T, ASF.Converters.Dates.MEDIUM, ASF.Converters.Dates.DEFAULT,
"Nov 19, 2011");
end Test_Date_Medium_Converter;
-- ------------------------------
-- Test the date long converter.
-- ------------------------------
procedure Test_Date_Long_Converter (T : in out Test) is
begin
Test_Date_Conversion (T, ASF.Converters.Dates.LONG, ASF.Converters.Dates.DEFAULT,
"November 19, 2011");
end Test_Date_Long_Converter;
-- ------------------------------
-- Test the date full converter.
-- ------------------------------
procedure Test_Date_Full_Converter (T : in out Test) is
begin
Test_Date_Conversion (T, ASF.Converters.Dates.FULL, ASF.Converters.Dates.DEFAULT,
"Saturday, November 19, 2011");
end Test_Date_Full_Converter;
-- ------------------------------
-- Test the time short converter.
-- ------------------------------
procedure Test_Time_Short_Converter (T : in out Test) is
begin
Test_Date_Conversion (T, ASF.Converters.Dates.DEFAULT, ASF.Converters.Dates.SHORT,
"03:04");
end Test_Time_Short_Converter;
-- ------------------------------
-- Test the time short converter.
-- ------------------------------
procedure Test_Time_Medium_Converter (T : in out Test) is
begin
Test_Date_Conversion (T, ASF.Converters.Dates.DEFAULT, ASF.Converters.Dates.MEDIUM,
"03:04");
end Test_Time_Medium_Converter;
-- ------------------------------
-- Test the time long converter.
-- ------------------------------
procedure Test_Time_Long_Converter (T : in out Test) is
begin
Test_Date_Conversion (T, ASF.Converters.Dates.DEFAULT, ASF.Converters.Dates.LONG,
"03:04:05");
end Test_Time_Long_Converter;
end ASF.Converters.Tests;
|
Implement some unit tests for date and time conversion
|
Implement some unit tests for date and time conversion
|
Ada
|
apache-2.0
|
stcarrez/ada-asf,stcarrez/ada-asf,stcarrez/ada-asf
|
|
308499888f5f31876b10335cf1c4e01a1b5051e7
|
regtests/util-beans-objects-datasets-tests.adb
|
regtests/util-beans-objects-datasets-tests.adb
|
-----------------------------------------------------------------------
-- util-beans-objects-datasets-tests -- Unit tests for dataset beans
-- Copyright (C) 2013 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Tests;
with Util.Test_Caller;
package body Util.Beans.Objects.Datasets.Tests is
package Caller is new Util.Test_Caller (Test, "Objects.Datasets");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test Util.Beans.Objects.Datasets",
Test_Fill_Dataset'Access);
end Add_Tests;
-- Test the creation, initialization and retrieval of dataset content.
procedure Test_Fill_Dataset (T : in out Test) is
Set : Dataset;
procedure Fill (Row : in out Object_Array) is
begin
Row (Row'First) := To_Object (String '("john"));
Row (Row'First + 1) := To_Object (String '("[email protected]"));
Row (Row'First + 2) := To_Object (Set.Get_Count);
end Fill;
begin
Set.Add_Column ("name");
Set.Add_Column ("email");
Set.Add_Column ("age");
for I in 1 .. 100 loop
Set.Append (Fill'Access);
end loop;
Util.Tests.Assert_Equals (T, 100, Set.Get_Count, "Invalid number of rows");
for I in 1 .. 100 loop
Set.Set_Row_Index (I);
declare
R : Object := Set.Get_Row;
begin
T.Assert (not Is_Null (R), "Row is null");
Util.Tests.Assert_Equals (T, "john", To_String (Get_Value (R, "name")),
"Invalid 'name' attribute");
Util.Tests.Assert_Equals (T, I, To_Integer (Get_Value (R, "age")),
"Invalid 'age' attribute");
end;
end loop;
end Test_Fill_Dataset;
end Util.Beans.Objects.Datasets.Tests;
|
Implement the unit tests on datasets to verify the creation, insertion and retrieval of datasets through bean interfaces
|
Implement the unit tests on datasets to verify the creation,
insertion and retrieval of datasets through bean interfaces
|
Ada
|
apache-2.0
|
Letractively/ada-util,flottokarotto/ada-util,flottokarotto/ada-util,Letractively/ada-util
|
|
20fa3451dd68782e0173e463ba7d00af886280d0
|
src/asis/asis-compilation_units-relations.adb
|
src/asis/asis-compilation_units-relations.adb
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A S I S . C O M P I L A T I O N _ U N I T S . R E L A T I O N S --
-- --
-- B o d y --
-- --
-- Copyright (c) 1995-2006, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
with Asis.Errors; use Asis.Errors;
with Asis.Exceptions; use Asis.Exceptions;
with Asis.Extensions; use Asis.Extensions;
with Asis.Set_Get; use Asis.Set_Get;
with A4G.Contt.Dp; use A4G.Contt.Dp;
with A4G.Vcheck; use A4G.Vcheck;
package body Asis.Compilation_Units.Relations is
Package_Name : constant String := "Asis.Compilation_Units.Relations.";
-----------------------
-- Elaboration_Order --
-----------------------
-- NOT IMPLEMENTED --
function Elaboration_Order
(Compilation_Units : Asis.Compilation_Unit_List;
The_Context : Asis.Context)
return Relationship
is
begin
Check_Validity (The_Context,
Package_Name & "Semantic_Dependence_Order");
if Is_Nil (Compilation_Units) then
return Nil_Relationship;
end if;
Not_Implemented_Yet (Diagnosis =>
Package_Name & "Semantic_Dependence_Order");
-- ASIS_Failed is raised, Not_Implemented_Error status is setted
return Nil_Relationship; -- to make the code syntactically correct
exception
when ASIS_Inappropriate_Context =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Semantic_Dependence_Order");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Semantic_Dependence_Order",
Ex => Ex);
end Elaboration_Order;
-------------------------------
-- Semantic_Dependence_Order --
-------------------------------
-- PARTIALLY IMPLEMENTED --
function Semantic_Dependence_Order
(Compilation_Units : Asis.Compilation_Unit_List;
Dependent_Units : Asis.Compilation_Unit_List;
The_Context : Asis.Context;
Relation : Asis.Relation_Kinds)
return Relationship
is
Res_Cont_Id : Context_Id;
Arg_Kind : Asis.Unit_Kinds;
Result_List : Compilation_Unit_List_Access;
Missing_List : Compilation_Unit_List_Access;
Missing_Len : ASIS_Natural := 0;
begin
Check_Validity (The_Context, Package_Name & "Semantic_Dependence_Order");
Res_Cont_Id := Get_Cont_Id (The_Context);
-- The current implementation limitation is that all the units from
-- Compilation_Units list and from Dependent_Units should be from
-- The_Context
for I in Compilation_Units'Range loop
Check_Validity (Compilation_Units (I),
Package_Name & "Semantic_Dependence_Order");
Arg_Kind := Kind (Compilation_Units (I));
if Arg_Kind = Not_A_Unit or else
Arg_Kind = A_Nonexistent_Declaration or else
Arg_Kind = A_Nonexistent_Body or else
Arg_Kind = A_Configuration_Compilation
then
Raise_ASIS_Inappropriate_Compilation_Unit (Diagnosis =>
Package_Name & "Semantic_Dependence_Order");
end if;
if Res_Cont_Id /= Encl_Cont_Id (Compilation_Units (I)) then
Not_Implemented_Yet (Diagnosis =>
Package_Name &
"Semantic_Dependence_Order (multi-context processing");
end if;
end loop;
for I in Dependent_Units'Range loop
Check_Validity (Dependent_Units (I),
Package_Name & "Semantic_Dependence_Order");
Arg_Kind := Kind (Dependent_Units (I));
if Arg_Kind = Not_A_Unit or else
Arg_Kind = A_Nonexistent_Declaration or else
Arg_Kind = A_Nonexistent_Body or else
Arg_Kind = A_Configuration_Compilation
then
Raise_ASIS_Inappropriate_Compilation_Unit (Diagnosis =>
Package_Name & "Semantic_Dependence_Order");
end if;
if Res_Cont_Id /= Encl_Cont_Id (Dependent_Units (I)) then
Not_Implemented_Yet (Diagnosis =>
Package_Name &
"Semantic_Dependence_Order (multi-context processing");
end if;
end loop;
if Is_Nil (Compilation_Units) then
return Nil_Relationship;
end if;
case Relation is
when Ancestors =>
Set_All_Ancestors (Compilation_Units, Result_List);
when Descendants =>
Set_All_Descendants (Compilation_Units, Result_List);
when Supporters =>
Set_All_Supporters (Compilation_Units, Result_List);
when Dependents =>
Set_All_Dependents
(Compilation_Units, Dependent_Units, Result_List);
when Family =>
Set_All_Families (Compilation_Units, Result_List);
when Needed_Units =>
Set_All_Needed_Units
(Compilation_Units, Result_List, Missing_List);
end case;
if Missing_List /= null then
Missing_Len := Missing_List'Length;
end if;
declare
Result : Relationship
(Consistent_Length => Result_List'Length,
Inconsistent_Length => 0,
Missing_Length => Missing_Len,
Circular_Length => 0);
begin
Result.Consistent := Result_List.all;
if Missing_List /= null then
Result.Missing := Missing_List.all;
end if;
Free (Result_List);
Free (Missing_List);
return Result;
end;
exception
when ASIS_Inappropriate_Context =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Semantic_Dependence_Order");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Semantic_Dependence_Order",
Ex => Ex);
end Semantic_Dependence_Order;
end Asis.Compilation_Units.Relations;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
stcarrez/dynamo,stcarrez/dynamo,stcarrez/dynamo
|
|
0fe95b092cfbe77e788a4ff89d4ed2e146b13b6a
|
testutil/ahven/ahven-text_runner.adb
|
testutil/ahven/ahven-text_runner.adb
|
--
-- Copyright (c) 2007-2009 Tero Koskinen <[email protected]>
--
-- 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.
--
with Ada.Text_IO;
with Ada.Strings.Fixed;
with Ada.Characters.Latin_1;
with Ahven.Runner;
with Ahven.XML_Runner;
with Ahven.AStrings;
use Ada.Text_IO;
use Ada.Strings.Fixed;
package body Ahven.Text_Runner is
use Ahven.Results;
use Ahven.Framework;
use Ahven.AStrings;
-- Local procedures
procedure Pad (Level : Natural);
procedure Print_Test (Info : Result_Info;
Level : Natural;
Result : String);
procedure Print_Passes (Result : Result_Collection;
Level : Natural);
procedure Report_Results (Result : Result_Collection;
Verbose : Boolean := False);
procedure Print_Log_File (Filename : String);
procedure Pad (Level : Natural) is
begin
for A in Integer range 1 .. Level loop
Put (" ");
end loop;
end Pad;
procedure Pad (Amount : in Natural;
Total : in out Natural) is
begin
for A in Natural range 1 .. Amount loop
Put (" ");
end loop;
Total := Total + Amount;
end Pad;
procedure Multiline_Pad (Input : String;
Level : Natural) is
begin
Pad (Level);
for A in Input'Range loop
Put (Input (A));
if (Input (A) = Ada.Characters.Latin_1.LF) and (A /= Input'Last) then
Pad (Level);
end if;
end loop;
end Multiline_Pad;
procedure Print_Test (Info : Result_Info;
Level : Natural;
Result : String) is
use Ada.Strings;
Max_Output_Width : constant := 50;
Max_Result_Width : constant := 7;
Max_Time_Out_Width : constant := 12;
subtype Result_Size is Integer range 1 .. Max_Result_Width;
subtype Time_Out_Size is Integer range 1 .. Max_Time_Out_Width;
procedure Print_Text (Str : String; Total : in out Natural) is
begin
Put (Str);
Total := Total + Str'Length;
end Print_Text;
Msg : constant String := Get_Message (Info);
Result_Out : String (Result_Size) := (others => ' ');
Time_Out : String (Time_Out_Size) := (others => ' ');
Total_Text : Natural := 0;
begin
Pad (Level + 1, Total_Text);
Print_Text (Get_Routine_Name (Info), Total_Text);
if Msg'Length > 0 then
Print_Text (" - ", Total_Text);
Print_Text (Msg, Total_Text);
end if;
if Total_Text < Max_Output_Width then
Pad (Max_Output_Width - Total_Text, Total_Text);
end if;
-- If we know the name of the routine, we print it,
-- the result, and the execution time.
if Get_Routine_Name (Info)'Length > 0 then
Move (Source => Result,
Target => Result_Out,
Drop => Right,
Justify => Left,
Pad => ' ');
Move (Source => Duration'Image (Get_Execution_Time (Info)),
Target => Time_Out,
Drop => Right,
Justify => Right,
Pad => ' ');
Put (" " & Result_Out);
Put (" " & Time_Out & "s");
end if;
if Get_Long_Message (Info)'Length > 0 then
New_Line;
Multiline_Pad (Get_Long_Message (Info), Level + 2);
end if;
New_Line;
end Print_Test;
type Print_Child_Proc is access
procedure (Result : Result_Collection; Level : Natural);
type Child_Count_Proc is access
function (Result : Result_Collection) return Natural;
procedure Print_Children (Result : Result_Collection;
Level : Natural;
Action : Print_Child_Proc;
Count : Child_Count_Proc)
is
Child_Iter : Result_Collection_Cursor := First_Child (Result);
begin
loop
exit when not Is_Valid (Child_Iter);
if Count.all (Data (Child_Iter).all) > 0 then
Action.all (Data (Child_Iter).all, Level + 1);
end if;
Child_Iter := Next (Child_Iter);
end loop;
end Print_Children;
procedure Print_Statuses (Result : Result_Collection;
Level : Natural;
Start : Result_Info_Cursor;
Action : Print_Child_Proc;
Status : String;
Count : Child_Count_Proc;
Print_Log : Boolean) is
Position : Result_Info_Cursor := Start;
begin
if Length (Get_Test_Name (Result)) > 0 then
Pad (Level);
Put_Line (To_String (Get_Test_Name (Result)) & ":");
end if;
Test_Loop :
loop
exit Test_Loop when not Is_Valid (Position);
Print_Test (Data (Position), Level, Status);
if Print_Log and
(Length (Get_Output_File (Data (Position))) > 0) then
Print_Log_File (To_String (Get_Output_File (Data (Position))));
end if;
Position := Next (Position);
end loop Test_Loop;
Print_Children (Result => Result,
Level => Level,
Action => Action,
Count => Count);
end Print_Statuses;
--
-- Print all failures from the result collection
-- and then recurse into child collections.
--
procedure Print_Failures (Result : Result_Collection;
Level : Natural) is
begin
Print_Statuses
(Result => Result,
Level => Level,
Start => First_Failure (Result),
Action => Print_Failures'Access,
Status => "FAIL",
Count => Failure_Count'Access,
Print_Log => True);
end Print_Failures;
--
-- Print all skips from the result collection
-- and then recurse into child collections.
--
procedure Print_Skips (Result : Result_Collection;
Level : Natural) is
begin
Print_Statuses
(Result => Result,
Level => Level,
Start => First_Skipped (Result),
Action => Print_Skips'Access,
Status => "SKIPPED",
Count => Skipped_Count'Access,
Print_Log => True);
end Print_Skips;
--
-- Print all errors from the result collection
-- and then recurse into child collections.
--
procedure Print_Errors (Result : Result_Collection;
Level : Natural) is
begin
Print_Statuses
(Result => Result,
Level => Level,
Start => First_Error (Result),
Action => Print_Errors'Access,
Status => "ERROR",
Count => Error_Count'Access,
Print_Log => True);
end Print_Errors;
--
-- Print all passes from the result collection
-- and then recurse into child collections.
--
procedure Print_Passes (Result : Result_Collection;
Level : Natural) is
begin
Print_Statuses
(Result => Result,
Level => Level,
Start => First_Pass (Result),
Action => Print_Passes'Access,
Status => "PASS",
Count => Pass_Count'Access,
Print_Log => False);
end Print_Passes;
--
-- Report passes, skips, failures, and errors from the result collection.
procedure Report_Results (Result : Result_Collection;
Verbose : Boolean := False) is
begin
Put_Line ("Passed : " & Integer'Image (Pass_Count (Result)));
if Verbose then
Print_Passes (Result, 0);
end if;
New_Line;
if Skipped_Count (Result) > 0 then
Put_Line ("Skipped : " & Integer'Image (Skipped_Count (Result)));
Print_Skips (Result, 0);
New_Line;
end if;
if Failure_Count (Result) > 0 then
Put_Line ("Failed : " & Integer'Image (Failure_Count (Result)));
Print_Failures (Result, 0);
New_Line;
end if;
if Error_Count (Result) > 0 then
Put_Line ("Errors : " & Integer'Image (Error_Count (Result)));
Print_Errors (Result, 0);
end if;
end Report_Results;
procedure Print_Log_File (Filename : String) is
Handle : File_Type;
Char : Character := ' ';
First : Boolean := True;
begin
Open (Handle, In_File, Filename);
loop
exit when End_Of_File (Handle);
Get (Handle, Char);
if First then
Put_Line ("===== Output =======");
First := False;
end if;
Put (Char);
if End_Of_Line (Handle) then
New_Line;
end if;
end loop;
Close (Handle);
if not First then
Put_Line ("====================");
end if;
end Print_Log_File;
procedure Do_Report (Test_Results : Results.Result_Collection;
Args : Parameters.Parameter_Info) is
begin
if Parameters.XML_Results (Args) then
XML_Runner.Report_Results
(Test_Results, Parameters.Result_Dir (Args));
else
Report_Results (Test_Results, Parameters.Verbose (Args));
end if;
end Do_Report;
procedure Run (Suite : in out Framework.Test'Class) is
begin
Runner.Run_Suite (Suite, Do_Report'Access);
end Run;
procedure Run (Suite : Framework.Test_Suite_Access) is
begin
Run (Suite.all);
end Run;
end Ahven.Text_Runner;
|
--
-- Copyright (c) 2007-2009 Tero Koskinen <[email protected]>
--
-- 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.
--
with Ada.Text_IO;
with Ada.Strings.Fixed;
with Ada.Characters.Latin_1;
with Ada.IO_Exceptions;
with Ahven.Runner;
with Ahven.XML_Runner;
with Ahven.AStrings;
use Ada.Text_IO;
use Ada.Strings.Fixed;
package body Ahven.Text_Runner is
use Ahven.Results;
use Ahven.Framework;
use Ahven.AStrings;
-- Local procedures
procedure Pad (Level : Natural);
procedure Print_Test (Info : Result_Info;
Level : Natural;
Result : String);
procedure Print_Passes (Result : Result_Collection;
Level : Natural);
procedure Report_Results (Result : Result_Collection;
Verbose : Boolean := False);
procedure Print_Log_File (Filename : String);
procedure Pad (Level : Natural) is
begin
for A in Integer range 1 .. Level loop
Put (" ");
end loop;
end Pad;
procedure Pad (Amount : in Natural;
Total : in out Natural) is
begin
for A in Natural range 1 .. Amount loop
Put (" ");
end loop;
Total := Total + Amount;
end Pad;
procedure Multiline_Pad (Input : String;
Level : Natural) is
begin
Pad (Level);
for A in Input'Range loop
Put (Input (A));
if (Input (A) = Ada.Characters.Latin_1.LF) and (A /= Input'Last) then
Pad (Level);
end if;
end loop;
end Multiline_Pad;
procedure Print_Test (Info : Result_Info;
Level : Natural;
Result : String) is
use Ada.Strings;
Max_Output_Width : constant := 50;
Max_Result_Width : constant := 7;
Max_Time_Out_Width : constant := 12;
subtype Result_Size is Integer range 1 .. Max_Result_Width;
subtype Time_Out_Size is Integer range 1 .. Max_Time_Out_Width;
procedure Print_Text (Str : String; Total : in out Natural) is
begin
Put (Str);
Total := Total + Str'Length;
end Print_Text;
Msg : constant String := Get_Message (Info);
Result_Out : String (Result_Size) := (others => ' ');
Time_Out : String (Time_Out_Size) := (others => ' ');
Total_Text : Natural := 0;
begin
Pad (Level + 1, Total_Text);
Print_Text (Get_Routine_Name (Info), Total_Text);
if Msg'Length > 0 then
Print_Text (" - ", Total_Text);
Print_Text (Msg, Total_Text);
end if;
if Total_Text < Max_Output_Width then
Pad (Max_Output_Width - Total_Text, Total_Text);
end if;
-- If we know the name of the routine, we print it,
-- the result, and the execution time.
if Get_Routine_Name (Info)'Length > 0 then
Move (Source => Result,
Target => Result_Out,
Drop => Right,
Justify => Left,
Pad => ' ');
Move (Source => Duration'Image (Get_Execution_Time (Info)),
Target => Time_Out,
Drop => Right,
Justify => Right,
Pad => ' ');
Put (" " & Result_Out);
Put (" " & Time_Out & "s");
end if;
if Get_Long_Message (Info)'Length > 0 then
New_Line;
Multiline_Pad (Get_Long_Message (Info), Level + 2);
end if;
New_Line;
end Print_Test;
type Print_Child_Proc is access
procedure (Result : Result_Collection; Level : Natural);
type Child_Count_Proc is access
function (Result : Result_Collection) return Natural;
procedure Print_Children (Result : Result_Collection;
Level : Natural;
Action : Print_Child_Proc;
Count : Child_Count_Proc)
is
Child_Iter : Result_Collection_Cursor := First_Child (Result);
begin
loop
exit when not Is_Valid (Child_Iter);
if Count.all (Data (Child_Iter).all) > 0 then
Action.all (Data (Child_Iter).all, Level + 1);
end if;
Child_Iter := Next (Child_Iter);
end loop;
end Print_Children;
procedure Print_Statuses (Result : Result_Collection;
Level : Natural;
Start : Result_Info_Cursor;
Action : Print_Child_Proc;
Status : String;
Count : Child_Count_Proc;
Print_Log : Boolean) is
Position : Result_Info_Cursor := Start;
begin
if Length (Get_Test_Name (Result)) > 0 then
Pad (Level);
Put_Line (To_String (Get_Test_Name (Result)) & ":");
end if;
Test_Loop :
loop
exit Test_Loop when not Is_Valid (Position);
Print_Test (Data (Position), Level, Status);
if Print_Log and
(Length (Get_Output_File (Data (Position))) > 0) then
Print_Log_File (To_String (Get_Output_File (Data (Position))));
end if;
Position := Next (Position);
end loop Test_Loop;
Print_Children (Result => Result,
Level => Level,
Action => Action,
Count => Count);
end Print_Statuses;
--
-- Print all failures from the result collection
-- and then recurse into child collections.
--
procedure Print_Failures (Result : Result_Collection;
Level : Natural) is
begin
Print_Statuses
(Result => Result,
Level => Level,
Start => First_Failure (Result),
Action => Print_Failures'Access,
Status => "FAIL",
Count => Failure_Count'Access,
Print_Log => True);
end Print_Failures;
--
-- Print all skips from the result collection
-- and then recurse into child collections.
--
procedure Print_Skips (Result : Result_Collection;
Level : Natural) is
begin
Print_Statuses
(Result => Result,
Level => Level,
Start => First_Skipped (Result),
Action => Print_Skips'Access,
Status => "SKIPPED",
Count => Skipped_Count'Access,
Print_Log => True);
end Print_Skips;
--
-- Print all errors from the result collection
-- and then recurse into child collections.
--
procedure Print_Errors (Result : Result_Collection;
Level : Natural) is
begin
Print_Statuses
(Result => Result,
Level => Level,
Start => First_Error (Result),
Action => Print_Errors'Access,
Status => "ERROR",
Count => Error_Count'Access,
Print_Log => True);
end Print_Errors;
--
-- Print all passes from the result collection
-- and then recurse into child collections.
--
procedure Print_Passes (Result : Result_Collection;
Level : Natural) is
begin
Print_Statuses
(Result => Result,
Level => Level,
Start => First_Pass (Result),
Action => Print_Passes'Access,
Status => "PASS",
Count => Pass_Count'Access,
Print_Log => False);
end Print_Passes;
--
-- Report passes, skips, failures, and errors from the result collection.
procedure Report_Results (Result : Result_Collection;
Verbose : Boolean := False) is
begin
Put_Line ("Passed : " & Integer'Image (Pass_Count (Result)));
if Verbose then
Print_Passes (Result, 0);
end if;
New_Line;
if Skipped_Count (Result) > 0 then
Put_Line ("Skipped : " & Integer'Image (Skipped_Count (Result)));
Print_Skips (Result, 0);
New_Line;
end if;
if Failure_Count (Result) > 0 then
Put_Line ("Failed : " & Integer'Image (Failure_Count (Result)));
Print_Failures (Result, 0);
New_Line;
end if;
if Error_Count (Result) > 0 then
Put_Line ("Errors : " & Integer'Image (Error_Count (Result)));
Print_Errors (Result, 0);
end if;
end Report_Results;
procedure Print_Log_File (Filename : String) is
Handle : File_Type;
Char : Character := ' ';
First : Boolean := True;
begin
Open (Handle, In_File, Filename);
begin
loop
exit when End_Of_File (Handle);
Get (Handle, Char);
if First then
Put_Line ("===== Output =======");
First := False;
end if;
Put (Char);
if End_Of_Line (Handle) then
New_Line;
end if;
end loop;
-- The End_Error exception is sometimes raised.
exception
when Ada.IO_Exceptions.End_Error =>
null;
end;
Close (Handle);
if not First then
Put_Line ("====================");
end if;
end Print_Log_File;
procedure Do_Report (Test_Results : Results.Result_Collection;
Args : Parameters.Parameter_Info) is
begin
if Parameters.XML_Results (Args) then
XML_Runner.Report_Results
(Test_Results, Parameters.Result_Dir (Args));
else
Report_Results (Test_Results, Parameters.Verbose (Args));
end if;
end Do_Report;
procedure Run (Suite : in out Framework.Test'Class) is
begin
Runner.Run_Suite (Suite, Do_Report'Access);
end Run;
procedure Run (Suite : Framework.Test_Suite_Access) is
begin
Run (Suite.all);
end Run;
end Ahven.Text_Runner;
|
Fix the Ahven text runner: the END_ERROR exception can be raised when reading the test output file
|
Fix the Ahven text runner: the END_ERROR exception can be raised when reading the test output file
|
Ada
|
apache-2.0
|
Letractively/ada-util,flottokarotto/ada-util,Letractively/ada-util,flottokarotto/ada-util
|
5b8098f5143e57e0e9c7d65ac2d1200d726f46ea
|
src/asis/a4g-expr_sem.ads
|
src/asis/a4g-expr_sem.ads
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . E X P R _ S E M --
-- --
-- S p e c --
-- --
-- Copyright (c) 1995-2005, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
-- This package contains routines needed for semantic queries from
-- the Asis.Expressions package
with Asis; use Asis;
package A4G.Expr_Sem is
-- All the routines defined in this package do not check their
-- arguments - a caller is responsible for the proper use of these
-- routines
function Expr_Type (Expression : Asis.Expression) return Asis.Declaration;
-- using the fact, that Expression is of An_Expression kind and that
-- the Etype field is set for its Node, this function finds the
-- type declaration which should be returned as the result of
-- Corresponding_Expression_Type (Expression)
function Identifier_Name_Definition
(Reference_I : Element)
return Asis.Defining_Name;
function Character_Literal_Name_Definition
(Reference_Ch : Element)
return Asis.Defining_Name;
-- Each of these two functions provides an Element representing the
-- defining occurrence for its argument, provided that the argument is
-- of appropriate kind and all the necessary checks have already been
-- done
function Is_Reference
(Name : Asis.Element;
Ref : Asis.Element)
return Boolean;
-- Provided that Name is of A_Defining_Name kind, this function checks is
-- Ref is a reference to this name. It is an error to call this function
-- for any Element which is not of A_Defining_Name as an actual for Name.
-- Any Element is acceptable as an actual for Ref, and this function does
-- not raise any exception in any case.
--
-- ??? Should we move this function into Asis.Extensions?
function Needs_List (Reference : Asis.Element) return Boolean;
-- Supposed to be applied to the argument of the
-- Corresponding_Name_Definition_List query. Checks if Reference
-- is ambiguous and refers to more than one entity.
procedure Collect_Overloaded_Entities (Reference : Asis.Element);
-- Supposed to be called for the argument of the
-- Corresponding_Name_Definition_List query in case if Needs_List is
-- True for it. Collects in the Element Table all the defining
-- names referred by Reference.
-- This procedure supposes, that the Element Table is already initialized
-- in the calling context
procedure Correct_Result
(Result : in out Element;
Reference : Element);
-- This procedure implements a most complicated case for the fix needed
-- for BB10-002. It correct the result in the situation when we have nested
-- generic instantiations, and the named number in question is declared in
-- template. In this situation the approach based on Original_Entity field
-- returns the defining name from the template, but we need the defining
-- name from the outer instantiation (see the test for BB10-002 for more
-- details)
function Is_From_Dispatching_Call (Reference : Element) return Boolean;
-- This function detects if its argument is a name from a dispatching call
-- for that Corresponding_Name_Definition should return Nil_Element (that
-- is, a name of a called subprogram or the name of a formal parameter from
-- a named association)
function Is_Implicit_Formal_Par (Result_El : Element) return Boolean;
-- Is supposed to be applied to the result of Identifier_Name_Definition.
-- Checks if this result corresponds to the situation when the argument of
-- Identifier_Name_Definition is the reference to a formal parameter from
-- implicit inherited subprogram
procedure Correct_Impl_Form_Par
(Result : in out Element;
Reference : Element);
-- This procedure is supposed to be called is Result is the result of the
-- call to Identifier_Name_Definition, and Is_Implicit_Formal_Par yields
-- True for Result. It creates the correct defining name for this iplicit
-- inherited formal parameter.
end A4G.Expr_Sem;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen
|
|
a76edd0844e319a91c659371e671327f74b867bc
|
src/asis/asis-extensions-flat_kinds.adb
|
src/asis/asis-extensions-flat_kinds.adb
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . K N D _ C O N V --
-- --
-- B o d y --
-- --
-- $Revision: 15351 $
-- --
-- Copyright (c) 1995-2002, 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 Asis.Set_Get;
with A4G.Knd_Conv; use A4G.Knd_Conv;
with A4G.Vcheck; use A4G.Vcheck;
package body Asis.Extensions.Flat_Kinds is
use Asis;
-----------------------
-- Flat_Element_Kind --
-----------------------
function Flat_Element_Kind
(Element : Asis.Element)
return Flat_Element_Kinds
is
begin
Check_Validity (Element, "Asis.Extensions.Flat_Kinds.Flat_Element_Kind");
return Flat_Element_Kinds (Asis.Set_Get.Int_Kind (Element));
end Flat_Element_Kind;
-------------------------------------------------
-- Flat Element Kinds Conversion Functions --
-------------------------------------------------
function Asis_From_Flat_Kind
(Flat_Kind : Flat_Element_Kinds)
return Asis.Element_Kinds
is
begin
return Asis_From_Internal_Kind (Internal_Element_Kinds (Flat_Kind));
end Asis_From_Flat_Kind;
function Pragma_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Pragma_Kinds
is
begin
return Pragma_Kind_From_Internal (Internal_Element_Kinds (Flat_Kind));
end Pragma_Kind_From_Flat;
function Defining_Name_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Defining_Name_Kinds
is
begin
return Defining_Name_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Defining_Name_Kind_From_Flat;
function Declaration_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Declaration_Kinds
is
begin
return Declaration_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Declaration_Kind_From_Flat;
function Definition_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Definition_Kinds
is
begin
return Definition_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Definition_Kind_From_Flat;
function Type_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Type_Kinds
is
begin
return Type_Kind_From_Internal (Internal_Element_Kinds (Flat_Kind));
end Type_Kind_From_Flat;
function Formal_Type_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Formal_Type_Kinds
is
begin
return Formal_Type_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Formal_Type_Kind_From_Flat;
function Access_Type_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Access_Type_Kinds
is
begin
return Access_Type_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Access_Type_Kind_From_Flat;
function Root_Type_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Root_Type_Kinds
is
begin
return Root_Type_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Root_Type_Kind_From_Flat;
function Constraint_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Constraint_Kinds
is
begin
return Constraint_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Constraint_Kind_From_Flat;
function Discrete_Range_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Discrete_Range_Kinds
is
begin
return Discrete_Range_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Discrete_Range_Kind_From_Flat;
function Expression_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Expression_Kinds
is
begin
return Expression_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Expression_Kind_From_Flat;
function Operator_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Operator_Kinds
is
begin
return Operator_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Operator_Kind_From_Flat;
function Attribute_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Attribute_Kinds
is
begin
return Attribute_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Attribute_Kind_From_Flat;
function Association_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Association_Kinds
is
begin
return Association_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Association_Kind_From_Flat;
function Statement_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Statement_Kinds
is
begin
return Statement_Kind_From_Internal (Internal_Element_Kinds (Flat_Kind));
end Statement_Kind_From_Flat;
function Path_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Path_Kinds
is
begin
return Path_Kind_From_Internal (Internal_Element_Kinds (Flat_Kind));
end Path_Kind_From_Flat;
function Clause_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Clause_Kinds
is
begin
return Clause_Kind_From_Internal (Internal_Element_Kinds (Flat_Kind));
end Clause_Kind_From_Flat;
function Representation_Clause_Kind_From_Flat
(Flat_Kind : Flat_Element_Kinds)
return Asis.Representation_Clause_Kinds
is
begin
return Representation_Clause_Kind_From_Internal
(Internal_Element_Kinds (Flat_Kind));
end Representation_Clause_Kind_From_Flat;
-------------------------------------
-- Additional Classification items --
-------------------------------------
-----------------------
-- Def_Operator_Kind --
-----------------------
function Def_Operator_Kind
(Op_Kind : Flat_Element_Kinds)
return Flat_Element_Kinds
is
begin
return Flat_Element_Kinds (Def_Operator_Kind
(Internal_Element_Kinds (Op_Kind)));
end Def_Operator_Kind;
end Asis.Extensions.Flat_Kinds;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen
|
|
52a4b58dd0475c59e5474ddef1524b5b1d0d60ed
|
src/security-auth-openid.adb
|
src/security-auth-openid.adb
|
-----------------------------------------------------------------------
-- security-openid -- OpenID 2.0 Support
-- Copyright (C) 2009, 2010, 2011, 2012 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Fixed;
with Ada.Text_IO;
with Util.Http.Clients;
with Util.Strings;
with Util.Encoders;
with Util.Log.Loggers;
with Util.Encoders.SHA1;
with Util.Encoders.HMAC.SHA1;
package body Security.Auth.OpenID is
use Ada.Strings.Fixed;
use Util.Log;
Log : constant Util.Log.Loggers.Logger := Loggers.Create ("Security.Auth.OpenID");
procedure Extract_Profile (Prefix : in String;
Request : in Parameters'Class;
Result : in out Authentication);
function Extract (From : String;
Start_Tag : String;
End_Tag : String) return String;
procedure Extract_Value (Into : in out Unbounded_String;
Request : in Parameters'Class;
Name : in String);
procedure Set_Result (Result : in out Authentication;
Status : in Auth_Result;
Message : in String);
function Get_Association_Query return String;
-- ------------------------------
-- Initialize the OpenID realm.
-- ------------------------------
-- Initialize the authentication realm.
overriding
procedure Initialize (Realm : in out Manager;
Params : in Parameters'Class;
Provider : in String := PROVIDER_OPENID) is
begin
Realm.Realm := To_Unbounded_String (Params.Get_Parameter (Provider & ".realm"));
Realm.Return_To := To_Unbounded_String (Params.Get_Parameter (Provider & ".callback_url"));
end Initialize;
-- ------------------------------
-- Discover the OpenID provider that must be used to authenticate the user.
-- The <b>Name</b> can be an URL or an alias that identifies the provider.
-- A cached OpenID provider can be returned.
-- Read the XRDS document from the URI and initialize the OpenID provider end point.
-- (See OpenID Section 7.3 Discovery)
-- ------------------------------
overriding
procedure Discover (Realm : in out Manager;
Name : in String;
Result : out End_Point) is
Client : Util.Http.Clients.Client;
Reply : Util.Http.Clients.Response;
begin
Log.Info ("Discover XRDS on {0}", Name);
Client.Add_Header ("Accept", "application/xrds+xml");
Client.Get (URL => Name,
Reply => Reply);
if Reply.Get_Status /= Util.Http.SC_OK then
Log.Error ("Received error {0} when discovering XRDS on {1}",
Util.Strings.Image (Reply.Get_Status), Name);
raise Service_Error with "Discovering XRDS of OpenID provider failed.";
end if;
Manager'Class (Realm).Extract_XRDS (Content => Reply.Get_Body,
Result => Result);
end Discover;
function Extract (From : String;
Start_Tag : String;
End_Tag : String) return String is
Pos : Natural := Index (From, Start_Tag);
Last : Natural;
Url_Pos : Natural;
begin
if Pos = 0 then
Pos := Index (From, Start_Tag (Start_Tag'First .. Start_Tag'Last - 1));
if Pos = 0 then
return "";
end if;
Pos := Index (From, ">", Pos + 1);
if Pos = 0 then
return "";
end if;
Url_Pos := Pos + 1;
else
Url_Pos := Pos + Start_Tag'Length;
end if;
Last := Index (From, End_Tag, Pos);
if Last <= Pos then
return "";
end if;
return From (Url_Pos .. Last - 1);
end Extract;
-- ------------------------------
-- Extract from the XRDS content the OpenID provider URI.
-- The default implementation is very basic as it returns the first <URI>
-- available in the stream without validating the XRDS document.
-- Raises the <b>Invalid_End_Point</b> exception if the URI cannot be found.
-- ------------------------------
procedure Extract_XRDS (Realm : in out Manager;
Content : in String;
Result : out End_Point) is
pragma Unreferenced (Realm);
URI : constant String := Extract (Content, "<URI>", "</URI>");
begin
if URI'Length = 0 then
raise Invalid_End_Point with "Cannot extract the <URI> from the XRDS document";
end if;
Result.URL := To_Unbounded_String (URI);
end Extract_XRDS;
function Get_Association_Query return String is
begin
return "openid.ns=http://specs.openid.net/auth/2.0&"
& "openid.mode=associate&"
& "openid.session_type=no-encryption&"
& "openid.assoc_type=HMAC-SHA1";
end Get_Association_Query;
-- ------------------------------
-- Associate the application (relying party) with the OpenID provider.
-- The association can be cached.
-- (See OpenID Section 8 Establishing Associations)
-- ------------------------------
overriding
procedure Associate (Realm : in out Manager;
OP : in End_Point;
Result : out Association) is
pragma Unreferenced (Realm);
Output : Unbounded_String;
URI : constant String := To_String (OP.URL);
Params : constant String := Get_Association_Query;
Client : Util.Http.Clients.Client;
Reply : Util.Http.Clients.Response;
Pos, Last, N : Natural;
begin
Client.Post (URL => URI,
Data => Params,
Reply => Reply);
if Reply.Get_Status /= Util.Http.SC_OK then
Log.Error ("Received error {0} when creating assoication with {1}",
Util.Strings.Image (Reply.Get_Status), URI);
raise Service_Error with "Cannot create association with OpenID provider.";
end if;
Output := To_Unbounded_String (Reply.Get_Body);
Pos := 1;
while Pos < Length (Output) loop
N := Index (Output, ":", Pos);
exit when N = 0;
Last := Index (Output, "" & ASCII.LF, N);
if Last = 0 then
Last := Length (Output);
else
Last := Last - 1;
end if;
declare
Key : constant String := Slice (Output, Pos, N - 1);
begin
if Key = "session_type" then
Result.Session_Type := Unbounded_Slice (Output, N + 1, Last);
elsif Key = "assoc_type" then
Result.Assoc_Type := Unbounded_Slice (Output, N + 1, Last);
elsif Key = "assoc_handle" then
Result.Assoc_Handle := Unbounded_Slice (Output, N + 1, Last);
elsif Key = "mac_key" then
Result.Mac_Key := Unbounded_Slice (Output, N + 1, Last);
elsif Key = "expires_in" then
declare
Val : constant String := Slice (Output, N + 1, Last);
-- Expires : Integer := Integer'Value (Val);
begin
Ada.Text_IO.Put_Line ("Expires: |" & Val & "|");
Result.Expired := Ada.Calendar.Clock;
end;
elsif Key /= "ns" then
Ada.Text_IO.Put_Line ("Key not recognized: " & Key);
end if;
end;
Pos := Last + 2;
end loop;
Log.Debug ("Received end point {0}", To_String (Output));
end Associate;
overriding
function Get_Authentication_URL (Realm : in Manager;
OP : in End_Point;
Assoc : in Association) return String is
Result : Unbounded_String := OP.URL;
Axa : constant String := "ax";
begin
if Index (Result, "?") > 0 then
Append (Result, "&");
else
Append (Result, "?");
end if;
Append (Result, "openid.ns=http://specs.openid.net/auth/2.0");
Append (Result, "&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select");
Append (Result, "&openid.identity=http://specs.openid.net/auth/2.0/identifier_select");
Append (Result, "&openid.mode=checkid_setup");
Append (Result, "&openid.ns." & Axa & "=http://openid.net/srv/ax/1.0");
Append (Result, "&openid." & Axa & ".mode=fetch_request");
Append (Result, "&openid." & Axa & ".type.email=http://axschema.org/contact/email");
Append (Result, "&openid." & Axa & ".type.fullname=http://axschema.org/namePerson");
Append (Result, "&openid." & Axa & ".type.language=http://axschema.org/pref/language");
Append (Result, "&openid." & Axa & ".type.firstname=http://axschema.org/namePerson/first");
Append (Result, "&openid." & Axa & ".type.lastname=http://axschema.org/namePerson/last");
Append (Result, "&openid." & Axa & ".type.gender=http://axschema.org/person/gender");
Append (Result, "&openid." & Axa & ".required=email,fullname,language,firstname,"
& "lastname,gender");
Append (Result, "&openid.ns.sreg=http://openid.net/extensions/sreg/1.1");
Append (Result, "&openid.sreg.required=email,fullname,gender,country,nickname");
Append (Result, "&openid.return_to=");
Append (Result, Realm.Return_To);
Append (Result, "&openid.assoc_handle=");
Append (Result, Assoc.Assoc_Handle);
Append (Result, "&openid.realm=");
Append (Result, Realm.Realm);
return To_String (Result);
end Get_Authentication_URL;
procedure Set_Result (Result : in out Authentication;
Status : in Auth_Result;
Message : in String) is
begin
if Status /= AUTHENTICATED then
Log.Error ("OpenID verification failed: {0}", Message);
else
Log.Info ("OpenID verification: {0}", Message);
end if;
Result.Status := Status;
end Set_Result;
procedure Extract_Value (Into : in out Unbounded_String;
Request : in Parameters'Class;
Name : in String) is
begin
if Length (Into) = 0 then
Into := To_Unbounded_String (Request.Get_Parameter (Name));
end if;
end Extract_Value;
procedure Extract_Profile (Prefix : in String;
Request : in Parameters'Class;
Result : in out Authentication) is
begin
Extract_Value (Result.Email, Request, Prefix & ".email");
Extract_Value (Result.Nickname, Request, Prefix & ".nickname");
Extract_Value (Result.Gender, Request, Prefix & ".gender");
Extract_Value (Result.Country, Request, Prefix & ".country");
Extract_Value (Result.Language, Request, Prefix & ".language");
Extract_Value (Result.Full_Name, Request, Prefix & ".fullname");
Extract_Value (Result.Timezone, Request, Prefix & ".timezone");
Extract_Value (Result.First_Name, Request, Prefix & ".firstname");
Extract_Value (Result.Last_Name, Request, Prefix & ".lastname");
-- If the fullname is not specified, try to build one from the first_name and last_name.
if Length (Result.Full_Name) = 0 then
Append (Result.Full_Name, Result.First_Name);
if Length (Result.First_Name) > 0 and Length (Result.Last_Name) > 0 then
Append (Result.Full_Name, " ");
Append (Result.Full_Name, Result.Last_Name);
end if;
end if;
end Extract_Profile;
-- ------------------------------
-- Verify the authentication result
-- ------------------------------
overriding
procedure Verify (Realm : in out Manager;
Assoc : in Association;
Request : in Parameters'Class;
Result : out Authentication) is
Mode : constant String := Request.Get_Parameter ("openid.mode");
begin
-- Step 1: verify the response status
if Mode = "cancel" then
Set_Result (Result, CANCEL, "Authentication refused");
return;
end if;
if Mode = "setup_needed" then
Set_Result (Result, SETUP_NEEDED, "Setup is needed");
return;
end if;
if Mode /= "id_res" then
Set_Result (Result, UNKNOWN, "Setup is needed");
return;
end if;
-- OpenID Section: 11.1. Verifying the Return URL
declare
Value : constant String := Request.Get_Parameter ("openid.return_to");
begin
if Value /= Realm.Return_To then
Set_Result (Result, UNKNOWN, "openid.return_to URL does not match");
return;
end if;
end;
-- OpenID Section: 11.2. Verifying Discovered Information
Manager'Class (Realm).Verify_Discovered (Assoc, Request, Result);
-- OpenID Section: 11.3. Checking the Nonce
declare
Value : constant String := Request.Get_Parameter ("openid.response_nonce");
begin
if Value = "" then
Set_Result (Result, UNKNOWN, "openid.response_nonce is empty");
return;
end if;
end;
-- OpenID Section: 11.4. Verifying Signatures
Manager'Class (Realm).Verify_Signature (Assoc, Request, Result);
declare
Value : constant String := Request.Get_Parameter ("openid.ns.sreg");
begin
-- Extract profile information
if Value = "http://openid.net/extensions/sreg/1.1" then
Extract_Profile ("openid.sreg", Request, Result);
end if;
end;
declare
Value : constant String := Request.Get_Parameter ("openid.ns.ax");
begin
if Value = "http://openid.net/srv/ax/1.0" then
Extract_Profile ("openid.ax.value", Request, Result);
end if;
end;
declare
Value : constant String := Request.Get_Parameter ("openid.ns.ext1");
begin
if Value = "http://openid.net/srv/ax/1.0" then
Extract_Profile ("openid.ext1.value", Request, Result);
end if;
end;
end Verify;
-- ------------------------------
-- Verify the signature part of the result
-- ------------------------------
procedure Verify_Signature (Realm : in Manager;
Assoc : in Association;
Request : in Parameters'Class;
Result : in out Authentication) is
pragma Unreferenced (Realm);
use type Util.Encoders.SHA1.Digest;
Signed : constant String := Request.Get_Parameter ("openid.signed");
Len : constant Natural := Signed'Length;
Sign : Unbounded_String;
Param : Unbounded_String;
Pos : Natural := 1;
Last : Natural;
begin
while Pos < Len loop
Last := Index (Signed, ",", Pos);
if Last > 0 then
Param := To_Unbounded_String (Signed (Pos .. Last - 1));
Pos := Last + 1;
else
Param := To_Unbounded_String (Signed (Pos .. Len));
Pos := Len + 1;
end if;
declare
Name : constant String := "openid." & To_String (Param);
Value : constant String := Request.Get_Parameter (Name);
begin
Append (Sign, Param);
Append (Sign, ':');
Append (Sign, Value);
Append (Sign, ASCII.LF);
end;
end loop;
Log.Info ("Signing: '{0}'", To_String (Sign));
declare
Decoder : constant Util.Encoders.Encoder := Util.Encoders.Create (Util.Encoders.BASE_64);
S : constant String := Request.Get_Parameter ("openid.sig");
Key : constant String := Decoder.Decode (To_String (Assoc.Mac_Key));
R : constant Util.Encoders.SHA1.Base64_Digest
:= Util.Encoders.HMAC.SHA1.Sign_Base64 (Key, To_String (Sign));
begin
Log.Info ("Signature: {0} - {1}", S, R);
if R /= S then
Set_Result (Result, INVALID_SIGNATURE, "openid.response_nonce is empty");
else
Set_Result (Result, AUTHENTICATED, "authenticated");
end if;
end;
end Verify_Signature;
-- ------------------------------
-- Verify the authentication result
-- ------------------------------
procedure Verify_Discovered (Realm : in out Manager;
Assoc : in Association;
Request : in Parameters'Class;
Result : out Authentication) is
pragma Unreferenced (Realm, Assoc);
begin
Result.Claimed_Id := To_Unbounded_String (Request.Get_Parameter ("openid.claimed_id"));
Result.Identity := To_Unbounded_String (Request.Get_Parameter ("openid.identity"));
end Verify_Discovered;
function To_String (Assoc : Association) return String is
begin
return "session_type=" & To_String (Assoc.Session_Type)
& "&assoc_type=" & To_String (Assoc.Assoc_Type)
& "&assoc_handle=" & To_String (Assoc.Assoc_Handle)
& "&mac_key=" & To_String (Assoc.Mac_Key);
end To_String;
end Security.Auth.OpenID;
|
Refactor the OpenID authentication to be based on the generic authentication framework
|
Refactor the OpenID authentication to be based on the generic authentication framework
|
Ada
|
apache-2.0
|
Letractively/ada-security
|
|
7dd0f559dd622dd310afffb25a5aaba166a53322
|
src/asis/asis-set_get.ads
|
src/asis/asis-set_get.ads
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A S I S . S E T _ G E T --
-- --
-- S p e c --
-- --
-- Copyright (C) 1995-2010, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
with Ada.Calendar; use Ada.Calendar;
with Asis.Extensions; use Asis.Extensions;
package Asis.Set_Get is
pragma Elaborate_Body (Asis.Set_Get);
-- This package contains the interface routines for setting and getting
-- the values of the internal components of the main ASIS abstractions -
-- Context, Compilation_Unit and Element. All the operations for getting
-- components are defined as functions, but the operations for obtaining
-- the tree nodes from an Element value may change the tree being accessed,
-- which should be considered as the side effect.
-- THE DOCUMENTATION IS INCOMPLETE!!!!!
---------------------------------------
-- String -> Program_Text conversion --
---------------------------------------
function To_Program_Text (S : String) return Program_Text;
-- This function takes the string which is a part of the source code
-- representation and converts it into ASIS Program_Text type. It tries
-- to recognize the wide character encoding and to convert it back into
-- Wide_Character
-------------
-- CONTEXT --
-------------
-------------------------------------
-- Id <-> ASIS Context conversions --
-------------------------------------
function Get_Cont_Id (C : Context) return Context_Id;
function Get_Cont (Id : Context_Id) return Context;
procedure Set_Cont (C : out Context; Id : Context_Id);
-- Assigns the value of Id to the Id fields of a given variable C
-- of the Asis Context type
pragma Inline (Get_Cont_Id);
pragma Inline (Get_Cont);
--------------------------------
-- Getting Context Attributes --
--------------------------------
function Valid (C : Context) return Boolean;
-- checks if its argument is an opened (=valid) Context
-- DO WE REALLY NEED THIS FUNCTION??
----------------------
-- COMPILATION_UNIT --
----------------------
----------------------------------------------
-- Id <-> ASIS Compilation Unit conversions --
----------------------------------------------
function Get_Unit_Id (C_U : Compilation_Unit) return Unit_Id;
function Get_Comp_Unit
(U : Unit_Id;
C : Context_Id)
return Compilation_Unit;
-- this function creates the new value of the Compilation_Unit
-- type; note, that it also sets the field Obtained as equal to
-- the current OS time
function Get_Comp_Unit_List
(U_List : Unit_Id_List;
C : Context_Id)
return Compilation_Unit_List;
-- Creates the ASIS Compilation Unit List from the list of unit Ids
pragma Inline (Get_Unit_Id);
pragma Inline (Get_Comp_Unit);
-----------------------------------------
-- Getting Compilation Unit Attributes --
-----------------------------------------
function Not_Nil (C_U : Compilation_Unit) return Boolean;
-- Check if C_U /= Nil_Compilation_Unit (the name "Exists" is already
-- busy in ASIS
function Nil (C_U : Compilation_Unit) return Boolean;
-- Check if C_U = Nil_Compilation_Unit
function Is_Standard (C_U : Compilation_Unit) return Boolean;
-- Check if C_U represents the predefined package Standard
function Kind (C_U : Compilation_Unit) return Asis.Unit_Kinds;
function Class (C_U : Compilation_Unit) return Unit_Classes;
function Origin (C_U : Compilation_Unit) return Unit_Origins;
function Is_Main_Unit (C_U : Compilation_Unit) return Boolean;
function Top (C_U : Compilation_Unit) return Node_Id;
function Is_Body_Required (C_U : Compilation_Unit) return Boolean;
function Unit_Name (C_U : Compilation_Unit) return String;
function Encl_Cont (C_U : Compilation_Unit) return Context;
function Encl_Cont_Id (C_U : Compilation_Unit) return Context_Id;
function Source_File (C_U : Compilation_Unit) return String;
function Ref_File (C_U : Compilation_Unit) return String;
function Context_Info (C_U : Compilation_Unit) return String;
function Time_Stamp (C_U : Compilation_Unit) return Time;
function Source_Status (C_U : Compilation_Unit)
return Source_File_Statuses;
function Main_Tree (C_U : Compilation_Unit) return Tree_Id;
-------------------
-- Miscellaneous --
-------------------
function "=" (Left, Right : Compilation_Unit) return Boolean;
-- This function "re-implements" the equivalent-to-predefined
-- compare operation for Compilation_Unit. It should never be used in
-- any ASIS application code.
function Valid (C_U : Compilation_Unit) return Boolean;
-- checks, if the argument is valid, that is, if its enclosing
-- Context is opened
procedure Reset_Main_Tree (C_U : Compilation_Unit);
-- If C_U is a main unit in some tree, this procedure resets
-- this tree, otherwise it does nothing. This procedure does not
-- reset the context, it should be done by a caller.
function Get_Configuration_CU
(C_U : Compilation_Unit)
return Compilation_Unit;
-- Returns the ASIS COmpilation unit which represents
-- A_Configuration_Compilation in the enclosing context of C_U
pragma Inline (Not_Nil);
pragma Inline (Nil);
pragma Inline (Is_Standard);
pragma Inline (Kind);
pragma Inline (Class);
pragma Inline (Origin);
pragma Inline (Is_Main_Unit);
pragma Inline (Top);
pragma Inline (Is_Body_Required);
pragma Inline (Unit_Name);
pragma Inline (Encl_Cont);
pragma Inline (Encl_Cont_Id);
pragma Inline (Valid);
-- THIS "INLINE" LIST IS INCOMPLETE!!!
-------------
-- ELEMENT --
-------------
function "=" (Left, Right : Element) return Boolean;
-- This function "re-implements" the equivalent-to-predefined
-- compare operation for Elements. It should never be used in
-- any ASIS application code.
---------
-- Get --
---------
function Node (E : Element) return Node_Id;
function R_Node (E : Element) return Node_Id;
function Node_Field_1 (E : Element) return Node_Id;
function Node_Field_2 (E : Element) return Node_Id;
function Node_Value (E : Element) return Node_Id;
function R_Node_Value (E : Element) return Node_Id;
function Node_Field_1_Value (E : Element) return Node_Id;
function Node_Field_2_Value (E : Element) return Node_Id;
-- Node, R_Node and Node_Field_1 reset the tree when returning
-- the node value in a way that the returned node will be the
-- proper node value for the tree being accessed by ASIS,
-- whereas Node_Value, R_Node_Value and Node_Field_1_Value
-- just return the node value without changing the currently
-- accessed tree
function Encl_Unit (E : Element) return Compilation_Unit;
function Encl_Unit_Id (E : Element) return Unit_Id;
function Encl_Cont (E : Element) return Context;
function Encl_Cont_Id (E : Element) return Context_Id;
function Kind (E : Element) return Asis.Element_Kinds;
function Int_Kind (E : Element) return Internal_Element_Kinds;
function Is_From_Implicit (E : Element) return Boolean;
function Is_From_Inherited (E : Element) return Boolean;
function Is_From_Instance (E : Element) return Boolean;
function Special_Case (E : Element) return Special_Cases;
function Normalization_Case (E : Element) return Normalization_Cases;
function Parenth_Count (E : Element) return Nat;
function Encl_Tree (E : Element) return Tree_Id;
function Rel_Sloc (E : Element) return Source_Ptr;
function Character_Code (E : Element) return Char_Code;
function Obtained (E : Element) return ASIS_OS_Time;
function Location (E : Asis.Element) return Source_Ptr;
-- this function returns not relative (as Rel_Sloc does), but
-- "absolute" location of the source position corresponding
-- to the Node on which E is based. This function is
-- "tree-swapping-safe"
function Valid (E : Element) return Boolean;
-- checks, if the argument is valid, that is, if the enclosing
-- Context of its enclosing Unit is opened
pragma Inline (Node);
pragma Inline (R_Node);
pragma Inline (Encl_Unit);
pragma Inline (Encl_Unit_Id);
pragma Inline (Encl_Cont);
pragma Inline (Encl_Cont_Id);
pragma Inline (Kind);
pragma Inline (Int_Kind);
pragma Inline (Is_From_Implicit);
pragma Inline (Is_From_Inherited);
pragma Inline (Is_From_Instance);
pragma Inline (Special_Case);
pragma Inline (Encl_Tree);
pragma Inline (Rel_Sloc);
pragma Inline (Valid);
---------
-- Set --
---------
procedure Set_Node (E : in out Element; N : Node_Id);
procedure Set_R_Node (E : in out Element; N : Node_Id);
procedure Set_Node_Field_1 (E : in out Element; N : Node_Id);
procedure Set_Node_Field_2 (E : in out Element; N : Node_Id);
procedure Set_Encl_Unit_Id (E : in out Element; U : Unit_Id);
procedure Set_Enclosing_Context (E : in out Element; C : Context_Id);
procedure Set_Obtained (E : in out Element; T : ASIS_OS_Time);
procedure Set_Int_Kind (E : in out Element;
K : Internal_Element_Kinds);
procedure Set_From_Implicit (E : in out Element; I : Boolean := True);
procedure Set_From_Inherited (E : in out Element; I : Boolean := True);
procedure Set_From_Instance (E : in out Element; I : Boolean := True);
procedure Set_Special_Case (E : in out Element; S : Special_Cases);
procedure Set_Rel_Sloc (E : in out Element; S : Source_Ptr);
procedure Set_Character_Code (E : in out Element; C : Char_Code);
procedure Set_Encl_Tree (E : in out Element; T : Tree_Id);
procedure Set_Normalization_Case (E : in out Element;
N : Normalization_Cases);
procedure Set_Parenth_Count (E : in out Element; Val : Nat);
function Set_Element
(Node : Node_Id;
R_Node : Node_Id;
Node_Field_1 : Node_Id;
Node_Field_2 : Node_Id;
Encl_Unit : Compilation_Unit;
-- contains Ids for both Enclosing Compilation Unit and Enclosing
-- Context
Int_Kind : Internal_Element_Kinds;
Implicit : Boolean;
Inherited : Boolean;
Instance : Boolean;
Spec_Case : Special_Cases;
Norm_Case : Normalization_Cases;
Par_Count : Nat;
Character_Code : Char_Code)
return Element;
-- Constructs and returns the ASIS Element value on the base of
-- Element attributes
-- Note, that it should not be any parameter passed for the
-- Enclosing_Tree field, because this field should be set equal
-- to the Id of the tree being currently accessed!
-- Note also, that it should not be any parameter passed for the
-- Rel_Scr field, because this field should be computed as the
-- difference between the source location of the node upon
-- the given element is to be built (that is, passed as the
-- actual for the Node parameter, and the top node of the
-- Element's enclosing Unit.
--
-- It is supposed, that this function is called as the part of the
-- constructing of the new element during processing some ASIS
-- query, so the actuals for Node, R_Node and the current setting of
-- the top node for the Unit pointed by Encl_Unit are consistent.
-- See also A4G.Mapping (body).
function Set_In_List
(EL : Element_List;
Node_Field_1 : Node_Id := Empty;
Implicit : Boolean := False;
Inherited : Boolean := False)
return Element_List;
-- For all the Elements in EL sets their fields Node_Field_1,
-- Is_Part_Of_Implicit, Is_Part_Of_Inherited to the values passed as
-- actuals accordingly for Node_Field_1, Implicit and Inherited.
procedure Convert_To_Limited_View (El : in out Asis.Element);
-- Provided that A4G.A_Sem.Belongs_To_Limited_View (El), changes its
-- internal representation in such a way that El represents the limited
-- view of the corresponding type or package. This includes changing of the
-- Element kind for type elements.
Char_Literal_Spec_Template : Element;
-- Used as a template for creating lists of
-- An_Enumeration_Literal_Specification representing defining
-- character literals of types Standard.Character and
-- Standard.Wide_Character. This variable is initialized in package body
Numeric_Error_Template : Element;
-- Used as a template for the artificial elements representing the obsolete
-- renaming of Numeric_Error exception in package Standard and components
-- thereof.
-----------------------------------------------------------
-- Special processing for Elements representing root and --
-- universal numeric types in ASIS --
-----------------------------------------------------------
function Set_Root_Type_Declaration
(Int_Kind : Internal_Element_Kinds;
Cont : Context_Id)
return Element;
-- Constructs and returns the ASIS Element representing the declaration
-- of a root or universal numeric type. If an actual for Int_Kind does
-- not belong to Internal_Root_Type_Kinds, Nil_Element is returned.
-- Otherwise the child element of the result returned by the
-- Type_Declaration_View function should be of Int_Kind kind.
-- Every opened Context contains exactly one Element representing
-- the declaration of a given root or universal numeric type.
-- These elements (as well as their child elements) have no Node to
-- be based upon (they simply do not need such a Node), they are
-- implicit declarations located in the predefined Standard package.
function Is_Root_Num_Type (Declaration : Asis.Declaration) return Boolean;
-- Checks if Declaration is A_Type_Declaration Element representing
-- the declaration of a root or universal numeric type.
function Root_Type_Definition
(Declaration : Asis.Declaration)
return Asis.Definition;
-- Transforms A_Type_Declaration Element representing the declaration
-- of a root or universal numeric type into the corresponding type
-- definition (being of Root_Type_Kinds). This function does not
-- check if its argument really represents the declaration of a root
-- or universal numeric type
end Asis.Set_Get;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
stcarrez/dynamo,stcarrez/dynamo,stcarrez/dynamo
|
|
641703d109c3c8f28ff999124d0c2ba77a9b5f7a
|
src/asis/asis-errors.ads
|
src/asis/asis-errors.ads
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT INTERFACE COMPONENTS --
-- --
-- A S I S . E R R O R S --
-- --
-- S p e c --
-- --
-- $Revision: 14416 $
-- --
-- This specification is adapted from the Ada Semantic Interface --
-- Specification Standard (ISO/IEC 15291) for use with GNAT. In accordance --
-- with the copyright of that document, you can freely copy and modify this --
-- specification, provided that if you redistribute a modified version, any --
-- changes that you have made are clearly indicated. --
-- --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- 4 package Asis.Errors
------------------------------------------------------------------------------
------------------------------------------------------------------------------
package Asis.Errors is
------------------------------------------------------------------------------
------------------------------------------------------------------------------
--
-- ASIS reports all operational errors by raising an exception. Whenever an
-- ASIS implementation raises one of the exceptions declared in package
-- Asis.Exceptions, it will previously have set the values returned by the
-- Status and Diagnosis queries to indicate the cause of the error. The
-- possible values for Status are indicated in the definition of Error_Kinds
-- below, with suggestions for the associated contents of the Diagnosis
-- string as a comment.
--
-- The Diagnosis and Status queries are provided in the Asis.Implementation
-- package to supply more information about the reasons for raising any
-- exception.
--
-- ASIS applications are encouraged to follow this same convention whenever
-- they explicitly raise any ASIS exception--always record a Status and
-- Diagnosis prior to raising the exception.
------------------------------------------------------------------------------
-- 4.1 type Error_Kinds
------------------------------------------------------------------------------
-- This enumeration type describes the various kinds of errors.
--
type Error_Kinds is (
Not_An_Error, -- No error is presently recorded
Value_Error, -- Routine argument value invalid
Initialization_Error, -- ASIS is uninitialized
Environment_Error, -- ASIS could not initialize
Parameter_Error, -- Bad Parameter given to Initialize
Capacity_Error, -- Implementation overloaded
Name_Error, -- Context/unit not found
Use_Error, -- Context/unit not use/open-able
Data_Error, -- Context/unit bad/invalid/corrupt
Text_Error, -- The program text cannot be located
Storage_Error, -- Storage_Error suppressed
Obsolete_Reference_Error, -- Argument or result is invalid due to
-- and inconsistent compilation unit
Unhandled_Exception_Error, -- Unexpected exception suppressed
Not_Implemented_Error, -- Functionality not implemented
Internal_Error); -- Implementation internal failure
end Asis.Errors;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
stcarrez/dynamo,stcarrez/dynamo,stcarrez/dynamo
|
|
90cc3902449a670a24377356a0d329d59e201f36
|
src/el-beans-methods.ads
|
src/el-beans-methods.ads
|
-----------------------------------------------------------------------
-- EL.Beans.Methods -- Bean methods
-- Copyright (C) 2010 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Strings;
package EL.Beans.Methods is
pragma Preelaborate;
type Method_Binding is tagged limited record
Name : Util.Strings.Name_Access;
end record;
type Method_Binding_Access is access constant Method_Binding'Class;
type Method_Binding_Array is array (Natural range <>) of Method_Binding_Access;
type Method_Binding_Array_Access is access constant Method_Binding_Array;
type Method_Bean is limited Interface;
type Method_Bean_Access is access all Method_Bean'Class;
function Get_Method_Bindings (From : in Method_Bean)
return Method_Binding_Array_Access is abstract;
end EL.Beans.Methods;
|
Declare the method binding types
|
Declare the method binding types
|
Ada
|
apache-2.0
|
stcarrez/ada-el
|
|
5837509c5270507efc13ce57d58d200d0bfbbca1
|
src/asis/a4g-a_opt.ads
|
src/asis/a4g-a_opt.ads
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . A _ O P T --
-- --
-- S p e c --
-- --
-- Copyright (C) 1995-2012, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
-- This package contains global switches set by the
-- Asis_Environment.Initialize routine from the Parameters siting and
-- referenced throughout the ASIS-for-GNAT
--
-- This package may be considered as an ASIS analog of the GNAT Opt
-- package
package A4G.A_Opt is
Is_Initialized : Boolean := False;
-- flag indicating if the environment has already been initialized.
Was_Initialized_At_Least_Once : Boolean := False;
-- flag indicating if the environment was initialized at least
-- once during the current launch of an ASIS application
type ASIS_Warning_Mode_Type is (Suppress, Normal, Treat_As_Error);
ASIS_Warning_Mode : ASIS_Warning_Mode_Type := Normal;
-- Controls treatment of warning messages. If set to Suppress, warning
-- messages are not generated at all. In Normal mode, they are generated
-- but do not count as errors. In Treat_As_Error mode, a warning is
-- treated as an error: ASIS_Failed is raised and the warning message is
-- sent to an ASIS Diagnosis string.
Strong_Version_Check : Boolean := True;
-- Strong version check means that version strings read from the tree and
-- stored in Gnatvsn are compared. Weak check means comparing ASIS version
-- numbers. See BA23-002
Generate_Bug_Box : Boolean := True;
-- Flag indicating if the ASIS bug box should be generated into Stderr
-- when an ASIS implementation bug is detected.
Keep_Going : Boolean := False;
-- Flag indicating if the exit to OS should NOT be generated in case if
-- ASIS internal implementation error. Set ON by Initialize '-k' parameter.
ASIS_2005_Mode_Internal : Boolean := True;
-- If this switch is ON, ASIS detects as predefined units also units listed
-- as predefined in the 2005 revision of the Ada Standard. Now this flag is
-- always ON, and we do not have any parameter to tell ASIS that only
-- Ada 95 predefined units should be classified as predefined Compilation
-- Units in ASIS.
procedure Process_Initialization_Parameters (Parameters : String);
-- Processes a Parameters string passed to the
-- Asis.Implementation.Initialize query: check parameters and makes the
-- corresponding settings for ASIS global switches and flags.
procedure Process_Finalization_Parameters (Parameters : String);
-- Processes a Parameters string passed to the
-- Asis.Implementation.Finalize query.
procedure Set_Off;
-- Sets Is_Initialized flag OFF and then sets all the global switches
-- except Was_Initialized_At_Least_Once in the initial (default) position.
-- Is to be called by Asis_Environment.Finalize
-- the type declarations below should probably be moved into A_Types???
type Context_Mode is
-- different ways to define an ASIS Context:
(One_Tree,
-- a Context is made up by only one tree file
N_Trees,
-- a Context is made up by N tree files
Partition,
-- a partition Context
All_Trees);
-- all the tree files in tree search path are considered as making up a
-- given Context
type Tree_Mode is
-- how ASIS deals with tree files
(On_The_Fly,
-- trees are created on the fly, created trees are reused as long as a
-- Context remains opened
Pre_Created,
-- only those trees which have been created before a Context is opened
-- are used
Mixed,
-- mixed approach - if ASIS cannot find a needed tree, it tries to
-- create it on the fly
Incremental,
-- Similar to Mixed, but these mode goes beyond the ASIS standard and
-- allows to change the environment when the Context remains open:
-- - when the Context is opened, all the existing trees are processed;
-- - if ASIS can not find a needed tree, it tries to create it on the
-- fly, and it refreshes the information in the Context unit table
-- using the data from this newly created tree;
-- - any access to a unit or to an element checks that a tree to be
-- accessed is consistent with the sources
-- ???? This documentation definitely needs revising???
GNSA
-- Any tree is created on the fly by calling GNSA. It is not written
-- in a tree file and then read back by ASIS, but it is left in the
-- same data structures where it has been created, and after that ASIS
-- works on the same data structures.
);
type Source_Mode is
-- how ASIS takes into account source files when checking the consistency
(All_Sources,
-- sources of all the units from a given Context (except the predefined
-- Standard package) should be around, and they should be the same as
-- the sources from which tree files making up the Context were created
Existing_Sources,
-- If for a given unit from the Context the corresponding source file
-- exists, it should be the same as those used to create tree files
-- making up the Context
No_Sources);
-- Existing source files are not taken into account when checking the
-- consistency of tree files
end A4G.A_Opt;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen
|
|
57e870ffb474b1846b7306e5db6f4b0b1d6cdced
|
src/ado-queries.ads
|
src/ado-queries.ads
|
-----------------------------------------------------------------------
-- ADO Databases -- Database Objects
-- Copyright (C) 2009, 2010 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Strings;
with ADO.SQL;
package ADO.Queries is
type Query_Definition_Record is limited record
Name : Util.Strings.Name_Access;
end record;
type Query_Definition is access all Query_Definition_Record;
type Context is new ADO.SQL.Query with null record;
end ADO.Queries;
|
Support for queries
|
Support for queries
|
Ada
|
apache-2.0
|
stcarrez/ada-ado
|
|
ad16a1169380c26bf3277114a5473a324534db71
|
src/asis/a4g-tree_rec.ads
|
src/asis/a4g-tree_rec.ads
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . T R E E _ R E C --
-- --
-- S p e c --
-- --
-- Copyright (c) 1995-2005, 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). --
-- --
------------------------------------------------------------------------------
-- This package defines the Tree_Rec type, which is used as an actual for
-- the instantiation of the GANT Table creating the type for the Context tree
-- table. This table stores information about trees (tree output files)
-- cerating the Ada environment processed by a given Context
with A4G.A_Types; use A4G.A_Types;
with Types; use Types;
package A4G.Tree_Rec is
-- See the A4G.Contt.TT package for the details of maintaining
-- the tree tables
------------------------------
-- Tree_Rec type definition --
------------------------------
-- Similar to the Contexts' Unit tables and Source File tables,
-- Tree tables are organised as Name tables (for the names of the
-- tree files), and each entry in such a Name table has additional
-- fields for information related to tree files handling in ASIS.
type Tree_Record is record
--------------------------------
-- Fields for Tree Name Table --
--------------------------------
Tree_Name_Chars_Index : Int;
-- Starting locations of characters in the Name_Chars table minus
-- one (i.e. pointer to character just before first character). The
-- reason for the bias of one is that indexes in Name_Buffer are
-- one's origin, so this avoids unnecessary adds and subtracts of 1.
Tree_Name_Len : Short;
-- Lengths of the names in characters
Int_Info : Int;
-- Int Value associated with this tree
---------------------
-- Tree attributes --
---------------------
Main_Unit : Unit_Id;
-- The ASIS Compilation Unit, correspondig to the main unit in
-- the tree
Main_Top : Node_Id;
-- The top node (having N_Compilation_Unit Node Kind) of Main_Unit
-- DO WE REALLY NEED IT?
Units : Elist_Id;
-- The list of all the Units (or all the Units except Main_Unit?)
-- which may be processed on the base of this tree, [each Unit
-- is accompanied by its top node, which it has in the given tree
-- ??? Not implemented for now!]
end record;
end A4G.Tree_Rec;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen
|
|
dc369c1be258440825c0bd5c2ef0ec504c75ded4
|
src/util-strings-sets.ads
|
src/util-strings-sets.ads
|
-----------------------------------------------------------------------
-- Util-strings-sets -- Set of strings
-- Copyright (C) 2011 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Hash;
with Ada.Containers.Indefinite_Hashed_Sets;
-- The <b>Util.Strings.Sets</b> package provides an instantiation
-- of a hashed set with Strings.
package Util.Strings.Sets is new Ada.Containers.Indefinite_Hashed_Sets
(Element_Type => String,
Hash => Ada.Strings.Hash,
Equivalent_Elements => "=");
|
Define the set of string package
|
Define the set of string package
|
Ada
|
apache-2.0
|
stcarrez/ada-util,stcarrez/ada-util
|
|
d749b6c1680c2797fe59e72000de877cb511b79f
|
src/sys/serialize/util-properties-form.adb
|
src/sys/serialize/util-properties-form.adb
|
-----------------------------------------------------------------------
-- util-properties-form -- read json files into properties
-- Copyright (C) 2020 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Serialize.IO.Form;
with Util.Stacks;
with Util.Log;
with Util.Beans.Objects;
package body Util.Properties.Form is
type Natural_Access is access all Natural;
package Length_Stack is new Util.Stacks (Element_Type => Natural,
Element_Type_Access => Natural_Access);
type Parser is abstract limited new Util.Serialize.IO.Reader with record
Base_Name : Ada.Strings.Unbounded.Unbounded_String;
Lengths : Length_Stack.Stack;
Separator : Ada.Strings.Unbounded.Unbounded_String;
Separator_Length : Natural;
end record;
-- Start a new object associated with the given name. This is called when
-- the '{' is reached. The reader must be updated so that the next
-- <b>Set_Member</b> procedure will associate the name/value pair on the
-- new object.
overriding
procedure Start_Object (Handler : in out Parser;
Name : in String;
Logger : in out Util.Log.Logging'Class);
-- Finish an object associated with the given name. The reader must be
-- updated to be associated with the previous object.
overriding
procedure Finish_Object (Handler : in out Parser;
Name : in String;
Logger : in out Util.Log.Logging'Class);
overriding
procedure Start_Array (Handler : in out Parser;
Name : in String;
Logger : in out Util.Log.Logging'Class);
overriding
procedure Finish_Array (Handler : in out Parser;
Name : in String;
Count : in Natural;
Logger : in out Util.Log.Logging'Class);
-- -----------------------
-- Start a new object associated with the given name. This is called when
-- the '{' is reached. The reader must be updated so that the next
-- <b>Set_Member</b> procedure will associate the name/value pair on the
-- new object.
-- -----------------------
overriding
procedure Start_Object (Handler : in out Parser;
Name : in String;
Logger : in out Util.Log.Logging'Class) is
pragma Unreferenced (Logger);
begin
if Name'Length > 0 then
Ada.Strings.Unbounded.Append (Handler.Base_Name, Name);
Ada.Strings.Unbounded.Append (Handler.Base_Name, Handler.Separator);
Length_Stack.Push (Handler.Lengths);
Length_Stack.Current (Handler.Lengths).all := Name'Length + Handler.Separator_Length;
end if;
end Start_Object;
-- -----------------------
-- Finish an object associated with the given name. The reader must be
-- updated to be associated with the previous object.
-- -----------------------
overriding
procedure Finish_Object (Handler : in out Parser;
Name : in String;
Logger : in out Util.Log.Logging'Class) is
pragma Unreferenced (Logger);
Len : constant Natural := Ada.Strings.Unbounded.Length (Handler.Base_Name);
begin
if Name'Length > 0 then
Ada.Strings.Unbounded.Delete (Handler.Base_Name,
Len - Name'Length - Handler.Separator_Length + 1, Len);
end if;
end Finish_Object;
overriding
procedure Start_Array (Handler : in out Parser;
Name : in String;
Logger : in out Util.Log.Logging'Class) is
begin
Handler.Start_Object (Name, Logger);
end Start_Array;
overriding
procedure Finish_Array (Handler : in out Parser;
Name : in String;
Count : in Natural;
Logger : in out Util.Log.Logging'Class) is
begin
Parser'Class (Handler).Set_Member ("length", Util.Beans.Objects.To_Object (Count), Logger);
Handler.Finish_Object (Name, Logger);
end Finish_Array;
-- -----------------------
-- Parse the application/form content and put the flattened content in the property manager.
-- -----------------------
procedure Parse_Form (Manager : in out Util.Properties.Manager'Class;
Content : in String;
Flatten_Separator : in String := ".") is
type Local_Parser is new Parser with record
Manager : access Util.Properties.Manager'Class;
end record;
-- Set the name/value pair on the current object. For each active mapping,
-- find whether a rule matches our name and execute it.
overriding
procedure Set_Member (Handler : in out Local_Parser;
Name : in String;
Value : in Util.Beans.Objects.Object;
Logger : in out Util.Log.Logging'Class;
Attribute : in Boolean := False);
-- -----------------------
-- Set the name/value pair on the current object. For each active mapping,
-- find whether a rule matches our name and execute it.
-- -----------------------
overriding
procedure Set_Member (Handler : in out Local_Parser;
Name : in String;
Value : in Util.Beans.Objects.Object;
Logger : in out Util.Log.Logging'Class;
Attribute : in Boolean := False) is
pragma Unreferenced (Logger, Attribute);
begin
Handler.Manager.Set (Ada.Strings.Unbounded.To_String (Handler.Base_Name) & Name,
Util.Beans.Objects.To_String (Value));
end Set_Member;
P : Local_Parser;
R : Util.Serialize.IO.Form.Parser;
begin
P.Separator := Ada.Strings.Unbounded.To_Unbounded_String (Flatten_Separator);
P.Separator_Length := Flatten_Separator'Length;
P.Manager := Manager'Access;
R.Parse_String (Content, P);
if R.Has_Error then
raise Util.Serialize.IO.Parse_Error;
end if;
end Parse_Form;
end Util.Properties.Form;
|
Implement the Parse_Form procedure (taken from Parse_JSON)
|
Implement the Parse_Form procedure (taken from Parse_JSON)
|
Ada
|
apache-2.0
|
stcarrez/ada-util,stcarrez/ada-util
|
|
775fba52a0f5a55be037e9a80a587a0298925f75
|
src/asis/a4g-expr_sem.ads
|
src/asis/a4g-expr_sem.ads
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . E X P R _ S E M --
-- --
-- S p e c --
-- --
-- Copyright (c) 1995-2005, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
-- This package contains routines needed for semantic queries from
-- the Asis.Expressions package
with Asis; use Asis;
package A4G.Expr_Sem is
-- All the routines defined in this package do not check their
-- arguments - a caller is responsible for the proper use of these
-- routines
function Expr_Type (Expression : Asis.Expression) return Asis.Declaration;
-- using the fact, that Expression is of An_Expression kind and that
-- the Etype field is set for its Node, this function finds the
-- type declaration which should be returned as the result of
-- Corresponding_Expression_Type (Expression)
function Identifier_Name_Definition
(Reference_I : Element)
return Asis.Defining_Name;
function Character_Literal_Name_Definition
(Reference_Ch : Element)
return Asis.Defining_Name;
-- Each of these two functions provides an Element representing the
-- defining occurrence for its argument, provided that the argument is
-- of appropriate kind and all the necessary checks have already been
-- done
function Is_Reference
(Name : Asis.Element;
Ref : Asis.Element)
return Boolean;
-- Provided that Name is of A_Defining_Name kind, this function checks is
-- Ref is a reference to this name. It is an error to call this function
-- for any Element which is not of A_Defining_Name as an actual for Name.
-- Any Element is acceptable as an actual for Ref, and this function does
-- not raise any exception in any case.
--
-- ??? Should we move this function into Asis.Extensions?
function Needs_List (Reference : Asis.Element) return Boolean;
-- Supposed to be applied to the argument of the
-- Corresponding_Name_Definition_List query. Checks if Reference
-- is ambiguous and refers to more than one entity.
procedure Collect_Overloaded_Entities (Reference : Asis.Element);
-- Supposed to be called for the argument of the
-- Corresponding_Name_Definition_List query in case if Needs_List is
-- True for it. Collects in the Element Table all the defining
-- names referred by Reference.
-- This procedure supposes, that the Element Table is already initialized
-- in the calling context
procedure Correct_Result
(Result : in out Element;
Reference : Element);
-- This procedure implements a most complicated case for the fix needed
-- for BB10-002. It correct the result in the situation when we have nested
-- generic instantiations, and the named number in question is declared in
-- template. In this situation the approach based on Original_Entity field
-- returns the defining name from the template, but we need the defining
-- name from the outer instantiation (see the test for BB10-002 for more
-- details)
function Is_From_Dispatching_Call (Reference : Element) return Boolean;
-- This function detects if its argument is a name from a dispatching call
-- for that Corresponding_Name_Definition should return Nil_Element (that
-- is, a name of a called subprogram or the name of a formal parameter from
-- a named association)
function Is_Implicit_Formal_Par (Result_El : Element) return Boolean;
-- Is supposed to be applied to the result of Identifier_Name_Definition.
-- Checks if this result corresponds to the situation when the argument of
-- Identifier_Name_Definition is the reference to a formal parameter from
-- implicit inherited subprogram
procedure Correct_Impl_Form_Par
(Result : in out Element;
Reference : Element);
-- This procedure is supposed to be called is Result is the result of the
-- call to Identifier_Name_Definition, and Is_Implicit_Formal_Par yields
-- True for Result. It creates the correct defining name for this iplicit
-- inherited formal parameter.
end A4G.Expr_Sem;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
stcarrez/dynamo,stcarrez/dynamo,stcarrez/dynamo
|
|
0325d9b6a1c0ab7adb3f13e3bdff931571839738
|
src/asis/asis-clauses.adb
|
src/asis/asis-clauses.adb
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A S I S . C L A U S E S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1995-2012, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
with Asis.Errors; use Asis.Errors;
with Asis.Exceptions; use Asis.Exceptions;
with Asis.Set_Get; use Asis.Set_Get;
with A4G.Mapping; use A4G.Mapping;
with A4G.Vcheck; use A4G.Vcheck;
with Atree; use Atree;
with Namet; use Namet;
with Nlists; use Nlists;
with Sinfo; use Sinfo;
with Snames; use Snames;
package body Asis.Clauses is
Package_Name : constant String := "Asis.Clauses.";
------------------
-- Clause_Names --
------------------
function Clause_Names (Clause : Asis.Element) return Asis.Element_List is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Clause);
Arg_Node : Node_Id;
Result_List : List_Id;
Result_Len : Natural := 1;
Withed_Uname : Node_Id;
begin
Check_Validity (Clause, Package_Name & "Clause_Names");
if not (Arg_Kind = A_Use_Package_Clause or else
Arg_Kind = A_Use_Type_Clause or else
Arg_Kind = A_Use_All_Type_Clause or else -- Ada 2012
Arg_Kind = A_With_Clause)
then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Clause_Names",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Clause);
if Arg_Kind = A_With_Clause then
-- first, computing the number of names listed in the argument
-- with clause
-- Note that we should skip implicit with cleause that may be added
-- by front-end
while not (Comes_From_Source (Arg_Node)
and then
Last_Name (Arg_Node))
loop
if Comes_From_Source (Arg_Node) then
Result_Len := Result_Len + 1;
end if;
Arg_Node := Next (Arg_Node);
end loop;
declare
Result_List : Asis.Element_List (1 .. Result_Len);
begin
Arg_Node := Node (Clause);
for I in 1 .. Result_Len loop
Withed_Uname := Sinfo.Name (Arg_Node);
Result_List (I) := Node_To_Element_New
(Starting_Element => Clause,
Node => Withed_Uname);
Arg_Node := Next (Arg_Node);
while Present (Arg_Node)
and then
not Comes_From_Source (Arg_Node)
loop
Arg_Node := Next (Arg_Node);
end loop;
end loop;
return Result_List;
end;
else
if Nkind (Arg_Node) = N_Use_Package_Clause then
Result_List := Names (Arg_Node);
else
Result_List := Subtype_Marks (Arg_Node);
end if;
return N_To_E_List_New (List => Result_List,
Starting_Element => Clause);
end if;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Clause_Names",
Argument => Clause);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Clause_Names",
Ex => Ex,
Arg_Element => Clause);
end Clause_Names;
-------------------------------
-- Component_Clause_Position --
-------------------------------
function Component_Clause_Position
(Clause : Asis.Component_Clause)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Clause);
Arg_Node : Node_Id;
begin
Check_Validity (Clause, Package_Name & "Component_Clause_Position");
if not (Arg_Kind = A_Component_Clause) then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Component_Clause_Position",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Clause);
return Node_To_Element_New (Node => Position (Arg_Node),
Starting_Element => Clause);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Component_Clause_Position",
Argument => Clause);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Component_Clause_Position",
Ex => Ex,
Arg_Element => Clause);
end Component_Clause_Position;
----------------------------
-- Component_Clause_Range --
----------------------------
function Component_Clause_Range
(Clause : Asis.Component_Clause)
return Asis.Discrete_Range
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Clause);
Arg_Node : Node_Id;
begin
Check_Validity (Clause, Package_Name & "Component_Clause_Range");
if not (Arg_Kind = A_Component_Clause) then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Component_Clause_Range",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Clause);
return Node_To_Element_New
(Node => Arg_Node,
Internal_Kind => A_Discrete_Simple_Expression_Range,
Starting_Element => Clause);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Component_Clause_Range",
Argument => Clause);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Component_Clause_Range",
Ex => Ex,
Arg_Element => Clause);
end Component_Clause_Range;
-----------------------
-- Component_Clauses --
-----------------------
function Component_Clauses
(Clause : Asis.Representation_Clause;
Include_Pragmas : Boolean := False)
return Asis.Component_Clause_List
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Clause);
Arg_Node : Node_Id;
begin
Check_Validity (Clause, Package_Name & "Component_Clauses");
if not (Arg_Kind = A_Record_Representation_Clause) then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Component_Clauses",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Clause);
return N_To_E_List_New
(List => Component_Clauses (Arg_Node),
Include_Pragmas => Include_Pragmas,
Starting_Element => Clause);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Component_Clauses",
Argument => Clause,
Bool_Par => Include_Pragmas);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Component_Clauses",
Ex => Ex,
Arg_Element => Clause,
Bool_Par_ON => Include_Pragmas);
end Component_Clauses;
---------------------------
-- Mod_Clause_Expression --
---------------------------
function Mod_Clause_Expression
(Clause : Asis.Representation_Clause)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Clause);
Arg_Node : Node_Id;
Mod_Clause_Node : Node_Id;
begin
Check_Validity (Clause, Package_Name & "Mod_Clause_Expression");
if not (Arg_Kind = A_Record_Representation_Clause) then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Mod_Clause_Expression",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Clause);
Mod_Clause_Node := Next (Arg_Node);
if Nkind (Mod_Clause_Node) = N_Attribute_Definition_Clause and then
From_At_Mod (Mod_Clause_Node)
then
Mod_Clause_Node := Sinfo.Expression (Mod_Clause_Node);
else
Mod_Clause_Node := Empty;
end if;
if No (Mod_Clause_Node) then
return Asis.Nil_Element;
else
return Node_To_Element_New
(Node => Mod_Clause_Node,
Starting_Element => Clause);
end if;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Mod_Clause_Expression",
Argument => Clause);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Mod_Clause_Expression",
Ex => Ex,
Arg_Element => Clause);
end Mod_Clause_Expression;
--------------------------------------
-- Representation_Clause_Expression --
--------------------------------------
function Representation_Clause_Expression
(Clause : Asis.Representation_Clause)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Clause);
Arg_Node : Node_Id;
Result_Node : Node_Id;
Result_Kind : Internal_Element_Kinds := Not_An_Element;
begin
Check_Validity (Clause,
Package_Name & "Representation_Clause_Expression");
if not (Arg_Kind = An_Attribute_Definition_Clause or else
Arg_Kind = An_Enumeration_Representation_Clause or else
Arg_Kind = An_At_Clause)
then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Representation_Clause_Expression",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Clause);
if Nkind (Arg_Node) = N_Enumeration_Representation_Clause then
Result_Node := Array_Aggregate (Arg_Node);
if Present (Expressions (Result_Node)) then
Result_Kind := A_Positional_Array_Aggregate;
else
Result_Kind := A_Named_Array_Aggregate;
end if;
else
Result_Node := Sinfo.Expression (Arg_Node);
end if;
return Node_To_Element_New (Node => Result_Node,
Internal_Kind => Result_Kind,
Starting_Element => Clause);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Representation_Clause_Expression",
Argument => Clause);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Representation_Clause_Expression",
Ex => Ex,
Arg_Element => Clause);
end Representation_Clause_Expression;
--------------------------------
-- Representation_Clause_Name --
--------------------------------
function Representation_Clause_Name
(Clause : Asis.Clause)
return Asis.Name
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Clause);
Arg_Node : Node_Id;
Result_Node : Node_Id;
Result_Element : Element;
Result_Kind : Internal_Element_Kinds := Not_An_Element;
Attr_Des : Name_Id;
-- needed for special processing of attribute definition clause
begin
Check_Validity (Clause, Package_Name & "Representation_Clause_Name");
if not (Arg_Kind = An_Attribute_Definition_Clause or else
Arg_Kind = An_Enumeration_Representation_Clause or else
Arg_Kind = A_Record_Representation_Clause or else
Arg_Kind = An_At_Clause or else
Arg_Kind = A_Component_Clause)
then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Representation_Clause_Name",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Clause);
if Nkind (Arg_Node) = N_Attribute_Definition_Clause then
-- for An_Attribute_Definition_Clause argument we have to return
-- as the result the Element of An_Attribute_Reference kind.
-- The tree does not contain the structures for attribute reference
-- in this case (and it should not, because, according to RM 95,
-- there is no attribute reference in the syntax structure of
-- an attribute definition clause, so we have to "emulate"
-- the result Elemet of An_Attribute_Reference kind on the base
-- of the same node
-- first, we have to define the exact kind of the "artificial"
-- attribute reference to be returned
Attr_Des := Chars (Arg_Node);
case Attr_Des is
when Name_Address =>
Result_Kind := An_Address_Attribute;
when Name_Alignment =>
Result_Kind := An_Alignment_Attribute;
when Name_Bit_Order =>
Result_Kind := A_Bit_Order_Attribute;
when Name_Component_Size =>
Result_Kind := A_Component_Size_Attribute;
when Name_External_Tag =>
Result_Kind := An_External_Tag_Attribute;
when Name_Input =>
Result_Kind := An_Input_Attribute;
when Name_Machine_Radix =>
Result_Kind := A_Machine_Radix_Attribute;
when Name_Output =>
Result_Kind := An_Output_Attribute;
when Name_Read =>
Result_Kind := A_Read_Attribute;
when Name_Size =>
Result_Kind := A_Size_Attribute;
when Name_Small =>
Result_Kind := A_Small_Attribute;
when Name_Storage_Size =>
Result_Kind := A_Storage_Size_Attribute;
when Name_Storage_Pool =>
Result_Kind := A_Storage_Pool_Attribute;
when Name_Write =>
Result_Kind := A_Write_Attribute;
when others =>
-- "others" means Name_Object_Size and Name_Value_Size
Result_Kind := An_Implementation_Defined_Attribute;
end case;
Result_Element := Clause;
Set_Int_Kind (Result_Element, Result_Kind);
return Result_Element;
elsif Nkind (Arg_Node) = N_Component_Clause then
Result_Node := Component_Name (Arg_Node);
else
Result_Node := Sinfo.Identifier (Arg_Node);
end if;
return Node_To_Element_New (Node => Result_Node,
Starting_Element => Clause);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Representation_Clause_Name",
Argument => Clause);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Representation_Clause_Name",
Ex => Ex,
Arg_Element => Clause);
end Representation_Clause_Name;
end Asis.Clauses;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen
|
|
941d83b00691a6e5bb481181be53abbace7c044f
|
src/asf-routes-servlets-rest.ads
|
src/asf-routes-servlets-rest.ads
|
-----------------------------------------------------------------------
-- asf-reoutes-servlets-rest -- Route for the REST API
-- Copyright (C) 2016 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Rest;
package ASF.Routes.Servlets.Rest is
type Descriptor_Array is array (ASF.Rest.Method_Type) of ASF.Rest.Descriptor_Access;
-- The route has one descriptor for each REST method.
type API_Route_Type is new ASF.Routes.Servlets.Servlet_Route_Type with record
Descriptors : Descriptor_Array;
end record;
end ASF.Routes.Servlets.Rest;
|
Define the ASF.Routes.Servlets.Rest package for the REST route
|
Define the ASF.Routes.Servlets.Rest package for the REST route
|
Ada
|
apache-2.0
|
stcarrez/ada-asf,stcarrez/ada-asf,stcarrez/ada-asf
|
|
a6eb0cccfa30b0af44432107a30bda80335fa4ec
|
src/babel-stores-local.adb
|
src/babel-stores-local.adb
|
-----------------------------------------------------------------------
-- bkp-stores-local -- Store management for local files
-- Copyright (C) 2014 Stephane.Carrez
-- Written by Stephane.Carrez ([email protected])
--
-- 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.Directories;
with Ada.Strings.Unbounded;
with Ada.Streams.Stream_IO;
with Util.Log.Loggers;
with Util.Files;
with Interfaces;
package body Babel.Stores.Local is
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Babel.Stores.Local");
function Get_File_Size (Ent : in Ada.Directories.Directory_Entry_Type) return Ada.Directories.File_Size is
Size : Ada.Directories.File_Size;
begin
Size := Ada.Directories.Size (Ent);
return Size;
exception
when Constraint_Error =>
return Ada.Directories.File_Size (Interfaces.Unsigned_32'Last);
end Get_File_Size;
-- ------------------------------
-- Get the absolute path to access the local file.
-- ------------------------------
function Get_Absolute_Path (Store : in Local_Store_Type;
Path : in String) return String is
begin
if Ada.Strings.Unbounded.Length (Store.Root_Dir) = 0 then
return Path;
else
return Util.Files.Compose (Ada.Strings.Unbounded.To_String (Store.Root_Dir), Path);
end if;
end Get_Absolute_Path;
procedure Read (Store : in out Local_Store_Type;
Path : in String;
Into : in out Babel.Files.Buffers.Buffer) is
use Ada.Strings.Unbounded;
use type Ada.Streams.Stream_Element_Offset;
File : Ada.Streams.Stream_IO.File_Type;
Abs_Path : constant String := Store.Get_Absolute_Path (Path);
begin
Ada.Streams.Stream_IO.Open (File, Ada.Streams.Stream_IO.In_File, Abs_Path);
Ada.Streams.Stream_IO.Read (File, Into.Data, Into.Last);
Ada.Streams.Stream_IO.Close (File);
end Read;
procedure Write (Store : in out Local_Store_Type;
Path : in String;
Into : in Babel.Files.Buffers.Buffer) is
use Ada.Strings.Unbounded;
use type Ada.Streams.Stream_Element_Offset;
File : Ada.Streams.Stream_IO.File_Type;
Abs_Path : constant String := Store.Get_Absolute_Path (Path);
begin
Ada.Streams.Stream_IO.Open (File, Ada.Streams.Stream_IO.Out_File, Abs_Path);
Ada.Streams.Stream_IO.Write (File, Into.Data (Into.Data'First .. Into.Last));
Ada.Streams.Stream_IO.Close (File);
end Write;
procedure Scan (Store : in out Local_Store_Type;
Path : in String;
Into : in out Babel.Files.File_Container'Class;
Filter : in Babel.Filters.Filter_Type'Class) is
use Ada.Directories;
use type Babel.Files.Directory_Vector_Access;
Search_Filter : constant Ada.Directories.Filter_Type := (Ordinary_File => True,
Ada.Directories.Directory => True,
Special_File => False);
Search : Search_Type;
Ent : Directory_Entry_Type;
New_File : Babel.Files.File;
Child : Babel.Files.Directory;
begin
Log.Info ("Scan directory {0}", Path);
Start_Search (Search, Directory => Path, Pattern => "*", Filter => Search_Filter);
while More_Entries (Search) loop
Get_Next_Entry (Search, Ent);
declare
Name : constant String := Simple_Name (Ent);
Kind : constant File_Kind := Ada.Directories.Kind (Ent);
begin
if Kind = Ordinary_File then
if Filter.Is_Accepted (Kind, Path, Name) then
New_File.Name := Ada.Strings.Unbounded.To_Unbounded_String (Name);
New_File.Size := Get_File_Size (Ent);
Into.Add_File (Path, New_File);
end if;
elsif Name /= "." and Name /= ".." and Filter.Is_Accepted (Kind, Path, Name) then
-- if Into.Children = null then
-- Into.Children := new Babel.Files.Directory_Vector;
-- end if;
-- Child.Name := Ada.Strings.Unbounded.To_Unbounded_String (Name);
-- Into.Children.Append (Child);
-- Into.Tot_Dirs := Into.Tot_Dirs + 1;
Into.Add_Directory (Path, Name);
end if;
end;
end loop;
exception
when E : others =>
Log.Error ("Exception ", E);
end Scan;
-- ------------------------------
-- Set the root directory for the local store.
-- ------------------------------
procedure Set_Root_Directory (Store : in out Local_Store_Type;
Path : in String) is
begin
Store.Root_Dir := Ada.Strings.Unbounded.To_Unbounded_String (Path);
end Set_Root_Directory;
end Babel.Stores.Local;
|
Store implementation to access files on the host computer
|
Store implementation to access files on the host computer
|
Ada
|
apache-2.0
|
stcarrez/babel
|
|
e77556ac73b62d0f7dc0d2995216527741ab497f
|
src/asis/a4g-span_beginning.ads
|
src/asis/a4g-span_beginning.ads
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . S P A N _ B E G I N N I N G --
-- --
-- S p e c --
-- --
-- Copyright (C) 1995-2012, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
with Asis;
with A4G.Int_Knds; use A4G.Int_Knds;
with Types; use Types;
package A4G.Span_Beginning is
function Set_Image_Beginning (E : Asis.Element) return Source_Ptr;
-- The driver function for computing the beginning of the element image
-- in the GNAT source text buffer. In case if the argument is a labeled
-- statement returns the baginning of the first attachecd label. Otherwise
-- calls the element-kind-specific function for computing the image
-- beginning
-- The functions below compute the beginning of the text image for some
-- specific set of ELement kinds/
function Subunit_Beginning (E : Asis.Element) return Source_Ptr;
function Private_Unit_Beginning (E : Asis.Element) return Source_Ptr;
-- Assuming that E is an element representing the top Unit element of a
-- subunit or of a library item representing a private unit, returns the
-- source pointer to the beginning of the keyword SEPARATE or PRIVATE
-- accordingly.
function No_Search (E : Asis.Element) return Source_Ptr;
-- That is, we can just use Sloc from the node the Element is based upon.
function Search_Identifier_Beginning
(E : Asis.Element)
return Source_Ptr;
-- A special processing is needed for an identifier representing the
-- attribute designator in pseudo-attribute-reference in an attribute
-- definition clause and for 'Class attribute in aspect indication
function Search_Subtype_Indication_Beginning
(E : Asis.Element)
return Source_Ptr;
-- If the subtype mark is an expanded name, we have to look for its prefix
function Defining_Identifier_Beginning
(E : Asis.Element)
return Source_Ptr;
-- Returns the beginning of A_Defining_Identifier elements. In case of
-- labels we have to get rid of '<<'
function Short_Circuit_Beginning (E : Asis.Element) return Source_Ptr;
-- Returns the beginning of short circuit expression
function Membership_Test_Beginning (E : Asis.Element) return Source_Ptr;
-- Returns the beginning of membership test expression
function Null_Component_Beginning (E : Asis.Element) return Source_Ptr;
-- In case of A_Nil_Component element Sloc of its Node points to
-- "record" (it's easy) or to variant (it's a pain)
function Search_Prefix_Beginning (E : Asis.Element) return Source_Ptr;
-- Is needed when the Argument has a "prefix" in its structure, but Sloc
-- points somewhere inside the elemen structure
-- --|A2005 start
function Possible_Null_Exclusion_Beginning
(E : Asis.Element)
return Source_Ptr;
-- Should be used for constructs that can contain null_exclusion
function Possible_Overriding_Indicator_Beginning
(E : Asis.Element)
return Source_Ptr;
-- Is supposed to be used for some of the constructs that can contain
-- overriding_indicator
-- --|A2005 end
function Component_And_Parameter_Declaration_Beginning
(E : Asis.Element)
return Source_Ptr;
function Exception_Declaration_Beginning
(E : Asis.Element)
return Source_Ptr;
function Derived_Definition_Beginning (E : Asis.Element) return Source_Ptr;
function Type_Definition_Beginning (E : Asis.Element) return Source_Ptr;
function Interface_Definition_Beginning
(E : Asis.Element)
return Source_Ptr;
function Tagged_Type_Definition_Beginning
(E : Asis.Element)
return Source_Ptr;
function Simple_Expression_Range_Beginning
(E : Asis.Element)
return Source_Ptr;
function Component_Definition_Beginning
(E : Asis.Element)
return Source_Ptr;
function Search_Left_Parenthesis_After (E : Asis.Element) return Source_Ptr;
-- Is needed when the Element does not have its "own" node (in particular,
-- for A_Known_Discriminant_Part Element)
function Private_Extension_Definition_Beginning
(E : Asis.Element)
return Source_Ptr;
function Private_Type_Definition_Beginning
(E : Asis.Element)
return Source_Ptr;
function Explicit_Dereference_Beginning
(E : Asis.Element)
return Source_Ptr;
function Function_Call_Beginning (E : Asis.Element) return Source_Ptr;
function Indexed_Component_Beginning (E : Asis.Element) return Source_Ptr;
function Component_Association_Beginning
(E : Asis.Element)
return Source_Ptr;
function Association_Beginning
(E : Asis.Element)
return Source_Ptr;
function Parenthesized_Expression_Beginning
(E : Asis.Element)
return Source_Ptr;
function Assignment_Statement_Beginning
(E : Asis.Element)
return Source_Ptr;
function Named_Statement_Beginning
(E : Asis.Element)
return Source_Ptr;
-- Takes care of loop and block names
function Call_Statement_Beginning (E : Asis.Element) return Source_Ptr;
function While_Loop_Statement_Beginning
(E : Asis.Element)
return Source_Ptr;
function For_Loop_Statement_Beginning (E : Asis.Element) return Source_Ptr;
function Else_Path_Beginning (E : Asis.Element) return Source_Ptr;
function With_Clause_Beginning (E : Asis.Element) return Source_Ptr;
function Component_Clause_Beginning (E : Asis.Element) return Source_Ptr;
function Subprogram_Spec_Beginning (E : Asis.Element) return Source_Ptr;
function Formal_Object_Declaration_Beginning
(E : Asis.Element)
return Source_Ptr;
function A_Then_Abort_Path_Beginning (E : Asis.Element) return Source_Ptr;
function Select_Alternative_Beginning (E : Asis.Element) return Source_Ptr;
-- --|A2015 start
function Case_Expression_Path_Beginning
(E : Asis.Element)
return Source_Ptr;
function If_Expression_Beginning
(E : Asis.Element)
return Source_Ptr;
function Conditional_Expression_Path_Beginning
(E : Asis.Element)
return Source_Ptr;
function An_Else_Expression_Path_Beginning
(E : Asis.Element)
return Source_Ptr;
-- --|A2015 end
-- The look-up table below defines the mapping from Element kinds onto
-- specific routines for computing the Element image beginning
type Set_Source_Location_type is
access function (E : Asis.Element) return Source_Ptr;
Switch : array (Internal_Element_Kinds) of Set_Source_Location_type := (
An_All_Calls_Remote_Pragma ..
-- An_Asynchronous_Pragma
-- An_Atomic_Pragma
-- An_Atomic_Components_Pragma
-- An_Attach_Handler_Pragma
-- A_Controlled_Pragma
-- A_Convention_Pragma
-- An_Elaborate_All_Pragma
-- An_Elaborate_Body_Pragma
-- An_Export_Pragma
-- An_Import_Pragma
-- An_Inline_Pragma
-- An_Inspection_Point_Pragma
-- An_Interrupt_Handler_Pragma
-- An_Interrupt_Priority_Pragma
-- A_List_Pragma
-- A_Locking_Policy_Pragma
-- A_Normalize_Scalars_Pragma
-- An_Optimize_Pragma
-- A_Pack_Pragma
-- A_Page_Pragma
-- A_Preelaborate_Pragma
-- A_Priority_Pragma
-- A_Pure_Pragma
-- A_Queuing_Policy_Pragma
-- A_Remote_Call_Interface_Pragma
-- A_Remote_Types_Pragma
-- A_Restrictions_Pragma
-- A_Reviewable_Pragma
-- A_Shared_Passive_Pragma
-- A_Suppress_Pragma
-- A_Task_Dispatching_Policy_Pragma
-- A_Volatile_Pragma
-- A_Volatile_Components_Pragma
-- An_Implementation_Defined_Pragma
An_Unknown_Pragma => No_Search'Access,
A_Defining_Identifier => Defining_Identifier_Beginning'Access,
A_Defining_Character_Literal ..
-- A_Defining_Enumeration_Literal
-- A_Defining_Or_Operator
-- A_Defining_Xor_Operator
-- A_Defining_Equal_Operator
-- A_Defining_Not_Equal_Operator
-- A_Defining_Less_Than_Operator
-- A_Defining_Less_Than_Or_Equal_Operator
-- A_Defining_Greater_Than_Operator
-- A_Defining_Greater_Than_Or_Equal_Operator
-- A_Defining_Plus_Operator
-- A_Defining_Minus_Operator
-- A_Defining_Concatenate_Operator
-- A_Defining_Unary_Plus_Operator
-- A_Defining_Unary_Minus_Operator
-- A_Defining_Multiply_Operator
-- A_Defining_Divide_Operator
-- A_Defining_Mod_Operator
-- A_Defining_Rem_Operator
-- A_Defining_Exponentiate_Operator
-- A_Defining_Abs_Operator
A_Defining_Not_Operator => No_Search'Access,
A_Defining_Expanded_Name => Search_Prefix_Beginning'Access,
An_Ordinary_Type_Declaration ..
-- A_Task_Type_Declaration
-- A_Protected_Type_Declaration
-- An_Incomplete_Type_Declaration
-- A_Private_Type_Declaration
-- A_Private_Extension_Declaration
-- A_Subtype_Declaration
-- A_Variable_Declaration
-- A_Constant_Declaration
-- A_Deferred_Constant_Declaration
-- A_Single_Task_Declaration
-- A_Single_Protected_Declaration
-- An_Integer_Number_Decl
-- A_Real_Number_Declaration
-- An_Enumeration_Literal_Specification
A_Discriminant_Specification => No_Search'Access,
A_Component_Declaration =>
Component_And_Parameter_Declaration_Beginning'Access,
A_Loop_Parameter_Specification => No_Search'Access,
-- --|A2012 start
A_Generalized_Iterator_Specification => No_Search'Access, -- ???
An_Element_Iterator_Specification => No_Search'Access, -- ???
-- --|A2012 end
A_Procedure_Declaration ..
A_Function_Declaration => Subprogram_Spec_Beginning'Access,
-- --|A2005 start
A_Null_Procedure_Declaration => Subprogram_Spec_Beginning'Access,
-- --|A2005 end
-- --|A2012 start
An_Expression_Function_Declaration => Subprogram_Spec_Beginning'Access,
-- --|A2012 end
A_Parameter_Specification =>
Component_And_Parameter_Declaration_Beginning'Access,
A_Procedure_Body_Declaration ..
A_Function_Body_Declaration => Subprogram_Spec_Beginning'Access,
A_Package_Declaration ..
-- A_Package_Body_Declaration
-- An_Object_Renaming_Declaration
-- An_Exception_Renaming_Declaration
A_Package_Renaming_Declaration => No_Search'Access,
A_Procedure_Renaming_Declaration => Subprogram_Spec_Beginning'Access,
A_Function_Renaming_Declaration => Subprogram_Spec_Beginning'Access,
A_Generic_Package_Renaming_Declaration ..
-- A_Generic_Procedure_Renaming_Declaration
-- A_Generic_Function_Renaming_Declaration
-- A_Task_Body_Declaration
A_Protected_Body_Declaration => No_Search'Access,
An_Entry_Declaration => Possible_Overriding_Indicator_Beginning'Access,
An_Entry_Body_Declaration ..
An_Entry_Index_Specification => No_Search'Access,
A_Procedure_Body_Stub ..
A_Function_Body_Stub => Subprogram_Spec_Beginning'Access,
A_Package_Body_Stub ..
-- A_Task_Body_Stub
A_Protected_Body_Stub => No_Search'Access,
An_Exception_Declaration =>
Exception_Declaration_Beginning'Access,
A_Choice_Parameter_Specification ..
-- A_Generic_Procedure_Declaration
-- A_Generic_Function_Declaration
-- A_Generic_Package_Declaration
A_Package_Instantiation => No_Search'Access,
A_Procedure_Instantiation ..
A_Function_Instantiation =>
Possible_Overriding_Indicator_Beginning'Access,
A_Formal_Object_Declaration =>
Formal_Object_Declaration_Beginning'Access,
A_Formal_Type_Declaration ..
-- A_Formal_Procedure_Declaration
-- A_Formal_Function_Declaration
-- A_Formal_Package_Declaration
A_Formal_Package_Declaration_With_Box => No_Search'Access,
A_Derived_Type_Definition => Derived_Definition_Beginning'Access,
A_Derived_Record_Extension_Definition =>
Derived_Definition_Beginning'Access,
An_Enumeration_Type_Definition ..
-- A_Signed_Integer_Type_Definition
-- A_Modular_Type_Definition
---------------------------------------------------------
-- !!! They all are implicit and cannot have image
-- |
-- |-> A_Root_Integer_Definition
-- |-> A_Root_Real_Definition
-- |-> A_Root_Fixed_Definition
-- |-> A_Universal_Integer_Definition
-- |-> A_Universal_Real_Definition
-- +-> A_Universal_Fixed_Definition
---------------------------------------------------------
-- A_Floating_Point_Definition
-- An_Ordinary_Fixed_Point_Definition
-- A_Decimal_Fixed_Point_Definition
-- An_Unconstrained_Array_Definition
A_Constrained_Array_Definition => No_Search'Access,
A_Record_Type_Definition => Type_Definition_Beginning'Access,
A_Tagged_Record_Type_Definition =>
Tagged_Type_Definition_Beginning'Access,
-- --|A2005 start
An_Ordinary_Interface ..
-- A_Limited_Interface,
-- A_Task_Interface,
-- A_Protected_Interface,
A_Synchronized_Interface => Interface_Definition_Beginning'Access,
-- --|A2005 end
A_Pool_Specific_Access_To_Variable ..
-- An_Access_To_Variable
-- An_Access_To_Constant
-- An_Access_To_Procedure
-- An_Access_To_Protected_Procedure
-- An_Access_To_Function
An_Access_To_Protected_Function => No_Search'Access,
A_Subtype_Indication => Search_Subtype_Indication_Beginning'Access,
A_Range_Attribute_Reference => Search_Prefix_Beginning'Access,
A_Simple_Expression_Range => Simple_Expression_Range_Beginning'Access,
A_Digits_Constraint ..
-- A_Delta_Constraint
-- An_Index_Constraint
A_Discriminant_Constraint => No_Search'Access,
A_Component_Definition => Component_Definition_Beginning'Access,
A_Discrete_Subtype_Indication_As_Subtype_Definition =>
Search_Subtype_Indication_Beginning'Access,
A_Discrete_Range_Attribute_Reference_As_Subtype_Definition =>
Search_Prefix_Beginning'Access,
A_Discrete_Simple_Expression_Range_As_Subtype_Definition =>
Simple_Expression_Range_Beginning'Access,
A_Discrete_Subtype_Indication =>
Search_Subtype_Indication_Beginning'Access,
A_Discrete_Range_Attribute_Reference => Search_Prefix_Beginning'Access,
A_Discrete_Simple_Expression_Range =>
Simple_Expression_Range_Beginning'Access,
An_Unknown_Discriminant_Part ..
A_Known_Discriminant_Part => Search_Left_Parenthesis_After'Access,
A_Record_Definition ..
A_Null_Record_Definition => No_Search'Access,
A_Null_Component => Null_Component_Beginning'Access,
A_Variant_Part ..
-- A_Variant
An_Others_Choice => No_Search'Access,
-- --|A2005 start
An_Anonymous_Access_To_Variable ..
-- An_Anonymous_Access_To_Constant,
-- An_Anonymous_Access_To_Procedure,
-- An_Anonymous_Access_To_Protected_Procedure,
-- An_Anonymous_Access_To_Function,
An_Anonymous_Access_To_Protected_Function =>
Possible_Null_Exclusion_Beginning'Access,
-- --|A2005 end
A_Private_Type_Definition => Private_Type_Definition_Beginning'Access,
A_Tagged_Private_Type_Definition =>
Private_Type_Definition_Beginning'Access,
A_Private_Extension_Definition =>
Private_Extension_Definition_Beginning'Access,
A_Task_Definition => No_Search'Access,
A_Protected_Definition => No_Search'Access,
A_Formal_Private_Type_Definition =>
Private_Type_Definition_Beginning'Access,
A_Formal_Tagged_Private_Type_Definition =>
Private_Type_Definition_Beginning'Access,
A_Formal_Derived_Type_Definition => Derived_Definition_Beginning'Access,
A_Formal_Discrete_Type_Definition => No_Search'Access,
A_Formal_Signed_Integer_Type_Definition ..
-- A_Formal_Modular_Type_Definition
-- A_Formal_Floating_Point_Definition
-- A_Formal_Ordinary_Fixed_Point_Definition
A_Formal_Decimal_Fixed_Point_Definition => No_Search'Access,
A_Formal_Ordinary_Interface ..
-- A_Formal_Limited_Interface
-- A_Formal_Task_Interface
-- A_Formal_Protected_Interface
A_Formal_Synchronized_Interface => Interface_Definition_Beginning'Access,
A_Formal_Unconstrained_Array_Definition ..
-- A_Formal_Constrained_Array_Definition
-- A_Formal_Pool_Specific_Access_To_Variable
-- A_Formal_Access_To_Variable
-- A_Formal_Access_To_Constant
-- A_Formal_Access_To_Procedure
-- A_Formal_Access_To_Protected_Procedure
-- A_Formal_Access_To_Function
A_Formal_Access_To_Protected_Function => No_Search'Access,
An_Aspect_Specification => No_Search'Access,
An_Integer_Literal ..
-- A_Real_Literal
A_String_Literal => No_Search'Access,
An_Identifier => Search_Identifier_Beginning'Access,
An_And_Operator ..
-- An_Or_Operator
-- An_Xor_Operator
-- An_Equal_Operator
-- A_Not_Equal_Operator
-- A_Less_Than_Operator
-- A_Less_Than_Or_Equal_Operator
-- A_Greater_Than_Operator
-- A_Greater_Than_Or_Equal_Operator
-- A_Plus_Operator
-- A_Minus_Operator
-- A_Concatenate_Operator
-- A_Unary_Plus_Operator
-- A_Unary_Minus_Operator
-- A_Multiply_Operator
-- A_Divide_Operator
-- A_Mod_Operator
-- A_Rem_Operator
-- An_Exponentiate_Operator
-- An_Abs_Operator
-- A_Not_Operator
-- A_Character_Literal
An_Enumeration_Literal => No_Search'Access,
An_Explicit_Dereference => Explicit_Dereference_Beginning'Access,
A_Function_Call => Function_Call_Beginning'Access,
An_Indexed_Component => Indexed_Component_Beginning'Access,
A_Slice => Indexed_Component_Beginning'Access,
A_Selected_Component ..
-- An_Access_Attribute
-- An_Address_Attribute
-- An_Adjacent_Attribute
-- An_Aft_Attribute
-- An_Alignment_Attribute
-- A_Base_Attribute
-- A_Bit_Order_Attribute
-- A_Body_Version_Attribute
-- A_Callable_Attribute
-- A_Caller_Attribute
-- A_Ceiling_Attribute
-- A_Class_Attribute
-- A_Component_Size_Attribute
-- A_Compose_Attribute
-- A_Constrained_Attribute
-- A_Copy_Sign_Attribute
-- A_Count_Attribute
-- A_Definite_Attribute
-- A_Delta_Attribute
-- A_Denorm_Attribute
-- A_Digits_Attribute
-- An_Exponent_Attribute
-- An_External_Tag_Attribute
-- A_First_Attribute
-- A_First_Bit_Attribute
-- A_Floor_Attribute
-- A_Fore_Attribute
-- A_Fraction_Attribute
-- An_Identity_Attribute
-- An_Image_Attribute
-- An_Input_Attribute
-- A_Last_Attribute
-- A_Last_Bit_Attribute
-- A_Leading_Part_Attribute
-- A_Length_Attribute
-- A_Machine_Attribute
-- A_Machine_Emax_Attribute
-- A_Machine_Emin_Attribute
-- A_Machine_Mantissa_Attribute
-- A_Machine_Overflows_Attribute
-- A_Machine_Radix_Attribute
-- A_Machine_Rounds_Attribute
-- A_Max_Attribute
-- A_Max_Size_In_Storage_Elements_Attribute
-- A_Min_Attribute
-- A_Model_Attribute
-- A_Model_Emin_Attribute
-- A_Model_Epsilon_Attribute
-- A_Model_Mantissa_Attribute
-- A_Model_Small_Attribute
-- A_Modulus_Attribute
-- An_Output_Attribute
-- A_Partition_ID_Attribute
-- A_Pos_Attribute
-- A_Position_Attribute
-- A_Pred_Attribute
-- A_Range_Attribute
-- A_Read_Attribute
-- A_Remainder_Attribute
-- A_Round_Attribute
-- A_Rounding_Attribute
-- A_Safe_First_Attribute
-- A_Safe_Last_Attribute
-- A_Scale_Attribute
-- A_Scaling_Attribute
-- A_Signed_Zeros_Attribute
-- A_Size_Attribute
-- A_Small_Attribute
-- A_Storage_Pool_Attribute
-- A_Storage_Size_Attribute
-- A_Succ_Attribute
-- A_Tag_Attribute
-- A_Terminated_Attribute
-- A_Truncation_Attribute
-- An_Unbiased_Rounding_Attribute
-- An_Unchecked_Access_Attribute
-- A_Val_Attribute
-- A_Valid_Attribute
-- A_Value_Attribute
-- A_Version_Attribute
-- A_Wide_Image_Attribute
-- A_Wide_Value_Attribute
-- A_Wide_Width_Attribute
-- A_Width_Attribute
-- A_Write_Attribute
-- An_Implementation_Defined_Attribute
An_Unknown_Attribute => Search_Prefix_Beginning'Access,
A_Record_Aggregate ..
-- An_Extension_Aggregate
-- An_Positional_Array_Aggregate
A_Named_Array_Aggregate => No_Search'Access,
An_And_Then_Short_Circuit ..
An_Or_Else_Short_Circuit => Short_Circuit_Beginning'Access,
An_In_Membership_Test ..
A_Not_In_Membership_Test => Membership_Test_Beginning'Access,
A_Null_Literal => No_Search'Access,
A_Parenthesized_Expression =>
Parenthesized_Expression_Beginning'Access,
A_Type_Conversion => Search_Prefix_Beginning'Access,
A_Qualified_Expression => Search_Prefix_Beginning'Access,
An_Allocation_From_Subtype => No_Search'Access,
An_Allocation_From_Qualified_Expression => No_Search'Access,
-- --|A2012 start
A_Case_Expression => No_Search'Access,
An_If_Expression => If_Expression_Beginning'Access,
-- --|A2012 end
A_Pragma_Argument_Association => Association_Beginning'Access,
A_Discriminant_Association => Association_Beginning'Access,
A_Record_Component_Association => Component_Association_Beginning'Access,
An_Array_Component_Association => Component_Association_Beginning'Access,
A_Parameter_Association => Association_Beginning'Access,
A_Generic_Association => No_Search'Access,
A_Null_Statement => No_Search'Access,
An_Assignment_Statement => Assignment_Statement_Beginning'Access,
An_If_Statement => No_Search'Access,
A_Case_Statement => No_Search'Access,
A_Loop_Statement => Named_Statement_Beginning'Access,
A_While_Loop_Statement => While_Loop_Statement_Beginning'Access,
A_For_Loop_Statement => For_Loop_Statement_Beginning'Access,
A_Block_Statement => Named_Statement_Beginning'Access,
An_Exit_Statement => No_Search'Access,
A_Goto_Statement => No_Search'Access,
A_Procedure_Call_Statement => Call_Statement_Beginning'Access,
A_Return_Statement => No_Search'Access,
An_Accept_Statement => No_Search'Access,
An_Entry_Call_Statement => Call_Statement_Beginning'Access,
A_Requeue_Statement ..
-- A_Requeue_Statement_With_Abort
-- A_Delay_Until_Statement
-- A_Delay_Relative_Statement
-- A_Terminate_Alternative_Statement
-- A_Selective_Accept_Statement
-- A_Timed_Entry_Call_Statement
-- A_Conditional_Entry_Call_Statement
-- An_Asynchronous_Select_Statement
-- An_Abort_Statement
-- A_Raise_Statement
-- A_Code_Statement
-- An_If_Path
-- NOTE: There is no explicit node in GNAT AST tree corresponding to
-- this Internal_Element_Kind's. It's supposed that corresponding
-- Element's record field contains Source_Ptr type value that points to
-- word IF.
-- If it isn't so, we should change this part.
-- I believe it's more correct to have A_Then_Path in spite of
-- An_If_Path which should point to the word THEN.
An_Elsif_Path => No_Search'Access,
An_Else_Path => Else_Path_Beginning'Access,
A_Case_Path => No_Search'Access,
A_Select_Path ..
-- NOTE: There is no explicit node in GNAT AST tree corresponding to
-- this Internal_Element_Kind's. It's supposed that corresponding
-- Element's record field contains Source_Ptr type value that
-- points to word SELECT.
-- If it isn't so, we should change this part.
An_Or_Path => Select_Alternative_Beginning'Access,
-- NOTE: There is no explicit node in GNAT AST tree corresponding to
-- this Internal_Element_Kind's. It's supposed that corresponding
-- Element's record field contains Source_Ptr type value that points to
-- word OR. If it isn't so, we should change this part.
A_Then_Abort_Path => A_Then_Abort_Path_Beginning'Access,
-- --|A2015 start
A_Case_Expression_Path => Case_Expression_Path_Beginning'Access,
An_If_Expression_Path ..
An_Elsif_Expression_Path => Conditional_Expression_Path_Beginning'Access,
An_Else_Expression_Path => An_Else_Expression_Path_Beginning'Access,
-- --|A2015 end
A_Use_Package_Clause ..
-- A_Use_Type_Clause
A_Use_All_Type_Clause => No_Search'Access, -- Ada 2012
A_With_Clause => With_Clause_Beginning'Access,
An_Attribute_Definition_Clause ..
-- An_Enumeration_Representation_Clause
-- A_Record_Representation_Clause
An_At_Clause => No_Search'Access,
A_Component_Clause => Component_Clause_Beginning'Access,
An_Exception_Handler => No_Search'Access,
others => No_Search'Access);
end A4G.Span_Beginning;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen
|
|
c6f1be51a50c419529afed8472328eb0519ecfce
|
src/asis/a4g-queries.ads
|
src/asis/a4g-queries.ads
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . Q U E R I E S --
-- --
-- S p e c --
-- --
-- Copyright (c) 1995-2006, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adaccore.com). --
-- --
-- The original version of this component has been developed by Jean-Charles--
-- Marteau ([email protected]) and Serge Reboul --
-- ([email protected]), ENSIMAG High School Graduates (Computer --
-- sciences) Grenoble, France in Sema Group Grenoble, France. Now this --
-- component is maintained by the ASIS team --
-- --
------------------------------------------------------------------------------
with Asis; use Asis;
----------------------------------------------------------
-- The goal of this package is, when we have an element --
-- to let us have ALL the possible queries for that --
-- element that return its children. --
----------------------------------------------------------
package A4G.Queries is
-- There is 3 kinds of queries in Asis :
type Query_Kinds is
(Bug,
-- just for the discriminant default expression
Single_Element_Query,
-- Queries taking an element and returning an element.
Element_List_Query,
-- Queries taking an element and returning a list of elements.
Element_List_Query_With_Boolean
-- Queries taking an element and a boolean and returning a list
-- of elements.
);
type A_Single_Element_Query is access
function (Elem : Asis.Element) return Asis.Element;
type A_Element_List_Query is access
function (Elem : Asis.Element) return Asis.Element_List;
type A_Element_List_Query_With_Boolean is access
function
(Elem : Asis.Element;
Bool : Boolean)
return Asis.Element_List;
-- Discriminant record that can access any type of query.
type Func_Elem (Query_Kind : Query_Kinds := Bug) is record
case Query_Kind is
when Bug =>
null;
when Single_Element_Query =>
Func_Simple : A_Single_Element_Query;
when Element_List_Query =>
Func_List : A_Element_List_Query;
when Element_List_Query_With_Boolean =>
Func_List_Boolean : A_Element_List_Query_With_Boolean;
Bool : Boolean;
end case;
end record;
type Query_Array is array (Positive range <>) of Func_Elem;
-- an empty array, when the element is a terminal
No_Query : Query_Array (1 .. 0);
----------------------------------------------------
-- This function returns a Query_Array containing --
-- all the existing queries for that element. --
-- If an element has no children, No_Query is --
-- returned. --
----------------------------------------------------
function Appropriate_Queries (Element : Asis.Element) return Query_Array;
end A4G.Queries;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
stcarrez/dynamo,stcarrez/dynamo,stcarrez/dynamo
|
|
cc54f6dd2e877e152bdcf944bdcb375b6a8b4a06
|
src/wiki-plugins-templates.ads
|
src/wiki-plugins-templates.ads
|
-----------------------------------------------------------------------
-- wiki-plugins-template -- Template Plugin
-- Copyright (C) 2016 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 Wiki.Strings;
-- === Template Plugins ===
-- The <b>Wiki.Plugins.Templates</b> package defines an abstract template plugin.
-- To use the template plugin, the <tt>Get_Template</tt> procedure must be implemented.
-- It is responsible for getting the template content according to the plugin parameters.
--
package Wiki.Plugins.Templates is
pragma Preelaborate;
type Template_Plugin is abstract new Wiki_Plugin with null record;
-- Get the template content for the plugin evaluation.
procedure Get_Template (Plugin : in out Template_Plugin;
Params : in out Wiki.Attributes.Attribute_List;
Template : out Wiki.Strings.UString) is abstract;
-- Expand the template configured with the parameters for the document.
-- The <tt>Get_Template</tt> operation is called and the template content returned
-- by that operation is parsed in the current document. Template parameters are passed
-- in the <tt>Context</tt> instance and they can be evaluated within the template
-- while parsing the template content.
overriding
procedure Expand (Plugin : in out Template_Plugin;
Document : in out Wiki.Documents.Document;
Params : in out Wiki.Attributes.Attribute_List;
Context : in Plugin_Context);
end Wiki.Plugins.Templates;
|
Declare the Wiki.Plugins.Templates package with the Template_Plugin type
|
Declare the Wiki.Plugins.Templates package with the Template_Plugin type
|
Ada
|
apache-2.0
|
stcarrez/ada-wiki,stcarrez/ada-wiki
|
|
054fa8fddbebf3e040b7fe8d888e33e5095c2295
|
test/AdaFrontend/vce_lv.adb
|
test/AdaFrontend/vce_lv.adb
|
-- RUN: %llvmgcc -c %s -o /dev/null
procedure VCE_LV is
type P is access String ;
type T is new P (5 .. 7);
subtype U is String (5 .. 7);
X : T := new U'(others => 'A');
begin
null;
end;
|
Test that a VIEW_CONVERT_EXPR used as an lvalue has the right type.
|
Test that a VIEW_CONVERT_EXPR used as an lvalue has the right type.
git-svn-id: 0ff597fd157e6f4fc38580e8d64ab130330d2411@35387 91177308-0d34-0410-b5e6-96231b3b80d8
|
Ada
|
apache-2.0
|
apple/swift-llvm,llvm-mirror/llvm,dslab-epfl/asap,llvm-mirror/llvm,chubbymaggie/asap,chubbymaggie/asap,GPUOpen-Drivers/llvm,chubbymaggie/asap,llvm-mirror/llvm,dslab-epfl/asap,apple/swift-llvm,GPUOpen-Drivers/llvm,apple/swift-llvm,dslab-epfl/asap,llvm-mirror/llvm,llvm-mirror/llvm,dslab-epfl/asap,GPUOpen-Drivers/llvm,GPUOpen-Drivers/llvm,GPUOpen-Drivers/llvm,llvm-mirror/llvm,dslab-epfl/asap,apple/swift-llvm,dslab-epfl/asap,llvm-mirror/llvm,chubbymaggie/asap,GPUOpen-Drivers/llvm,llvm-mirror/llvm,GPUOpen-Drivers/llvm,apple/swift-llvm,apple/swift-llvm,chubbymaggie/asap,dslab-epfl/asap,apple/swift-llvm,GPUOpen-Drivers/llvm,chubbymaggie/asap,apple/swift-llvm,llvm-mirror/llvm
|
|
059d023ec56579b471707c48fb2d0f24e1ac4150
|
src/util-serialize-mappers.adb
|
src/util-serialize-mappers.adb
|
-----------------------------------------------------------------------
-- util-serialize-mappers -- Serialize objects in various formats
-- Copyright (C) 2010 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Serialize.Mappers is
-- -----------------------
-- Bind the name and the handler in the current mapper.
-- -----------------------
procedure Add_Member (Controller : in out Mapper;
Name : in String;
Handler : in Mapper_Access) is
begin
Controller.Mapping.Insert (Key => Name,
New_Item => Handler);
end Add_Member;
-- -----------------------
-- Add the member to the current mapper.
-- -----------------------
procedure Add_Member (Controller : in out Mapper;
Name : in String) is
begin
Controller.Mapping.Insert (Key => Name, New_Item => null);
end Add_Member;
-- -----------------------
-- Find the mapper associated with the given name.
-- Returns null if there is no mapper.
-- -----------------------
function Find_Mapper (Controller : in Mapper;
Name : in String) return Mapper_Access is
Pos : constant Mapper_Map.Cursor := Controller.Mapping.Find (Key => Name);
begin
if Mapper_Map.Has_Element (Pos) then
return Mapper_Map.Element (Pos);
else
return null;
end if;
end Find_Mapper;
end Util.Serialize.Mappers;
|
Add operations to specify the mapping
|
Add operations to specify the mapping
|
Ada
|
apache-2.0
|
stcarrez/ada-util,stcarrez/ada-util
|
|
35bd62d5429b5982544c8e6ec9639e6b6417e28c
|
src/util-streams-texts-wtr.ads
|
src/util-streams-texts-wtr.ads
|
-----------------------------------------------------------------------
-- util-streams-texts-tr -- Text translation utilities on streams
-- Copyright (C) 2010, 2011, 2012, 2015, 2016, 2017 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Texts.Transforms;
with Ada.Wide_Wide_Characters.Handling;
package Util.Streams.Texts.WTR is
new Util.Texts.Transforms (Stream => Print_Stream'Class,
Char => Wide_Wide_Character,
Input => Wide_Wide_String,
Put => Write_Char,
To_Upper => Ada.Wide_Wide_Characters.Handling.To_Upper,
To_Lower => Ada.Wide_Wide_Characters.Handling.To_Lower);
|
Refactor Buffered_Stream and Print_Stream - move the WTR package instantiation in a separate file
|
Refactor Buffered_Stream and Print_Stream
- move the WTR package instantiation in a separate file
|
Ada
|
apache-2.0
|
stcarrez/ada-util,stcarrez/ada-util
|
|
7b1258799f23d196dc3a13d3405d6fe825bc670f
|
src/util-serialize-tools.adb
|
src/util-serialize-tools.adb
|
-----------------------------------------------------------------------
-- util-serialize-tools -- Tools to Serialize objects in various formats
-- Copyright (C) 2012 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Containers;
with Util.Streams.Texts;
with Util.Streams.Buffered;
with Util.Serialize.IO.JSON;
with Util.Serialize.Mappers.Record_Mapper;
package body Util.Serialize.Tools is
type Object_Field is (FIELD_NAME, FIELD_VALUE);
type Object_Map_Access is access all Util.Beans.Objects.Maps.Map'Class;
type Object_Mapper_Context is record
Map : Object_Map_Access;
Name : Util.Beans.Objects.Object;
end record;
type Object_Mapper_Context_Access is access all Object_Mapper_Context;
procedure Set_Member (Into : in out Object_Mapper_Context;
Field : in Object_Field;
Value : in Util.Beans.Objects.Object) is
begin
case Field is
when FIELD_NAME =>
Into.Name := Value;
when FIELD_VALUE =>
Into.Map.Include (Util.Beans.Objects.To_String (Into.Name), Value);
Into.Name := Util.Beans.Objects.Null_Object;
end case;
end Set_Member;
package Object_Mapper is new
Util.Serialize.Mappers.Record_Mapper (Element_Type => Object_Mapper_Context,
Element_Type_Access => Object_Mapper_Context_Access,
Fields => Object_Field,
Set_Member => Set_Member);
Object_Mapping : aliased Object_Mapper.Mapper;
procedure To_JSON (Output : in out Util.Serialize.IO.JSON.Output_Stream;
Map : in Util.Beans.Objects.Maps.Map) is
use type Ada.Containers.Count_Type;
procedure Write (Name : in String;
Value : in Util.Beans.Objects.Object) is
begin
Output.Start_Entity (Name => "");
Output.Write_Attribute (Name => "name",
Value => Util.Beans.Objects.To_Object (Name));
Output.Write_Attribute (Name => "value",
Value => Value);
Output.End_Entity (Name => "");
end Write;
begin
if Map.Length > 0 then
declare
Iter : Util.Beans.Objects.Maps.Cursor := Map.First;
begin
Output.Start_Array (Name => "params",
Length => Map.Length);
while Util.Beans.Objects.Maps.Has_Element (Iter) loop
Util.Beans.Objects.Maps.Query_Element (Iter, Write'Access);
Util.Beans.Objects.Maps.Next (Iter);
end loop;
Output.End_Array;
end;
end if;
end To_JSON;
-- -----------------------
-- Serialize the objects defined in the object map <b>Map</b> into an XML stream.
-- Returns the JSON string that contains a serialization of the object maps.
-- -----------------------
function To_JSON (Map : in Util.Beans.Objects.Maps.Map) return String is
use type Ada.Containers.Count_Type;
begin
if Map.Length = 0 then
return "";
end if;
declare
Output : Util.Serialize.IO.JSON.Output_Stream;
begin
Output.Initialize (Size => 10000);
Output.Start_Document;
To_JSON (Output, Map);
Output.End_Document;
return Util.Streams.Texts.To_String (Util.Streams.Buffered.Buffered_Stream (Output));
end;
end To_JSON;
-- -----------------------
-- Deserializes the JSON content passed in <b>Content</b> and restore the object map
-- which their values.
-- Returns the object map that was restored.
-- -----------------------
function From_JSON (Content : in String) return Util.Beans.Objects.Maps.Map is
Result : aliased Util.Beans.Objects.Maps.Map;
Parser : Util.Serialize.IO.JSON.Parser;
Context : aliased Object_Mapper_Context;
begin
Context.Map := Result'Unchecked_Access;
Parser.Add_Mapping ("params", Object_Mapping'Access);
Object_Mapper.Set_Context (Parser, Context'Unchecked_Access);
Parser.Parse (Content);
return Result;
end From_JSON;
begin
Object_Mapping.Add_Mapping ("param/@name", FIELD_NAME);
Object_Mapping.Add_Mapping ("param", FIELD_VALUE);
end Util.Serialize.Tools;
|
Implement the To_JSON and From_JSON operations
|
Implement the To_JSON and From_JSON operations
|
Ada
|
apache-2.0
|
Letractively/ada-util,flottokarotto/ada-util,Letractively/ada-util,flottokarotto/ada-util
|
|
22bbe5251c1d64dc2cd6b12d698d17dbe1ab5943
|
src/asis/a4g-decl_sem.adb
|
src/asis/a4g-decl_sem.adb
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . D E C L _ S E M --
-- --
-- B o d y --
-- --
-- Copyright (C) 1995-2012, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
-- This package contains routines needed for semantic queries from
-- the Asis.Declarations package
with Asis.Declarations; use Asis.Declarations;
with Asis.Definitions; use Asis.Definitions;
with Asis.Iterator; use Asis.Iterator;
with Asis.Elements; use Asis.Elements;
with Asis.Errors; use Asis.Errors;
with Asis.Exceptions; use Asis.Exceptions;
with Asis.Extensions; use Asis.Extensions;
with Asis.Set_Get; use Asis.Set_Get;
with A4G.A_Sem; use A4G.A_Sem;
with A4G.Int_Knds; use A4G.Int_Knds;
with A4G.Vcheck; use A4G.Vcheck;
with A4G.Mapping; use A4G.Mapping;
with Atree; use Atree;
with Einfo; use Einfo;
with Namet; use Namet;
with Nlists; use Nlists;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
package body A4G.Decl_Sem is
-----------------------------
-- Corresponding_Body_Node --
-----------------------------
function Corresponding_Body_Node (Decl_Node : Node_Id) return Node_Id is
Result_Node : Node_Id;
begin
Result_Node := Corresponding_Body (Decl_Node);
if No (Result_Node) then
-- package without a body
return Result_Node;
end if;
Result_Node := Parent (Result_Node);
if Nkind (Result_Node) = N_Defining_Program_Unit_Name then
Result_Node := Parent (Result_Node);
end if;
if Nkind (Result_Node) = N_Function_Specification or else
Nkind (Result_Node) = N_Procedure_Specification
then
Result_Node := Parent (Result_Node);
end if;
if Nkind (Parent (Result_Node)) = N_Subunit then
-- we come back to the stub!
Result_Node := Corresponding_Stub (Parent (Result_Node));
end if;
if not Comes_From_Source (Result_Node)
and then
not (Is_Rewrite_Substitution (Result_Node)
-- SCz
-- and then
-- Nkind (Original_Node (Result_Node)) = N_Expression_Function)
)
then
-- implicit body created by the compiler for renaming-as-body.
-- the renaming itself is the previous list member, so
Result_Node := Get_Renaming_As_Body (Decl_Node);
end if;
return Result_Node;
end Corresponding_Body_Node;
-----------------------------
-- Corresponding_Decl_Node --
-----------------------------
function Corresponding_Decl_Node (Body_Node : Node_Id) return Node_Id is
Result_Node : Node_Id := Empty;
Protected_Def_Node : Node_Id;
Tmp_Node : Node_Id := Empty;
begin
case Nkind (Body_Node) is
when N_Body_Stub =>
Result_Node := Corr_Decl_For_Stub (Body_Node);
when N_Entry_Body =>
Protected_Def_Node := Corresponding_Spec (Parent (Body_Node));
if Ekind (Protected_Def_Node) = E_Limited_Private_Type then
Protected_Def_Node := Full_View (Protected_Def_Node);
end if;
Protected_Def_Node := Parent (Protected_Def_Node);
Protected_Def_Node := Protected_Definition (Protected_Def_Node);
Tmp_Node :=
First_Non_Pragma (Visible_Declarations (Protected_Def_Node));
while Present (Tmp_Node) loop
if Nkind (Tmp_Node) = N_Entry_Declaration and then
Parent (Corresponding_Body (Tmp_Node)) = Body_Node
then
Result_Node := Tmp_Node;
exit;
end if;
Tmp_Node := Next_Non_Pragma (Tmp_Node);
end loop;
if No (Result_Node) and then
Present (Private_Declarations (Protected_Def_Node))
then
Tmp_Node :=
First_Non_Pragma (Private_Declarations (Protected_Def_Node));
while Present (Tmp_Node) loop
if Nkind (Tmp_Node) = N_Entry_Declaration and then
Parent (Corresponding_Body (Tmp_Node)) = Body_Node
then
Result_Node := Tmp_Node;
exit;
end if;
Tmp_Node := Next_Non_Pragma (Tmp_Node);
end loop;
end if;
when others =>
Result_Node := Corresponding_Spec (Body_Node);
Result_Node := Parent (Result_Node);
if Nkind (Result_Node) = N_Defining_Program_Unit_Name then
Result_Node := Parent (Result_Node);
end if;
end case;
pragma Assert (Present (Result_Node));
-- now - from a defining entity to the declaration itself; note,
-- that here we cannot get a defining expanded name, because the
-- corresponding declaration for library units are obtained in
-- another control flow
case Nkind (Result_Node) is
when N_Function_Specification |
N_Procedure_Specification |
N_Package_Specification =>
Result_Node := Parent (Result_Node);
when N_Private_Type_Declaration =>
-- this is the case when a task type is the completion
-- of a private type
Result_Node := Full_View (Defining_Identifier (Result_Node));
Result_Node := Parent (Result_Node);
when others =>
null;
end case;
return Result_Node;
end Corresponding_Decl_Node;
---------------------------------------
-- Get_Corresponding_Generic_Element --
---------------------------------------
function Get_Corresponding_Generic_Element
(Gen_Unit : Asis.Declaration;
Def_Name : Asis.Element)
return Asis.Element
is
Kind_To_Check : constant Internal_Element_Kinds := Int_Kind (Def_Name);
Sloc_To_Check : constant Source_Ptr := Sloc (Node (Def_Name));
Line_To_Check : constant Physical_Line_Number :=
Get_Physical_Line_Number (Sloc_To_Check);
Column_To_Check : constant Column_Number :=
Get_Column_Number (Sloc_To_Check);
Result_Element : Asis.Element := Nil_Element;
Tmp_El : Asis.Element;
Check_Inherited_Element : constant Boolean :=
Is_Part_Of_Inherited (Def_Name);
Sloc_To_Check_1 : constant Source_Ptr := Sloc (Node_Field_1 (Def_Name));
Line_To_Check_1 : constant Physical_Line_Number :=
Get_Physical_Line_Number (Sloc_To_Check_1);
Column_To_Check_1 : constant Column_Number :=
Get_Column_Number (Sloc_To_Check_1);
-- Used in case if we are looking for an implicit Element
function Is_Found (E : Asis.Element) return Boolean;
-- Checks if the Element being traversed is a corresponding generic
-- element for Def_Name
function Is_Found (E : Asis.Element) return Boolean is
Elem_Sloc : constant Source_Ptr := Sloc (Node (E));
Elem_Sloc_1 : Source_Ptr;
Result : Boolean := False;
begin
if not (Check_Inherited_Element xor Is_Part_Of_Inherited (E)) then
Result :=
Line_To_Check = Get_Physical_Line_Number (Elem_Sloc)
and then
Column_To_Check = Get_Column_Number (Elem_Sloc);
if Result
and then
Check_Inherited_Element
then
Elem_Sloc_1 := Sloc (Node_Field_1 (E));
Result :=
Line_To_Check_1 = Get_Physical_Line_Number (Elem_Sloc_1)
and then
Column_To_Check_1 = Get_Column_Number (Elem_Sloc_1);
end if;
end if;
return Result;
end Is_Found;
-- and now, variables and actuals for Traverse_Element
My_Control : Traverse_Control := Continue;
My_State : No_State := Not_Used;
procedure Pre_Op
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out No_State);
procedure Look_For_Corr_Gen_El is new Traverse_Element
(State_Information => No_State,
Pre_Operation => Pre_Op,
Post_Operation => No_Op);
procedure Pre_Op
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out No_State)
is
pragma Unreferenced (State);
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Element);
begin
case Arg_Kind is
when An_Internal_Body_Stub =>
if Kind_To_Check = A_Defining_Identifier or else
Kind_To_Check in Internal_Defining_Operator_Kinds
then
-- We have to traverse the code of the subunit -
-- see 9217-015. But before doing this, let's check the
-- name of the subunit:
Tmp_El := Asis.Declarations.Names (Element) (1);
if Int_Kind (Tmp_El) = Kind_To_Check and then
Is_Found (Tmp_El)
then
Result_Element := Tmp_El;
Control := Terminate_Immediately;
return;
end if;
end if;
-- If we are here, we have to traverse the proper body:
Tmp_El := Corresponding_Subunit (Element);
if not Is_Nil (Tmp_El) then
Look_For_Corr_Gen_El (Element => Tmp_El,
Control => My_Control,
State => My_State);
end if;
when Internal_Defining_Name_Kinds =>
if Int_Kind (Element) = Kind_To_Check and then
Is_Found (Element)
then
Result_Element := Element;
Control := Terminate_Immediately;
end if;
when A_Derived_Type_Definition |
A_Derived_Record_Extension_Definition |
A_Formal_Derived_Type_Definition =>
if Check_Inherited_Element then
declare
Inherited_Decls : constant Asis.Element_List :=
Implicit_Inherited_Declarations (Element);
Inherited_Subprgs : constant Asis.Element_List :=
Implicit_Inherited_Subprograms (Element);
begin
for J in Inherited_Decls'Range loop
exit when My_Control = Terminate_Immediately;
Look_For_Corr_Gen_El
(Element => Inherited_Decls (J),
Control => My_Control,
State => My_State);
end loop;
for J in Inherited_Subprgs'Range loop
exit when My_Control = Terminate_Immediately;
Look_For_Corr_Gen_El
(Element => Inherited_Subprgs (J),
Control => My_Control,
State => My_State);
end loop;
end;
end if;
when others =>
null;
end case;
end Pre_Op;
begin -- Get_Corresponding_Generic_Element
Look_For_Corr_Gen_El (Element => Gen_Unit,
Control => My_Control,
State => My_State);
return Result_Element;
exception
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Nil_Element,
Outer_Call => "A4G.Decl_Sem.Get_Corresponding_Generic_Element");
end if;
raise;
end Get_Corresponding_Generic_Element;
-----------------------
-- Get_Expanded_Spec --
-----------------------
function Get_Expanded_Spec (Instance_Node : Node_Id) return Node_Id is
Result_Node : Node_Id;
begin
-- GNAT constructs the structure corresponding to an expanded generic
-- specification just before the instantiation itself, except the case
-- of the formal package with box:
if Nkind (Instance_Node) = N_Package_Declaration and then
Nkind (Original_Node (Instance_Node)) = N_Formal_Package_Declaration
then
Result_Node := Instance_Node;
else
Result_Node := Prev_Non_Pragma (Instance_Node);
end if;
if Nkind (Result_Node) = N_Package_Body then
-- Here we have the expanded generic body, therefore - one
-- more step up the list
Result_Node := Prev_Non_Pragma (Result_Node);
end if;
-- in case of a package instantiation, we have to take the whole
-- expanded package, but in case of a subprogram instantiation we
-- need only the subprogram declaration, which is the last element
-- of the visible declarations list of the "artificial" package
-- spec created by the compiler
if not (Nkind (Instance_Node) = N_Package_Instantiation or else
Nkind (Original_Node (Instance_Node)) =
N_Formal_Package_Declaration)
then
Result_Node := Last_Non_Pragma (Visible_Declarations
(Specification (Result_Node)));
if Nkind (Result_Node) = N_Subprogram_Body then
Result_Node := Parent (Parent (Corresponding_Spec (Result_Node)));
end if;
pragma Assert (Nkind (Result_Node) = N_Subprogram_Declaration);
end if;
return Result_Node;
end Get_Expanded_Spec;
--------------------------
-- Get_Renaming_As_Body --
--------------------------
function Get_Renaming_As_Body
(Node : Node_Id;
Spec_Only : Boolean := False)
return Node_Id
is
Entity_Node : Node_Id;
Scope_Node : Node_Id;
Result_Node : Node_Id := Empty;
List_To_Search : List_Id;
Search_Node : Node_Id := Node;
-- in the first List_To_Search we start not from the very beginning;
-- but from the node representing the argument subprogram declaration
Completion_Found : Boolean := False;
procedure Search_In_List;
-- looks for a possible renaming-as-bode node being a completion for
-- Node, using global settings for List_To_Search and Search_Node
procedure Search_In_List is
begin
while Present (Search_Node) loop
if Nkind (Search_Node) = N_Subprogram_Renaming_Declaration and then
Corresponding_Spec (Search_Node) = Entity_Node
then
Result_Node := Search_Node;
Completion_Found := True;
return;
end if;
Search_Node := Next_Non_Pragma (Search_Node);
end loop;
end Search_In_List;
begin -- Get_Renaming_As_Body
Entity_Node := Defining_Unit_Name (Specification (Node));
List_To_Search := List_Containing (Node);
Search_In_List;
if Completion_Found then
goto end_of_search;
end if;
-- here we have to see, where we are. If we are not in a package,
-- we have nothing to do, but if we are in the package, we may
-- have to search again in another lists (the private part and
-- the body)
Scope_Node := Scope (Entity_Node);
-- Node here can be of N_Subprogram_Declaration only!
if Nkind (Parent (Scope_Node)) = N_Implicit_Label_Declaration then
-- this is the implicit name created for a block statement,
-- so we do not have any other list to search in
goto end_of_search;
else
Scope_Node := Parent (Scope_Node);
end if;
if Nkind (Scope_Node) = N_Defining_Program_Unit_Name then
Scope_Node := Parent (Scope_Node);
end if;
-- now if we are not in N_Package_Specification, we have no
-- other list to search in
if Nkind (Scope_Node) /= N_Package_Specification then
goto end_of_search;
end if;
-- and here we are in N_Package_Specification
if List_To_Search = Visible_Declarations (Scope_Node) then
-- continuing in the private part:
List_To_Search := Private_Declarations (Scope_Node);
if not (No (List_To_Search)
or else Is_Empty_List (List_To_Search))
then
Search_Node := First_Non_Pragma (List_To_Search);
Search_In_List;
end if;
if Completion_Found or else Spec_Only then
goto end_of_search;
end if;
end if;
-- and here we have to go into the package body, if any:
Scope_Node := Corresponding_Body (Parent (Scope_Node));
if Present (Scope_Node) then
while Nkind (Scope_Node) /= N_Package_Body loop
Scope_Node := Parent (Scope_Node);
end loop;
-- and to continue to search in the package body:
List_To_Search := Sinfo.Declarations (Scope_Node);
if not (No (List_To_Search)
or else Is_Empty_List (List_To_Search))
then
Search_Node := First_Non_Pragma (List_To_Search);
Search_In_List;
end if;
end if;
<< end_of_search >>
return Result_Node;
end Get_Renaming_As_Body;
-----------------------
-- Serach_First_View --
-----------------------
function Serach_First_View (Type_Entity : Entity_Id) return Entity_Id is
Type_Chars : constant Name_Id := Chars (Type_Entity);
Type_Decl : constant Node_Id := Parent (Type_Entity);
Result_Node : Node_Id := Empty;
Scope_Node : Node_Id;
Scope_Kind : Node_Kind;
Search_List : List_Id;
Private_Decls_Passed : Boolean := False;
procedure Sesrch_In_List (L : List_Id);
-- we have a separate procedure for searching in a list of
-- declarations, because we have to do this search from one to
-- three times in case of a package. This procedure uses Type_Chars,
-- Type_Decl and Result_Node as global values, and it sets
-- Result_Node equal to the node defining the type with the same name
-- as the name of the type represented by Type_Entity, if the
-- search is successful, otherwise it remains is equal to Empty.
-- this procedure supposes, that L is not No_List
procedure Sesrch_In_List (L : List_Id) is
Next_Decl : Node_Id;
Next_Decl_Original : Node_Id;
Next_Kind : Node_Kind;
begin
Next_Decl := First_Non_Pragma (L);
Next_Decl_Original := Original_Node (Next_Decl);
Next_Kind := Nkind (Next_Decl_Original);
while Present (Next_Decl) loop
if (Comes_From_Source (Next_Decl_Original)
and then
(Next_Kind = N_Full_Type_Declaration or else
Next_Kind = N_Task_Type_Declaration or else
Next_Kind = N_Protected_Type_Declaration or else
Next_Kind = N_Private_Type_Declaration or else
Next_Kind = N_Private_Extension_Declaration or else
Next_Kind = N_Formal_Type_Declaration or else
-- impossible in ASIS, but possible in the tree
-- because of the tree rewritings
Next_Kind = N_Incomplete_Type_Declaration))
-- these cases correspond to non-rewritten type
-- declarations
or else
(not (Comes_From_Source (Next_Decl_Original))
and then
Next_Kind = N_Subtype_Declaration)
-- the declaration of a derived type rewritten into a
-- subtype declaration
then
if Is_Not_Duplicated_Decl (Next_Decl) then
-- ??? <tree problem 2> - we need this "if" only because of this problem
if Next_Decl_Original = Type_Decl then
-- no private or incomplete view
Result_Node := Type_Entity;
return;
end if;
if Type_Chars = Chars (Defining_Identifier (Next_Decl)) then
-- we've found something...
Result_Node := Defining_Identifier (Next_Decl);
return;
end if;
end if;
end if;
Next_Decl := Next_Non_Pragma (Next_Decl);
Next_Decl_Original := Original_Node (Next_Decl);
Next_Kind := Nkind (Next_Decl_Original);
end loop;
end Sesrch_In_List;
begin -- Serach_First_View
-- first, defining the scope of the Type_Entity. In case of a package
-- body it will be a package spec anyway.
Scope_Node := Scope (Type_Entity);
if Nkind (Parent (Scope_Node)) = N_Implicit_Label_Declaration then
-- this is the implicit name created for a block statement
Scope_Node := Parent (Block_Node (Scope_Node));
else
Scope_Node := Parent (Scope_Node);
end if;
if Nkind (Scope_Node) = N_Defining_Program_Unit_Name then
Scope_Node := Parent (Scope_Node);
end if;
-- now we are in N_Function_Specification, N_Procedure_Specification
-- or in N_Package_Specification
Scope_Kind := Nkind (Scope_Node);
if Scope_Kind = N_Function_Specification or else
Scope_Kind = N_Procedure_Specification
then
-- we do not do this additional step for packages, because
-- N_Package_Specification_Node already contains references to
-- declaration lists, and for a package we gave to start from the
-- declarations in the package spec, but for a subprogram
-- we have to go to a subprogram body, because nothing interesting
-- for this function can be declared in a separate subprogram
-- specification (if any) or in a generic formal part (if any)
Scope_Node := Parent (Scope_Node);
Scope_Kind := Nkind (Scope_Node);
end if;
if Scope_Kind = N_Subprogram_Declaration
or else
Scope_Kind = N_Generic_Subprogram_Declaration
or else
Scope_Kind = N_Task_Type_Declaration
or else
Scope_Kind = N_Entry_Declaration
or else
Scope_Kind = N_Subprogram_Body_Stub
then
Scope_Node := Corresponding_Body (Scope_Node);
Scope_Node := Parent (Scope_Node);
if Nkind (Scope_Node) = N_Defining_Program_Unit_Name then
Scope_Node := Parent (Scope_Node);
end if;
if Nkind (Scope_Node) = N_Function_Specification or else
Nkind (Scope_Node) = N_Procedure_Specification
then
Scope_Node := Parent (Scope_Node);
end if;
Scope_Kind := Nkind (Scope_Node);
end if;
-- now, defining the list to search. In case of generics, we do not
-- have to start from parsing the list of generic parameters, because
-- a generic formal type cannot have a completion as its full view,
-- and it cannot be a completion of some other type.
if Scope_Kind = N_Subprogram_Body or else
Scope_Kind = N_Task_Body or else
Scope_Kind = N_Block_Statement or else
Scope_Kind = N_Entry_Body
then
Search_List := Sinfo.Declarations (Scope_Node);
elsif Scope_Kind = N_Package_Specification then
Search_List := Visible_Declarations (Scope_Node);
if Is_Empty_List (Search_List) then
-- note, that Visible_Declarations cannot be No_List
Private_Decls_Passed := True;
Search_List := Private_Declarations (Scope_Node);
if No (Search_List) or else Is_Empty_List (Search_List) then
-- here we should go to the declarative part of the package
-- body. Note, that if we are in a legal ada program, and if
-- we start from a type declaration, Search_List cannot
-- be No_List or an empty list
Scope_Node := Parent (Corresponding_Body (Parent (Scope_Node)));
-- note, that Search_Kind is unchanged here
Search_List := Sinfo.Declarations (Scope_Node);
end if;
end if;
end if;
Sesrch_In_List (Search_List);
if Result_Node /= Empty then
if Result_Node /= Type_Entity and then
Full_View (Result_Node) /= Type_Entity
then
-- The case when Type_Entity is a full type declaration that
-- completes a private type/extension declaration that in turn
-- completes an incomplete type.
Result_Node := Full_View (Result_Node);
end if;
return Result_Node;
end if;
-- it is possible only for a package - we have to continue in the
-- private part or/and in the body
pragma Assert (Scope_Kind = N_Package_Specification);
-- first, try a private part, if needed and if any
if not Private_Decls_Passed then
-- Scope_Node is still of N_Package_Specification kind here!
Private_Decls_Passed := True;
Search_List := Private_Declarations (Scope_Node);
if Present (Search_List) and then Is_Non_Empty_List (Search_List) then
Sesrch_In_List (Search_List);
if Result_Node /= Empty then
return Result_Node;
end if;
end if;
end if;
-- if we are here, Scope_Node is still of N_Package_Specification,
-- and the only thing we have to do now is to check the package
-- body
-- There is some redundancy in the code - in fact, we need only
-- one boolean flag (Private_Decls_Passed) to control the search in
-- case of a package
Scope_Node := Parent (Corresponding_Body (Parent (Scope_Node)));
if Nkind (Scope_Node) = N_Defining_Program_Unit_Name then
Scope_Node := Parent (Scope_Node);
end if;
Search_List := Sinfo.Declarations (Scope_Node);
Sesrch_In_List (Search_List);
if Result_Node /= Empty then
return Result_Node;
else
pragma Assert (False);
return Empty;
end if;
end Serach_First_View;
end A4G.Decl_Sem;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen
|
|
fda432c473ce0510a9b3d1c3b3515ffd2bb94967
|
src/asis/a4g-defaults.adb
|
src/asis/a4g-defaults.adb
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . D E F A U L T S --
-- --
-- Copyright (C) 1995-2010, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
with Unchecked_Deallocation;
with A4G.A_Osint; use A4G.A_Osint;
with A4G.U_Conv; use A4G.U_Conv;
with Output; use Output;
package body A4G.Defaults is
procedure Free_String is new Unchecked_Deallocation
(String, String_Access);
procedure Add_Src_Search_Dir (Dir : String);
-- Add Dir at the end of the default source file search path.
procedure Add_Lib_Search_Dir (Dir : String);
-- Add Dir at the end of the default library (=object+ALI) file search
-- path.
------------------------
-- Add_Lib_Search_Dir --
------------------------
procedure Add_Lib_Search_Dir (Dir : String) is
begin
ASIS_Lib_Search_Directories.Increment_Last;
ASIS_Lib_Search_Directories.Table (ASIS_Lib_Search_Directories.Last) :=
new String'(Normalize_Directory_Name (Dir));
end Add_Lib_Search_Dir;
------------------------
-- Add_Src_Search_Dir --
------------------------
procedure Add_Src_Search_Dir (Dir : String) is
begin
ASIS_Src_Search_Directories.Increment_Last;
ASIS_Src_Search_Directories.Table (ASIS_Src_Search_Directories.Last) :=
new String'(Normalize_Directory_Name (Dir));
end Add_Src_Search_Dir;
--------------
-- Finalize --
--------------
procedure Finalize is
begin
-- finalise ASIS_Src_Search_Directories:
for I in First_Dir_Id .. ASIS_Src_Search_Directories.Last loop
Free_String (ASIS_Src_Search_Directories.Table (I));
end loop;
-- finalize ASIS_Lib_Search_Directories:
for I in First_Dir_Id .. ASIS_Lib_Search_Directories.Last loop
Free_String (ASIS_Lib_Search_Directories.Table (I));
end loop;
-- finalize ASIS_Tree_Search_Directories
for I in First_Dir_Id .. ASIS_Tree_Search_Directories.Last loop
Free_String (ASIS_Tree_Search_Directories.Table (I));
end loop;
end Finalize;
----------------
-- Initialize --
----------------
procedure Initialize is
Search_Path : String_Access;
begin
-- just in case:
Finalize;
ASIS_Src_Search_Directories.Init;
ASIS_Lib_Search_Directories.Init;
ASIS_Tree_Search_Directories.Init;
-- stroring the defaults for: the code is stolen from Osint
-- (body, rev. 1.147) and then adjusted
for Dir_kind in Search_Dir_Kinds loop
case Dir_kind is
when Source =>
Search_Path := Getenv ("ADA_INCLUDE_PATH");
when Object =>
Search_Path := Getenv ("ADA_OBJECTS_PATH");
when Tree =>
-- There is no environment variable for separate
-- tree path at the moment;
exit;
end case;
if Search_Path'Length > 0 then
declare
Lower_Bound : Positive := 1;
Upper_Bound : Positive;
begin
loop
while Lower_Bound <= Search_Path'Last
and then Search_Path.all (Lower_Bound) =
ASIS_Path_Separator
loop
Lower_Bound := Lower_Bound + 1;
end loop;
exit when Lower_Bound > Search_Path'Last;
Upper_Bound := Lower_Bound;
while Upper_Bound <= Search_Path'Last
and then Search_Path.all (Upper_Bound) /=
ASIS_Path_Separator
loop
Upper_Bound := Upper_Bound + 1;
end loop;
case Dir_kind is
when Source =>
Add_Src_Search_Dir
(Search_Path.all (Lower_Bound .. Upper_Bound - 1));
when Object =>
Add_Lib_Search_Dir
(Search_Path.all (Lower_Bound .. Upper_Bound - 1));
when Tree =>
exit; -- non implemented yet;
end case;
Lower_Bound := Upper_Bound + 1;
end loop;
end;
end if;
end loop;
-- ??? TEMPORARY SOLUTION: the default objects search path
-- is also used as the default tree path
for J in First_Dir_Id .. ASIS_Lib_Search_Directories.Last loop
ASIS_Tree_Search_Directories.Increment_Last;
ASIS_Tree_Search_Directories.Table
(ASIS_Tree_Search_Directories.Last) :=
new String'(ASIS_Lib_Search_Directories.Table (J).all);
end loop;
Free (Search_Path);
end Initialize;
-------------------------
-- Locate_Default_File --
-------------------------
function Locate_Default_File
(File_Name : String_Access;
Dir_Kind : Search_Dir_Kinds)
return String_Access
is
function Is_Here_In_Src (File_Name : String_Access; Dir : Dir_Id)
return Boolean;
function Is_Here_In_Lib (File_Name : String_Access; Dir : Dir_Id)
return Boolean;
-- funtion Is_Here_In_Tree (File_Name : String_Access; Dir : Dir_Id)
-- return Boolean;
function Is_Here_In_Src (File_Name : String_Access; Dir : Dir_Id)
return Boolean
is
begin
return Is_Regular_File (ASIS_Src_Search_Directories.Table (Dir).all
& To_String (File_Name));
end Is_Here_In_Src;
function Is_Here_In_Lib (File_Name : String_Access; Dir : Dir_Id)
return Boolean
is
begin
return Is_Regular_File (ASIS_Lib_Search_Directories.Table (Dir).all
& To_String (File_Name));
end Is_Here_In_Lib;
begin
case Dir_Kind is
when Source =>
for Dir in First_Dir_Id .. ASIS_Src_Search_Directories.Last loop
if Is_Here_In_Src (File_Name, Dir) then
return new String'
(ASIS_Src_Search_Directories.Table (Dir).all
& File_Name.all);
end if;
end loop;
when Object =>
for Dir in First_Dir_Id .. ASIS_Lib_Search_Directories.Last loop
if Is_Here_In_Lib (File_Name, Dir) then
return new String'
(ASIS_Lib_Search_Directories.Table (Dir).all
& File_Name.all);
end if;
end loop;
when Tree =>
null; -- non implemented yet;
end case;
return null;
end Locate_Default_File;
------------------------
-- Print_Lib_Defaults --
------------------------
procedure Print_Lib_Defaults is
begin
if ASIS_Lib_Search_Directories.Last < First_Dir_Id then
Write_Str (" No default library files search path");
Write_Eol;
else
for Dir in First_Dir_Id .. ASIS_Lib_Search_Directories.Last loop
Write_Str (" " & ASIS_Lib_Search_Directories.Table (Dir).all);
Write_Eol;
end loop;
end if;
end Print_Lib_Defaults;
---------------------------
-- Print_Source_Defaults --
---------------------------
procedure Print_Source_Defaults is
begin
if ASIS_Src_Search_Directories.Last < First_Dir_Id then
Write_Str (" No default source search path");
Write_Eol;
else
for Dir in First_Dir_Id .. ASIS_Src_Search_Directories.Last loop
Write_Str (" " & ASIS_Src_Search_Directories.Table (Dir).all);
Write_Eol;
end loop;
end if;
end Print_Source_Defaults;
-------------------------
-- Print_Tree_Defaults --
-------------------------
procedure Print_Tree_Defaults is
begin
if ASIS_Tree_Search_Directories.Last < First_Dir_Id then
Write_Str (" No default tree files search path");
Write_Eol;
else
for Dir in First_Dir_Id .. ASIS_Tree_Search_Directories.Last loop
Write_Str (" " & ASIS_Tree_Search_Directories.Table (Dir).all);
Write_Eol;
end loop;
end if;
end Print_Tree_Defaults;
end A4G.Defaults;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen
|
|
5e76a30e7598b95ca3126c7fb39daca5a968864c
|
src/asf-components-widgets-tabs.adb
|
src/asf-components-widgets-tabs.adb
|
-----------------------------------------------------------------------
-- components-widgets-tabs -- Tab views and tabs
-- Copyright (C) 2013 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Contexts.Writer;
package body ASF.Components.Widgets.Tabs is
-- ------------------------------
-- Render the tab start.
-- ------------------------------
overriding
procedure Encode_Begin (UI : in UITab;
Context : in out ASF.Contexts.Faces.Faces_Context'Class) is
Writer : constant Contexts.Writer.Response_Writer_Access := Context.Get_Response_Writer;
begin
if UI.Is_Rendered (Context) then
Writer.Start_Element ("div");
Writer.Write_Attribute ("id", UI.Get_Client_Id);
end if;
end Encode_Begin;
-- ------------------------------
-- Render the tab close.
-- ------------------------------
overriding
procedure Encode_End (UI : in UITab;
Context : in out ASF.Contexts.Faces.Faces_Context'Class) is
Writer : constant Contexts.Writer.Response_Writer_Access := Context.Get_Response_Writer;
begin
if UI.Is_Rendered (Context) then
Writer.End_Element ("div");
end if;
end Encode_End;
-- ------------------------------
-- Render the tab list and prepare to render the tab contents.
-- ------------------------------
overriding
procedure Encode_Begin (UI : in UITabView;
Context : in out ASF.Contexts.Faces.Faces_Context'Class) is
procedure Render_Tab (T : in Components.Base.UIComponent_Access);
Writer : constant Contexts.Writer.Response_Writer_Access := Context.Get_Response_Writer;
procedure Render_Tab (T : in Components.Base.UIComponent_Access) is
Id : constant Unbounded_String := T.Get_Client_Id;
begin
if T.all in UITab'Class then
Writer.Start_Element ("li");
Writer.Start_Element ("a");
Writer.Write_Attribute ("href", "#" & To_String (Id));
Writer.Write_Text (T.Get_Attribute ("title", Context));
Writer.End_Element ("a");
Writer.End_Element ("li");
end if;
end Render_Tab;
procedure Render_Tabs is
new ASF.Components.Base.Iterate (Process => Render_Tab);
begin
if UI.Is_Rendered (Context) then
declare
Id : constant Unbounded_String := UI.Get_Client_Id;
begin
Writer.Start_Element ("div");
Writer.Write_Attribute ("id", Id);
Writer.Start_Element ("ul");
Render_Tabs (UI);
Writer.End_Element ("ul");
Writer.Queue_Script ("$(""#");
Writer.Queue_Script (Id);
Writer.Queue_Script (""").tabs({");
Writer.Queue_Script ("});");
end;
end if;
end Encode_Begin;
-- ------------------------------
-- Render the tab view close.
-- ------------------------------
overriding
procedure Encode_End (UI : in UITabView;
Context : in out ASF.Contexts.Faces.Faces_Context'Class) is
Writer : constant Contexts.Writer.Response_Writer_Access := Context.Get_Response_Writer;
begin
if UI.Is_Rendered (Context) then
Writer.End_Element ("div");
end if;
end Encode_End;
end ASF.Components.Widgets.Tabs;
|
Implement the new <w:tab> and <w:tabView> components
|
Implement the new <w:tab> and <w:tabView> components
|
Ada
|
apache-2.0
|
Letractively/ada-asf,Letractively/ada-asf,Letractively/ada-asf
|
|
ddb523ee224a35693999a32c5d7d76d0de30a0d4
|
src/asis/asis-data_decomposition-debug.ads
|
src/asis/asis-data_decomposition-debug.ads
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A S I S . D A T A _ D E C O M P O S I T I O N . D E B U G --
-- --
-- S p e c --
-- --
-- Copyright (c) 1995-2006, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
-- This package contains routines forming debug images for bstractions
-- declared in Asis.Data_Decomposition.
package Asis.Data_Decomposition.Debug is
function Debug_Image (RC : Record_Component) return Wide_String;
function Debug_Image (AC : Array_Component) return Wide_String;
-- Returns a string value containing implementation-defined debug
-- information associated with the element.
--
-- The return value uses Asis.Text.Delimiter_Image to separate the lines
-- of multi-line results. The return value does not end with
-- Asis.Text.Delimiter_Image.
function Is_Derived_From_Record (TD : Element) return Boolean;
function Is_Derived_From_Array (TD : Element) return Boolean;
-- The public renaming of
-- Asis.Data_Decomposition.Aux.Is_Derived_From_Record/
-- Asis.Data_Decomposition.Aux.Is_Derived_From_Array
-- May be, we should have it in Asis.Extensions
function Dimension (Comp : Array_Component) return ASIS_Natural;
-- The public renaming of
-- Asis.Data_Decomposition.Set_Get.Dimension
-- May be, we should have it in Asis.Extensions
-- function Linear_Index
-- (Inds : Dimension_Indexes;
-- D : ASIS_Natural;
-- Ind_Lengths : Dimention_Length;
-- Conv : Convention_Id := Convention_Ada)
-- return Asis.ASIS_Natural;
-- function De_Linear_Index
-- (Index : Asis.ASIS_Natural;
-- D : ASIS_Natural;
-- Ind_Lengths : Dimention_Length;
-- Conv : Convention_Id := Convention_Ada)
-- return Dimension_Indexes;
-- The public renaming of
-- Asis.Data_Decomposition.Aux.Linear_Index and
-- Asis.Data_Decomposition.Aux.De_Linear_Index
end Asis.Data_Decomposition.Debug;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen
|
|
b7f3273a231c30ca9f9b0f6dba6e92820ff90540
|
src/wiki-parsers-html.ads
|
src/wiki-parsers-html.ads
|
-----------------------------------------------------------------------
-- wiki-parsers-html -- Wiki HTML parser
-- Copyright (C) 2015 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.
-----------------------------------------------------------------------
-- This is a small HTML parser that is called to deal with embedded HTML in wiki text.
-- The parser is intended to handle incorrect HTML and clean the result as much as possible.
-- We cannot use a real XML/Sax parser (such as XML/Ada) because we must handle errors and
-- backtrack from HTML parsing to wiki or raw text parsing.
--
-- When parsing HTML content, we call the <tt>Start_Element</tt> or <tt>End_Element</tt>
-- operations. The renderer is then able to handle the HTML tag according to its needs.
private package Wiki.Parsers.Html is
pragma Preelaborate;
-- Parse a HTML element <XXX attributes>
-- or parse an end of HTML element </XXX>
procedure Parse_Element (P : in out Parser);
end Wiki.Parsers.Html;
|
Define a simple HTML parser that can be used to parse HTML text embedded in wiki text
|
Define a simple HTML parser that can be used to parse HTML text embedded in wiki text
|
Ada
|
apache-2.0
|
stcarrez/ada-wiki,stcarrez/ada-wiki
|
|
9f9ab71f4c6521f1d5be2c75186d681702e450a3
|
awa/src/awa-helpers.adb
|
awa/src/awa-helpers.adb
|
-----------------------------------------------------------------------
-- awa-helpers -- Helpers for AWA applications
-- Copyright (C) 2011, 2013 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 AWA.Helpers is
-- ------------------------------
-- Get the value as an identifier.
-- Returns NO_IDENTIFIER if the value is invalid.
-- ------------------------------
function To_Identifier (Value : in Util.Beans.Objects.Object) return ADO.Identifier is
begin
return ADO.Identifier (Util.Beans.Objects.To_Long_Long_Integer (Value));
exception
when Constraint_Error =>
return ADO.NO_IDENTIFIER;
end To_Identifier;
end AWA.Helpers;
|
Implement new operation To_Identifier
|
Implement new operation To_Identifier
|
Ada
|
apache-2.0
|
stcarrez/ada-awa,stcarrez/ada-awa,stcarrez/ada-awa,stcarrez/ada-awa
|
|
1d4d948d333104e0423ebed08bdd7a276abc75a2
|
awa/src/awa-oauth-filters.ads
|
awa/src/awa-oauth-filters.ads
|
-----------------------------------------------------------------------
-- awa-oauth-filters -- OAuth filter
-- Copyright (C) 2017 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 ASF.Requests;
with ASF.Responses;
with ASF.Sessions;
with ASF.Principals;
with ASF.Filters;
with ASF.Servlets;
with ASF.Security.Filters;
with AWA.Users.Principals;
with AWA.OAuth.Services;
package AWA.OAuth.Filters is
-- ------------------------------
-- OAuth Authentication filter
-- ------------------------------
-- The <b>Auth_Filter</b> verifies that the access token passed for the OAuth
-- operation is valid and it extracts the user to configure the request principal.
type Auth_Filter is new ASF.Filters.Filter with private;
-- Initialize the filter.
overriding
procedure Initialize (Filter : in out Auth_Filter;
Config : in ASF.Servlets.Filter_Config);
-- The Do_Filter method of the Filter is called by the container each time
-- a request/response pair is passed through the chain due to a client request
-- for a resource at the end of the chain. The Filter_Chain passed in to this
-- method allows the Filter to pass on the request and response to the next
-- entity in the chain.
--
-- Before passing the control to the next filter, initialize the service
-- context to give access to the current application, current user and
-- manage possible transaction rollbacks.
overriding
procedure Do_Filter (F : in Auth_Filter;
Request : in out ASF.Requests.Request'Class;
Response : in out ASF.Responses.Response'Class;
Chain : in out ASF.Servlets.Filter_Chain);
private
use Ada.Strings.Unbounded;
type Auth_Filter is new ASF.Filters.Filter with record
Realm : AWA.OAuth.Services.Auth_Manager_Access;
end record;
end AWA.OAuth.Filters;
|
Define the OAuth security filter for AWA applications
|
Define the OAuth security filter for AWA applications
|
Ada
|
apache-2.0
|
stcarrez/ada-awa,stcarrez/ada-awa,stcarrez/ada-awa,stcarrez/ada-awa
|
|
bc4445378b6f457993c62077a3dfe45f8e8c36d3
|
regtests/util-commands-tests.ads
|
regtests/util-commands-tests.ads
|
-----------------------------------------------------------------------
-- util-commands-tests - Test for commands
-- Copyright (C) 2018 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Tests;
package Util.Commands.Tests is
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite);
type Test is new Util.Tests.Test with null record;
-- Tests when the execution of commands.
procedure Test_Execute (T : in out Test);
-- Test execution of help.
procedure Test_Help (T : in out Test);
-- Test usage operation.
procedure Test_Usage (T : in out Test);
end Util.Commands.Tests;
|
Add tests for the Util.Commands.Drivers package
|
Add tests for the Util.Commands.Drivers package
|
Ada
|
apache-2.0
|
stcarrez/ada-util,stcarrez/ada-util
|
|
5588b3d7802ee994a6b5cfe243fdb4cb5f0972eb
|
src/wiki-nodes.adb
|
src/wiki-nodes.adb
|
-----------------------------------------------------------------------
-- wiki-nodes -- Wiki Document Internal representation
-- Copyright (C) 2016 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 Wiki.Nodes is
-- ------------------------------
-- Create a text node.
-- ------------------------------
function Create_Text (Text : in WString) return Node_Type_Access is
begin
return new Node_Type '(Kind => N_TEXT,
Len => Text'Length,
Text => Text,
others => <>);
end Create_Text;
end Wiki.Nodes;
|
Implement the Create_Text function
|
Implement the Create_Text function
|
Ada
|
apache-2.0
|
stcarrez/ada-wiki,stcarrez/ada-wiki
|
|
77119f2b27d96aa3979a4f4dadf9e6ff1b39329b
|
tools/druss-commands-ping.ads
|
tools/druss-commands-ping.ads
|
-----------------------------------------------------------------------
-- druss-commands-ping -- Ping devices from the gateway
-- Copyright (C) 2017 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 Druss.Commands.Ping is
type Command_Type is new Druss.Commands.Drivers.Command_Type with null record;
procedure Do_Ping (Command : in Command_Type;
Args : in Argument_List'Class;
Context : in out Context_Type);
-- Execute a ping from the gateway to each device.
overriding
procedure Execute (Command : in Command_Type;
Name : in String;
Args : in Argument_List'Class;
Context : in out Context_Type);
-- Write the help associated with the command.
overriding
procedure Help (Command : in Command_Type;
Context : in out Context_Type);
end Druss.Commands.Ping;
|
Define the ping command to ask the Bbox to ping the known devices
|
Define the ping command to ask the Bbox to ping the known devices
|
Ada
|
apache-2.0
|
stcarrez/bbox-ada-api
|
|
725753adcc28d0b9a854d134dddcfe320e1b06f9
|
src/util-commands.adb
|
src/util-commands.adb
|
-----------------------------------------------------------------------
-- util-commands -- Support to make command line tools
-- Copyright (C) 2017 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Command_Line;
package body Util.Commands is
-- ------------------------------
-- Get the number of arguments available.
-- ------------------------------
overriding
function Get_Count (List : in Default_Argument_List) return Natural is
begin
return Ada.Command_Line.Argument_Count - List.Offset;
end Get_Count;
-- ------------------------------
-- Get the argument at the given position.
-- ------------------------------
overriding
function Get_Argument (List : in Default_Argument_List;
Pos : in Positive) return String is
begin
return Ada.Command_Line.Argument (Pos - List.Offset);
end Get_Argument;
end Util.Commands;
|
Implement the Get_Count and Get_Argument operations
|
Implement the Get_Count and Get_Argument operations
|
Ada
|
apache-2.0
|
stcarrez/ada-util,stcarrez/ada-util
|
|
248d56e2d7ab28d3f117544d5eaa90345dc461fa
|
mat/regtests/mat-frames-tests.adb
|
mat/regtests/mat-frames-tests.adb
|
-----------------------------------------------------------------------
-- mat-readers-tests -- Unit tests for MAT readers
-- Copyright (C) 2014 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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;
with Ada.Directories;
with Util.Test_Caller;
with MAT.Frames.Print;
with MAT.Readers.Files;
package body MAT.Frames.Tests is
use Util.Tests;
package Caller is new Util.Test_Caller (Test, "Files");
-- Builtin and well known definition of test frames.
Frame_1_0 : constant Frame_Table (1 .. 10) :=
(1_0, 1_2, 1_3, 1_4, 1_5, 1_6, 1_7, 1_8, 1_9, 1_10);
Frame_1_1 : constant Frame_Table (1 .. 15) :=
(1_0, 1_2, 1_3, 1_4, 1_5, 1_6, 1_7, 1_8, 1_9, 1_10,
1_11, 1_12, 1_13, 1_14, 1_15);
Frame_1_2 : constant Frame_Table (1 .. 16) :=
(1_0, 1_2, 1_3, 1_4, 1_5, 1_6, 1_7, 1_8, 1_9, 1_10,
1_11, 1_12, 1_13, 1_14, 1_20, 1_21);
Frame_1_3 : constant Frame_Table (1 .. 15) :=
(1_0, 1_2, 1_3, 1_4, 1_5, 1_6, 1_7, 1_8, 1_9, 1_10,
1_11, 1_12, 1_13, 1_14, 1_30);
Frame_2_0 : constant Frame_Table (1 .. 10) :=
(2_0, 2_2, 2_3, 2_4, 2_5, 2_6, 2_7, 2_8, 2_9, 2_10);
Frame_2_1 : constant Frame_Table (1 .. 10) :=
(2_0, 2_1, 2_1, 2_1, 2_1, 2_1, 2_1, 2_1, 2_1, 2_10);
Frame_2_2 : constant Frame_Table (1 .. 10) :=
(2_0, 2_1, 2_2, 2_1, 2_1, 2_1, 2_1, 2_1, 2_1, 2_1);
Frame_2_3 : constant Frame_Table (1 .. 10) :=
(2_0, 2_1, 2_2, 2_1, 2_1, 2_3, 2_1, 2_1, 2_1, 2_1);
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test MAT.Frames.Insert",
Test_Simple_Frames'Access);
Caller.Add_Test (Suite, "Test MAT.Frames.Find",
Test_Find_Frames'Access);
Caller.Add_Test (Suite, "Test MAT.Frames.Backtrace",
Test_Complex_Frames'Access);
end Add_Tests;
-- ------------------------------
-- Create a tree with the well known test frames.
-- ------------------------------
function Create_Test_Frames return Frame_Type is
Root : Frame_Type := Create_Root;
F : Frame_Type;
begin
Insert (Root, Frame_1_0, F);
Insert (Root, Frame_1_1, F);
Insert (Root, Frame_1_2, F);
Insert (Root, Frame_1_3, F);
Insert (Root, Frame_2_0, F);
Insert (Root, Frame_2_1, F);
Insert (Root, Frame_2_2, F);
Insert (Root, Frame_2_3, F);
return Root;
end Create_Test_Frames;
-- ------------------------------
-- Basic consistency checks when creating the test tree
-- ------------------------------
procedure Test_Simple_Frames (T : in out Test) is
Root : Frame_Type := Create_Root;
F : Frame_Type;
begin
-- Consistency check on empty tree.
Util.Tests.Assert_Equals (T, 0, Count_Children (Root),
"Empty frame: Count_Children must return 0");
Util.Tests.Assert_Equals (T, 0, Current_Depth (Root),
"Empty frame: Current_Depth must return 0");
-- Insert first frame and verify consistency.
Insert (Root, Frame_1_0, F);
Util.Tests.Assert_Equals (T, 1, Count_Children (Root),
"Simple frame: Count_Children must return 1");
Util.Tests.Assert_Equals (T, 10, Current_Depth (F),
"Simple frame: Current_Depth must return 10");
-- Expect (Msg => "Frames.Count_Children",
-- Val => 1,
-- Result => Count_Children (Root));
-- Expect (Msg => "Frames.Count_Children(recursive)",
-- Val => 1,
-- Result => Count_Children (Root, True));
-- Expect (Msg => "Frames.Current_Depth",
-- Val => 10,
-- Result => Current_Depth (F));
Insert (Root, Frame_1_1, F);
Insert (Root, Frame_1_2, F);
Insert (Root, Frame_1_3, F);
if Verbose then
MAT.Frames.Print (Ada.Text_IO.Standard_Output, Root);
end if;
Util.Tests.Assert_Equals (T, 1, Count_Children (Root),
"Simple frame: Count_Children must return 1");
Util.Tests.Assert_Equals (T, 3, Count_Children (Root, True),
"Simple frame: Count_Children (recursive) must return 3");
Util.Tests.Assert_Equals (T, 15, Current_Depth (F),
"Simple frame: Current_Depth must return 15");
Insert (Root, Frame_2_0, F);
Insert (Root, Frame_2_1, F);
Insert (Root, Frame_2_2, F);
Insert (Root, Frame_2_3, F);
if Verbose then
MAT.Frames.Print (Ada.Text_IO.Standard_Output, Root);
end if;
Util.Tests.Assert_Equals (T, 2, Count_Children (Root),
"Simple frame: Count_Children must return 2");
Util.Tests.Assert_Equals (T, 7, Count_Children (Root, True),
"Simple frame: Count_Children (recursive) must return 7");
Util.Tests.Assert_Equals (T, 10, Current_Depth (F),
"Simple frame: Current_Depth must return 10");
Destroy (Root);
end Test_Simple_Frames;
-- ------------------------------
-- Test searching in the frame.
-- ------------------------------
procedure Test_Find_Frames (T : in out Test) is
Root : Frame_Type := Create_Test_Frames;
Result : Frame_Type;
Last_Pc : Natural;
begin
-- Find exact frame.
Find (Root, Frame_2_3, Result, Last_Pc);
T.Assert (Result /= Root, "Frames.Find must return a valid frame");
T.Assert (Last_Pc = 0, "Frames.Find must return a 0 Last_Pc");
declare
Pc : Frame_Table (1 .. 8) := Frame_2_3 (1 .. 8);
begin
Find (Root, Pc, Result, Last_Pc);
T.Assert (Result /= Root, "Frames.Find must return a valid frame");
-- Expect (Msg => "Frames.Find (Last_Pc param)",
-- Val => 0,
-- Result => Last_Pc);
end;
Destroy (Root);
end Test_Find_Frames;
-- ------------------------------
-- Create a complex frame tree and run tests on it.
-- ------------------------------
procedure Test_Complex_Frames (T : in out Test) is
Pc : Frame_Table (1 .. 8);
Root : Frame_Type := Create_Root;
procedure Create_Frame (Depth : in Natural);
procedure Create_Frame (Depth : in Natural) is
use type MAT.Types.Target_Addr;
use type MAT.Events.Frame_Table;
F : Frame_Type;
begin
Pc (Depth) := MAT.Types.Target_Addr (Depth);
if Depth < Pc'Last then
Create_Frame (Depth + 1);
end if;
Insert (Root, Pc (1 .. Depth), F);
Pc (Depth) := MAT.Types.Target_Addr (Depth) + 1000;
Insert (Root, Pc (1 .. Depth), F);
if Depth < Pc'Last then
Create_Frame (Depth + 1);
end if;
declare
Read_Pc : Frame_Table := Backtrace (F);
begin
T.Assert (Read_Pc = Pc (1 .. Depth), "Frames.backtrace (same as inserted)");
if Verbose then
for I in Read_Pc'Range loop
Ada.Text_IO.Put (" " & MAT.Types.Target_Addr'Image (Read_Pc (I)));
end loop;
Ada.Text_IO.New_Line;
end if;
end;
end Create_Frame;
begin
Create_Frame (1);
if Verbose then
MAT.Frames.Print (Ada.Text_IO.Standard_Output, Root);
end if;
Destroy (Root);
end Test_Complex_Frames;
end MAT.Frames.Tests;
|
Implement some unit tests for the stack frame tree
|
Implement some unit tests for the stack frame tree
|
Ada
|
apache-2.0
|
stcarrez/mat,stcarrez/mat,stcarrez/mat
|
|
6bcae9852379443b18b1aa640c93bceaa3f3caf2
|
mat/src/mat-targets-readers.adb
|
mat/src/mat-targets-readers.adb
|
-----------------------------------------------------------------------
-- mat-targets-readers - Definition and Analysis of process start events
-- Copyright (C) 2014 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Log.Loggers;
package body MAT.Targets.Readers is
-- The logger
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("MAT.Targets.Readers");
MSG_BEGIN : constant MAT.Events.Internal_Reference := 0;
MSG_END : constant MAT.Events.Internal_Reference := 1;
M_PID : constant MAT.Events.Internal_Reference := 1;
M_EXE : constant MAT.Events.Internal_Reference := 2;
PID_NAME : aliased constant String := "pid";
EXE_NAME : aliased constant String := "exe";
Process_Attributes : aliased constant MAT.Events.Attribute_Table :=
(1 => (Name => PID_NAME'Access, Size => 0,
Kind => MAT.Events.T_SIZE_T, Ref => M_PID),
2 => (Name => EXE_NAME'Access, Size => 0,
Kind => MAT.Events.T_FRAME, Ref => M_EXE));
procedure Create_Process (For_Servant : in out Process_Servant;
Pid : in MAT.Types.Target_Process_Ref) is
begin
MAT.Memory.Targets.Initialize (Memory => For_Servant.Process.Memory,
Reader => For_Servant.Reader.all);
end Create_Process;
overriding
procedure Dispatch (For_Servant : in out Process_Servant;
Id : in MAT.Events.Internal_Reference;
Params : in MAT.Events.Const_Attribute_Table_Access;
Frame : in MAT.Events.Frame_Info;
Msg : in out MAT.Readers.Message) is
begin
case Id is
when MSG_BEGIN =>
null;
when MSG_END =>
null;
when others =>
null;
end case;
end Dispatch;
-- Register the reader to extract and analyze process events.
procedure Register (Into : in out MAT.Readers.Manager_Base'Class;
Reader : in Process_Reader_Access) is
begin
Into.Register_Reader (Reader.all'Access, "begin", MSG_BEGIN,
Process_Attributes'Access);
Into.Register_Reader (Reader.all'Access, "end", MSG_END,
Process_Attributes'Access);
end Register;
end MAT.Targets.Readers;
|
Implement the package to read the begin/end events and create the process instance
|
Implement the package to read the begin/end events and create the process instance
|
Ada
|
apache-2.0
|
stcarrez/mat,stcarrez/mat,stcarrez/mat
|
|
b8c44f46a2923d418efa9f0f84e6e8afcc134f5e
|
regtests/asf-navigations-tests.adb
|
regtests/asf-navigations-tests.adb
|
-----------------------------------------------------------------------
-- asf-navigations-tests - Tests for ASF navigation
-- Copyright (C) 2013 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Test_Caller;
with Util.Beans.Objects;
with ASF.Tests;
with ASF.Requests.Mockup;
with ASF.Responses.Mockup;
with ASF.Applications.Main;
with ASF.Applications.Main.Configs;
with ASF.Applications.Tests;
package body ASF.Navigations.Tests is
use Util.Beans.Objects;
use ASF.Tests;
package Caller is new Util.Test_Caller (Test, "Navigations");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test navigation exact match (view, outcome, action)",
Test_Exact_Navigation'Access);
Caller.Add_Test (Suite, "Test navigation partial match (view, outcome)",
Test_Partial_Navigation'Access);
Caller.Add_Test (Suite, "Test navigation exception match (view, outcome)",
Test_Exception_Navigation'Access);
end Add_Tests;
-- ------------------------------
-- Initialize the test application
-- ------------------------------
overriding
procedure Set_Up (T : in out Test) is
pragma Unreferenced (T);
use type ASF.Applications.Main.Application_Access;
Fact : ASF.Applications.Main.Application_Factory;
begin
if ASF.Tests.Get_Application = null then
ASF.Tests.Initialize (Util.Tests.Get_Properties, Factory => Fact);
end if;
end Set_Up;
-- ------------------------------
-- Check the navigation for an URI and expect the result to match the regular expression.
-- ------------------------------
procedure Check_Navigation (T : in out Test;
Name : in String;
Match : in String;
Raise_Flag : in Boolean := False) is
Request : ASF.Requests.Mockup.Request;
Reply : ASF.Responses.Mockup.Response;
Form : aliased ASF.Applications.Tests.Form_Bean;
File : constant String := Util.Tests.Get_Path ("regtests/config/test-navigations.xml");
begin
Form.Perm_Error := Raise_Flag;
ASF.Applications.Main.Configs.Read_Configuration (ASF.Tests.Get_Application.all, File);
Request.Set_Attribute ("form", To_Object (Value => Form'Unchecked_Access,
Storage => STATIC));
Do_Get (Request, Reply, "/tests/" & Name & ".html", Name & ".txt");
Request.Set_Parameter ("formText", "1");
Request.Set_Parameter ("name", "John");
Request.Set_Parameter ("password", "12345");
Request.Set_Parameter ("email", "[email protected]");
Request.Set_Parameter ("ok", "1");
Do_Post (Request, Reply, "/tests/" & Name & ".html", Name & "form-navigation-exact.txt");
Assert_Matches (T, Match,
Reply, "Wrong generated content");
end Check_Navigation;
-- ------------------------------
-- Test a form navigation with an exact match (view, outcome, action).
-- ------------------------------
procedure Test_Exact_Navigation (T : in out Test) is
begin
T.Check_Navigation ("form-nav", ".*success.*");
end Test_Exact_Navigation;
-- ------------------------------
-- Test a form navigation with a partial match (view, outcome).
-- ------------------------------
procedure Test_Partial_Navigation (T : in out Test) is
begin
T.Check_Navigation ("form-nav-partial", ".*success partial.*");
end Test_Partial_Navigation;
-- ------------------------------
-- Test a form navigation with a exception match (view, outcome).
-- ------------------------------
procedure Test_Exception_Navigation (T : in out Test) is
begin
T.Check_Navigation ("form-nav-exception", ".*success exception.*", True);
end Test_Exception_Navigation;
end ASF.Navigations.Tests;
|
Add navigation rule unit test
|
Add navigation rule unit test
|
Ada
|
apache-2.0
|
Letractively/ada-asf,Letractively/ada-asf,Letractively/ada-asf
|
|
bfe22b44a87bfe9220e2b3ce8c9678477f66c6fc
|
samples/convert.adb
|
samples/convert.adb
|
-----------------------------------------------------------------------
-- convert -- Convert a wiki format into another
-- Copyright (C) 2022 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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;
with Ada.Wide_Wide_Text_IO;
with Ada.IO_Exceptions;
with Ada.Strings.Unbounded;
with Ada.Strings.UTF_Encoding.Wide_Wide_Strings;
with GNAT.Command_Line;
with Util.Files;
with Util.Strings.Transforms;
with Wiki.Strings;
with Wiki.Filters.Html;
with Wiki.Filters.TOC;
with Wiki.Streams.Builders;
with Wiki.Render.Wiki;
with Wiki.Documents;
with Wiki.Parsers;
procedure Convert is
use GNAT.Command_Line;
use Ada.Strings.Unbounded;
use Ada.Strings.UTF_Encoding;
procedure Usage;
procedure Parse (Content : in String);
procedure Print (Item : in Wiki.Strings.WString);
function To_Syntax (Name : in String) return Wiki.Wiki_Syntax;
Html_Filter : aliased Wiki.Filters.Html.Html_Filter_Type;
TOC : aliased Wiki.Filters.TOC.TOC_Filter;
Count : Natural := 0;
Src_Syntax : Wiki.Wiki_Syntax := Wiki.SYNTAX_MARKDOWN;
Dst_Syntax : Wiki.Wiki_Syntax := Wiki.SYNTAX_MARKDOWN;
procedure Usage is
begin
Ada.Text_IO.Put_Line ("Convert a wiki file from one format to another");
Ada.Text_IO.Put_Line ("Usage: convert [-s format] [-d format] file...");
Ada.Text_IO.Put_Line (" -s format Define the source file format");
Ada.Text_IO.Put_Line (" -d format Define the destination file format");
end Usage;
procedure Print (Item : in Wiki.Strings.WString) is
begin
Ada.Wide_Wide_Text_IO.Put (Item);
end Print;
procedure Parse (Content : in String) is
Doc : Wiki.Documents.Document;
Engine : Wiki.Parsers.Parser;
Stream : aliased Wiki.Streams.Builders.Output_Builder_Stream;
Renderer : aliased Wiki.Render.Wiki.Wiki_Renderer;
begin
Engine.Add_Filter (TOC'Unchecked_Access);
Engine.Add_Filter (Html_Filter'Unchecked_Access);
Engine.Set_Syntax (Src_Syntax);
Engine.Parse (Wide_Wide_Strings.Decode (Content), Doc);
Renderer.Set_Output_Stream (Stream'Unchecked_Access, Dst_Syntax);
Renderer.Render (Doc);
Stream.Iterate (Print'Access);
Ada.Wide_Wide_Text_IO.New_Line;
end Parse;
function To_Syntax (Name : in String) return Wiki.Wiki_Syntax is
begin
if Name = "markdown" then
return Wiki.SYNTAX_MARKDOWN;
end if;
if Name = "dotclear" then
return Wiki.SYNTAX_DOTCLEAR;
end if;
if Name = "creole" then
return Wiki.SYNTAX_CREOLE;
end if;
if Name = "textile" then
return Wiki.SYNTAX_TEXTILE;
end if;
if Name = "mediawiki" then
return Wiki.SYNTAX_MEDIA_WIKI;
end if;
if Name = "html" then
return Wiki.SYNTAX_HTML;
end if;
return Wiki.SYNTAX_MARKDOWN;
end To_Syntax;
begin
loop
case Getopt ("s: d:") is
when 's' =>
declare
Value : constant String := Util.Strings.Transforms.To_Lower_Case (Parameter);
begin
Src_Syntax := To_Syntax (Value);
exception
when Constraint_Error =>
Ada.Text_IO.Put_Line ("Invalid source format " & Value);
end;
when 'd' =>
declare
Value : constant String := Util.Strings.Transforms.To_Lower_Case (Parameter);
begin
Dst_Syntax := To_Syntax (Value);
exception
when Constraint_Error =>
Ada.Text_IO.Put_Line ("Invalid source format " & Value);
end;
when others =>
exit;
end case;
end loop;
loop
declare
Name : constant String := GNAT.Command_Line.Get_Argument;
Data : Unbounded_String;
begin
if Name = "" then
if Count = 0 then
Usage;
end if;
return;
end if;
Count := Count + 1;
Util.Files.Read_File (Name, Data);
Parse (To_String (Data));
exception
when Ada.IO_Exceptions.Name_Error =>
Ada.Text_IO.Put_Line ("Cannot read file '" & Name & "'");
end;
end loop;
exception
when Invalid_Switch =>
Ada.Text_IO.Put_Line ("Invalid option.");
Usage;
end Convert;
|
Add new example to convert a wiki syntax into another
|
Add new example to convert a wiki syntax into another
|
Ada
|
apache-2.0
|
stcarrez/ada-wiki,stcarrez/ada-wiki
|
|
44c560358e27dd3dc2bb7141db0b68f1394b553f
|
samples/objcalc.adb
|
samples/objcalc.adb
|
with Ada.Text_IO;
with Ada.Command_Line;
with Util.Beans.Objects;
procedure ObjCalc is
package UBO renames Util.Beans.Objects;
use type UBO.Object;
Value : UBO.Object := UBO.To_Object (Integer (0));
begin
Value := Value + UBO.To_Object (Integer (123));
Value := Value - UBO.To_Object (String '("12"));
-- Should print '111'
Ada.Text_IO.Put_Line (UBO.To_String (Value));
end ObjCalc;
|
Add very simple examples for Objects
|
Add very simple examples for Objects
|
Ada
|
apache-2.0
|
stcarrez/ada-util,stcarrez/ada-util
|
|
e2a5e17dddb81a96242f462b8e8013a57f7e7cdd
|
src/asis/asis-ada_environments.adb
|
src/asis/asis-ada_environments.adb
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A S I S . A D A _ E N V I R O N M E N T S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1995-2008, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adaccore.com). --
-- --
------------------------------------------------------------------------------
with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Strings; use Ada.Strings;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Asis.Errors; use Asis.Errors;
with Asis.Exceptions; use Asis.Exceptions;
with Asis.Set_Get; use Asis.Set_Get;
with A4G.A_Debug; use A4G.A_Debug;
with A4G.A_Opt; use A4G.A_Opt;
with A4G.A_Output; use A4G.A_Output;
with A4G.Contt; use A4G.Contt;
with A4G.Contt.TT; use A4G.Contt.TT;
with A4G.Contt.UT; use A4G.Contt.UT;
with A4G.Vcheck; use A4G.Vcheck;
with Output; use Output;
package body Asis.Ada_Environments is
Package_Name : constant String := "Asis.Ada_Environments.";
---------------
-- Associate --
---------------
procedure Associate
(The_Context : in out Asis.Context;
Name : Wide_String;
Parameters : Wide_String := Default_Parameters)
is
S_Parameters : constant String := Trim (To_String (Parameters), Both);
Cont : Context_Id;
begin
Cont := Get_Cont_Id (The_Context);
if not A4G.A_Opt.Is_Initialized then
Set_Error_Status
(Status => Initialization_Error,
Diagnosis => Package_Name & "Associate: "
& "called for non-initialized ASIS");
raise ASIS_Failed;
end if;
if Is_Opened (Cont) then
Set_Error_Status
(Status => Value_Error,
Diagnosis => Package_Name & "Associate: "
& "the Context has already been opened");
raise ASIS_Inappropriate_Context;
end if;
if Cont = Non_Associated then
-- this is the first association for a given Context
Cont := Allocate_New_Context;
Set_Cont (The_Context, Cont);
else
Erase_Old (Cont);
end if;
Verify_Context_Name (To_String (Name), Cont);
Process_Context_Parameters (S_Parameters, Cont);
Set_Is_Associated (Cont, True);
Save_Context (Cont);
Set_Current_Cont (Nil_Context_Id);
exception
when ASIS_Inappropriate_Context =>
Set_Is_Associated (Cont, False);
raise;
when ASIS_Failed =>
Set_Is_Associated (Cont, False);
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information (Outer_Call => Package_Name & "Associate");
end if;
raise;
when Ex : others =>
Set_Is_Associated (Cont, False);
Report_ASIS_Bug
(Query_Name => Package_Name & "Associate",
Ex => Ex);
end Associate;
-----------
-- Close --
-----------
procedure Close (The_Context : in out Asis.Context) is
Cont : Context_Id;
begin
Cont := Get_Cont_Id (The_Context);
Reset_Context (Cont);
if not Is_Opened (Cont) then
Set_Error_Status (Status => Value_Error,
Diagnosis => Package_Name & "Close: " &
"the Context is not open");
raise ASIS_Inappropriate_Context;
end if;
if Debug_Flag_C or else
Debug_Lib_Model or else
Debug_Mode
then
Write_Str ("Closing Context ");
Write_Int (Int (Cont));
Write_Eol;
Print_Units (Cont);
Print_Trees (Cont);
end if;
Set_Is_Opened (Cont, False);
Set_Current_Cont (Nil_Context_Id);
Reset_Cache;
exception
when ASIS_Inappropriate_Context =>
raise;
when ASIS_Failed =>
Set_Current_Cont (Nil_Context_Id);
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information (Outer_Call => Package_Name & "Close");
end if;
raise;
when Ex : others =>
Set_Current_Cont (Nil_Context_Id);
Report_ASIS_Bug
(Query_Name => Package_Name & "Associate",
Ex => Ex);
end Close;
-----------------
-- Debug_Image --
-----------------
function Debug_Image
(The_Context : Asis.Context)
return Wide_String
is
Arg_Cont : Context_Id;
LT : Wide_String renames A4G.A_Types.Asis_Wide_Line_Terminator;
begin
Arg_Cont := Get_Cont_Id (The_Context);
Reset_Context (Arg_Cont);
return LT & "Context Debug_Image: " &
LT & "Context Id is" &
Context_Id'Wide_Image (Arg_Cont) &
LT & To_Wide_String (Debug_String (The_Context));
exception
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Debug_Image",
Ex => Ex);
end Debug_Image;
------------------
-- Default_Name --
------------------
function Default_Name return Wide_String is
begin
return Nil_Asis_Wide_String;
end Default_Name;
------------------------
-- Default_Parameters --
------------------------
function Default_Parameters return Wide_String is
begin
return Nil_Asis_Wide_String;
end Default_Parameters;
----------------
-- Dissociate --
----------------
procedure Dissociate (The_Context : in out Asis.Context) is
Cont : Context_Id;
begin
Cont := Get_Cont_Id (The_Context);
if Is_Opened (Cont) then
Set_Error_Status (Status => Value_Error,
Diagnosis => Package_Name & "Dissociate: "
& "the Context is open");
raise ASIS_Inappropriate_Context;
end if;
if Debug_Flag_C or else
Debug_Lib_Model or else
Debug_Mode
then
Write_Str ("Dissociating Context ");
Write_Int (Int (Cont));
Write_Eol;
Print_Context_Parameters (Cont);
end if;
if Is_Associated (Cont) then
Erase_Old (Cont);
Set_Is_Associated (Cont, False);
end if;
exception
when ASIS_Inappropriate_Context =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information (Outer_Call => Package_Name & "Dissociate");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Dissociate",
Ex => Ex);
end Dissociate;
------------
-- Exists --
------------
function Exists (The_Context : Asis.Context) return Boolean is
Cont : Context_Id;
begin
Cont := Get_Cont_Id (The_Context);
return Is_Associated (Cont);
end Exists;
----------------------
-- Has_Associations --
----------------------
function Has_Associations
(The_Context : Asis.Context)
return Boolean
is
Cont : Context_Id;
begin
Cont := Get_Cont_Id (The_Context);
return Is_Associated (Cont);
end Has_Associations;
--------------
-- Is_Equal --
--------------
function Is_Equal
(Left : Asis.Context;
Right : Asis.Context)
return Boolean
is
begin
return Get_Cont_Id (Left) = Get_Cont_Id (Right);
-- Should be revised
end Is_Equal;
------------------
-- Is_Identical --
------------------
function Is_Identical
(Left : Asis.Context;
Right : Asis.Context)
return Boolean
is
begin
return Get_Cont_Id (Left) = Get_Cont_Id (Right);
end Is_Identical;
-------------
-- Is_Open --
-------------
function Is_Open (The_Context : Asis.Context) return Boolean is
Cont : Context_Id;
begin
Cont := Get_Cont_Id (The_Context);
return Is_Opened (Cont);
end Is_Open;
----------
-- Name --
----------
function Name (The_Context : Asis.Context) return Wide_String is
Cont : Context_Id;
begin
Cont := Get_Cont_Id (The_Context);
return To_Wide_String (Get_Context_Name (Cont));
end Name;
----------
-- Open --
----------
procedure Open (The_Context : in out Asis.Context) is
Cont : Context_Id;
Context_Tree_Mode : Tree_Mode;
begin
Cont := Get_Cont_Id (The_Context);
if not Is_Associated (Cont) then
Set_Error_Status (Status => Value_Error,
Diagnosis => Package_Name & "Open: " &
"the Context does not have association");
raise ASIS_Inappropriate_Context;
elsif Is_Opened (Cont) then
Set_Error_Status (Status => Value_Error,
Diagnosis => Package_Name & "Open: " &
"the Context has already been opened");
raise ASIS_Inappropriate_Context;
end if;
Reset_Context (Cont);
Context_Tree_Mode := Tree_Processing_Mode (Cont);
if Tree_Processing_Mode (Cont) = GNSA then
Set_Error_Status (Status => Use_Error,
Diagnosis => Package_Name & "Open: " &
"GNSA Context mode is not allowed");
raise ASIS_Inappropriate_Context;
end if;
Increase_ASIS_OS_Time;
Pre_Initialize (Cont);
A4G.Contt.Initialize (Cont);
-- Having these two Pre_Initialize and A4G.Contt.Initialize calling
-- one after another is a kind of junk, but there are some problems
-- with multi-context processing which have not been completely
-- detected and which does not allow to get rid of this definitely
-- redundunt "initialization"
case Context_Tree_Mode is
when Pre_Created | Mixed =>
Scan_Trees_New (Cont);
when Incremental =>
-- Not the best approach, unfortunately
begin
Scan_Trees_New (Cont);
exception
when Inconsistent_Incremental_Context =>
-- Setting empty incremental context:
Pre_Initialize (Cont);
A4G.Contt.Initialize (Cont);
end;
when others =>
null;
end case;
Set_Is_Opened (Cont, True);
Save_Context (Cont);
Set_Current_Cont (Nil_Context_Id);
exception
when Program_Error =>
raise;
when ASIS_Inappropriate_Context =>
raise;
when ASIS_Failed =>
Set_Is_Opened (Cont, False);
Set_Current_Cont (Nil_Context_Id);
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information (Outer_Call => Package_Name & "Open");
end if;
raise;
when Ex : others =>
Set_Is_Opened (Cont, False);
Set_Current_Cont (Nil_Context_Id);
Report_ASIS_Bug
(Query_Name => Package_Name & "Open",
Ex => Ex);
end Open;
----------------
-- Parameters --
----------------
function Parameters (The_Context : Asis.Context) return Wide_String is
Cont : Context_Id;
begin
Cont := Get_Cont_Id (The_Context);
return To_Wide_String (Get_Context_Parameters (Cont));
end Parameters;
end Asis.Ada_Environments;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen
|
|
9347897714ee6394d6591b74746fd17ecc9d8ba3
|
src/os-linux/util-systems-dlls.adb
|
src/os-linux/util-systems-dlls.adb
|
-----------------------------------------------------------------------
-- util-systems-dlls -- Unix shared library support
-- Copyright (C) 2013 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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;
with Interfaces.C;
with Interfaces.C.Strings;
with Util.Systems.Constants;
package body Util.Systems.DLLs is
function Sys_Dlopen (Path : in Interfaces.C.Strings.chars_ptr;
Mode : in Flags) return Handle;
pragma Import (C, Sys_Dlopen, "dlopen");
function Sys_Dlclose (Lib : in Handle) return Interfaces.C.int;
pragma Import (C, Sys_Dlclose, "dlclose");
function Sys_Dlsym (Lib : in Handle;
Symbol : in Interfaces.C.Strings.chars_ptr) return System.Address;
pragma Import (C, Sys_Dlsym, "dlsym");
function Sys_Dlerror return Interfaces.C.Strings.chars_ptr;
pragma Import (C, Sys_Dlerror, "dlerror");
function Error_Message return String is
begin
return Interfaces.C.Strings.Value (Sys_Dlerror);
end Error_Message;
pragma Linker_Options ("-ldl");
-- -----------------------
-- Load the shared library with the given name or path and return a library handle.
-- Raises the <tt>Load_Error</tt> exception if the library cannot be loaded.
-- -----------------------
function Load (Path : in String;
Mode : in Flags := Util.Systems.Constants.RTLD_LAZY) return Handle is
Lib : Interfaces.C.Strings.chars_ptr := Interfaces.C.Strings.New_String (Path);
Result : Handle := Sys_Dlopen (Lib, Mode);
begin
Interfaces.C.Strings.Free (Lib);
if Result = Null_Handle then
raise Load_Error with Error_Message;
else
return Result;
end if;
end Load;
-- -----------------------
-- Unload the shared library.
-- -----------------------
procedure Unload (Lib : in Handle) is
Result : Interfaces.C.int;
begin
if Lib /= Null_Handle then
Result := Sys_Dlclose (Lib);
end if;
end Unload;
-- -----------------------
-- Get a global symbol with the given name in the library.
-- Raises the <tt>Not_Found</tt> exception if the symbol does not exist.
-- -----------------------
function Get_Symbol (Lib : in Handle;
Name : in String) return System.Address is
use type System.Address;
Symbol : Interfaces.C.Strings.Chars_Ptr := Interfaces.C.Strings.New_String (Name);
Result : System.Address := Sys_Dlsym (Lib, Symbol);
begin
Interfaces.C.Strings.Free (Symbol);
if Result = System.Null_Address then
raise Not_Found with Error_Message;
else
return Result;
end if;
end Get_Symbol;
end Util.Systems.DLLs;
|
Implement the shared library support for Unix
|
Implement the shared library support for Unix
|
Ada
|
apache-2.0
|
stcarrez/ada-util,stcarrez/ada-util
|
|
755e61356a6a2c3061a46f4986a8ca66433ad829
|
src/util-texts-builders.adb
|
src/util-texts-builders.adb
|
-----------------------------------------------------------------------
-- util-texts-builders -- Text builder
-- Copyright (C) 2013 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Unchecked_Deallocation;
package body Util.Texts.Builders is
-- ------------------------------
-- Get the length of the item builder.
-- ------------------------------
function Length (Source : in Builder) return Natural is
begin
return Source.Length;
end Length;
-- ------------------------------
-- Get the capacity of the builder.
-- ------------------------------
function Capacity (Source : in Builder) return Natural is
B : constant Block_Access := Source.Current;
begin
return Source.Length + B.Len - B.Last;
end Capacity;
-- ------------------------------
-- Get the builder block size.
-- ------------------------------
function Block_Size (Source : in Builder) return Positive is
begin
return Source.Block_Size;
end Block_Size;
-- ------------------------------
-- Set the block size for the allocation of next chunks.
-- ------------------------------
procedure Set_Block_Size (Source : in out Builder;
Size : in Positive) is
begin
Source.Block_Size := Size;
end Set_Block_Size;
-- ------------------------------
-- Append the <tt>New_Item</tt> at the end of the source growing the buffer if necessary.
-- ------------------------------
procedure Append (Source : in out Builder;
New_Item : in Input) is
B : Block_Access := Source.Current;
Start : Natural := New_Item'First;
Last : constant Natural := New_Item'Last;
begin
while Start <= Last loop
declare
Space : Natural := B.Len - B.Last;
Size : constant Natural := Last - Start + 1;
begin
if Space > Size then
Space := Size;
elsif Space = 0 then
if Size > Source.Block_Size then
B.Next_Block := new Block (Size);
else
B.Next_Block := new Block (Source.Block_Size);
end if;
B := B.Next_Block;
Source.Current := B;
if B.Len > Size then
Space := Size;
else
Space := B.Len;
end if;
end if;
B.Content (B.Last + 1 .. B.Last + Space) := New_Item (Start .. Start + Space - 1);
Source.Length := Source.Length + Space;
B.Last := B.Last + Space;
Start := Start + Space;
end;
end loop;
end Append;
-- ------------------------------
-- Append the <tt>New_Item</tt> at the end of the source growing the buffer if necessary.
-- ------------------------------
procedure Append (Source : in out Builder;
New_Item : in Element_Type) is
B : Block_Access := Source.Current;
begin
if B.Len = B.Last then
B.Next_Block := new Block (Source.Block_Size);
B := B.Next_Block;
Source.Current := B;
end if;
Source.Length := Source.Length + 1;
B.Last := B.Last + 1;
B.Content (B.Last) := New_Item;
end Append;
-- ------------------------------
-- Clear the source freeing any storage allocated for the buffer.
-- ------------------------------
procedure Clear (Source : in out Builder) is
procedure Free is
new Ada.Unchecked_Deallocation (Object => Block, Name => Block_Access);
Current, Next : Block_Access;
begin
Next := Source.First.Next_Block;
while Next /= null loop
Current := Next;
Next := Current.Next_Block;
Free (Current);
end loop;
Source.First.Next_Block := null;
Source.First.Last := 0;
Source.Current := Source.First'Unchecked_Access;
Source.Length := 0;
end Clear;
-- ------------------------------
-- Iterate over the buffer content calling the <tt>Process</tt> procedure with each
-- chunk.
-- ------------------------------
procedure Iterate (Source : in Builder;
Process : not null access procedure (Chunk : in Input)) is
begin
if Source.First.Last > 0 then
Process (Source.First.Content (1 .. Source.First.Last));
declare
B : Block_Access := Source.First.Next_Block;
begin
while B /= null loop
Process (B.Content (1 .. B.Last));
B := B.Next_Block;
end loop;
end;
end if;
end Iterate;
-- ------------------------------
-- Get the buffer content as an array.
-- ------------------------------
function To_Array (Source : in Builder) return Input is
Result : Input (1 .. Source.Length);
begin
if Source.First.Last > 0 then
declare
Pos : Positive := Source.First.Last;
B : Block_Access := Source.First.Next_Block;
begin
Result (1 .. Pos) := Source.First.Content (1 .. Pos);
while B /= null loop
Result (Pos + 1 .. Pos + B.Last) := B.Content (1 .. B.Last);
Pos := Pos + B.Last;
B := B.Next_Block;
end loop;
end;
end if;
return Result;
end To_Array;
-- ------------------------------
-- Setup the builder.
-- ------------------------------
overriding
procedure Initialize (Source : in out Builder) is
begin
Source.Current := Source.First'Unchecked_Access;
end Initialize;
-- ------------------------------
-- Finalize the builder releasing the storage.
-- ------------------------------
overriding
procedure Finalize (Source : in out Builder) is
begin
Clear (Source);
end Finalize;
end Util.Texts.Builders;
|
Implement the new package
|
Implement the new package
|
Ada
|
apache-2.0
|
Letractively/ada-util,flottokarotto/ada-util,flottokarotto/ada-util,Letractively/ada-util
|
|
832ad8e835a7580072958a9ae1c77ce890b7ba0e
|
src/asis/a4g-gnat_int.adb
|
src/asis/a4g-gnat_int.adb
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . G N A T _ I N T --
-- --
-- B o d y --
-- --
-- Copyright (C) 1995-2012, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
with Ada.Exceptions;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Directory_Operations; use GNAT.Directory_Operations;
with Asis.Errors;
with Asis.Exceptions; use Asis.Exceptions;
with Asis.Extensions; use Asis.Extensions;
with A4G.A_Debug; use A4G.A_Debug;
with A4G.A_Opt; use A4G.A_Opt;
with A4G.A_Output; use A4G.A_Output;
with A4G.Contt; use A4G.Contt;
with A4G.Vcheck; use A4G.Vcheck;
with Aspects;
with Atree;
with Csets;
with Elists;
with Fname;
with Gnatvsn;
with Lib;
with Namet;
with Nlists;
with Opt; use Opt;
with Repinfo;
with Sem_Aux;
with Sinput;
with Stand;
with Stringt;
with Uintp;
with Urealp;
with Tree_IO;
package body A4G.GNAT_Int is
LT : String renames ASIS_Line_Terminator;
Standard_GCC : constant String_Access :=
GNAT.OS_Lib.Locate_Exec_On_Path ("gcc");
-----------------
-- Create_Tree --
-----------------
procedure Create_Tree (Source_File : String_Access;
Context : Context_Id;
Is_Predefined : Boolean;
Success : out Boolean)
is
begin
if Is_Predefined then
Compile (Source_File => Source_File,
Args => (1 => GNAT_Flag),
Success => Success,
GCC => Gcc_To_Call (Context));
else
Compile (Source_File => Source_File,
Args => I_Options (Context),
Success => Success,
GCC => Gcc_To_Call (Context));
end if;
exception
when others =>
Raise_ASIS_Failed ("A4G.GNAT_Int.Create_Tree:" & LT &
" check the path and environment settings for gcc!");
end Create_Tree;
-------------
-- Execute --
-------------
function Execute
(Program : String_Access;
Args : Argument_List;
Compiler_Out : String := "";
Display_Call : Boolean := A4G.A_Debug.Debug_Mode)
return Boolean
is
Success : Boolean;
Return_Code : Integer;
Execute : String_Access := Program;
begin
if Execute = null then
Execute := Standard_GCC;
end if;
if Display_Call then
Put (Standard_Error, Execute.all);
for J in Args'Range loop
Put (Standard_Error, " ");
Put (Standard_Error, Args (J).all);
end loop;
New_Line (Standard_Error);
end if;
if Execute = null then
Ada.Exceptions.Raise_Exception
(Program_Error'Identity,
"A4G.GNAT_Int.Execute: Can not locate program to execute");
end if;
if Compiler_Out /= "" then
GNAT.OS_Lib.Spawn
(Execute.all,
Args,
Compiler_Out,
Success,
Return_Code);
Success := Return_Code = 0;
else
GNAT.OS_Lib.Spawn (Execute.all, Args, Success);
end if;
return Success;
end Execute;
----------------------------------------------
-- General Interfaces between GNAT and ASIS --
----------------------------------------------
function A_Time (T : Time_Stamp_Type) return Time is
Year : Year_Number;
Month : Month_Number;
Day : Day_Number;
Hours : Integer range 0 .. 23;
Minutes : Integer range 0 .. 59;
Seconds : Integer range 0 .. 59;
Day_Time : Day_Duration;
begin
Split_Time_Stamp
(TS => T,
Year => Nat (Year),
Month => Nat (Month),
Day => Nat (Day),
Hour => Nat (Hours),
Minutes => Nat (Minutes),
Seconds => Nat (Seconds));
Day_Time := Duration (Seconds + 60 * Minutes + 3600 * Hours);
return Time_Of (Year, Month, Day, Day_Time);
end A_Time;
--------------------------------
-- Tree_In_With_Version_Check --
--------------------------------
procedure Tree_In_With_Version_Check
(Desc : File_Descriptor;
Cont : Context_Id;
Success : out Boolean)
is
Cont_Mode : constant Context_Mode := Context_Processing_Mode (Cont);
File_Closed : Boolean := False;
ASIS_GNAT_V : constant String := Gnatvsn.Gnat_Version_String;
First_A_Idx : Natural := ASIS_GNAT_V'First;
Last_A_Idx : Natural;
First_T_Idx : Natural;
Last_T_Idx : Natural;
begin
Success := False;
Tree_IO.Tree_Read_Initialize (Desc);
Opt.Tree_Read;
-- GNAT/ASIS version check first
if Tree_ASIS_Version_Number /= Tree_IO.ASIS_Version_Number then
Close (Desc, File_Closed);
Ada.Exceptions.Raise_Exception
(Program_Error'Identity, "Inconsistent versions of GNAT and ASIS");
end if;
-- Check that ASIS Pro uses the tree created by GNAT Pro
First_T_Idx := Tree_Version_String'First;
if ASIS_GNAT_V (First_A_Idx .. First_A_Idx + 2) = "Pro"
and then Tree_Version_String (First_T_Idx .. First_T_Idx + 2) /=
"Pro"
then
Close (Desc, File_Closed);
Ada.Exceptions.Raise_Exception
(Program_Error'Identity, "ASIS Pro can be used with GNAT Pro only");
end if;
if Strong_Version_Check then
-- We check only the dates here!
First_A_Idx :=
Index (Source => ASIS_GNAT_V,
Pattern => "(") + 1;
First_T_Idx :=
Index (Source => Tree_Version_String.all,
Pattern => "(") + 1;
Last_A_Idx := Index (Source => ASIS_GNAT_V,
Pattern => ")") - 1;
if Index (Source => ASIS_GNAT_V, Pattern => "-") /= 0 then
Last_A_Idx := Index (Source => ASIS_GNAT_V,
Pattern => "-") - 1;
end if;
Last_T_Idx := Index (Source => Tree_Version_String.all,
Pattern => ")") - 1;
if Index (Source => Tree_Version_String.all, Pattern => "-") /=
0
then
Last_T_Idx :=
Index (Source => Tree_Version_String.all,
Pattern => "-") - 1;
end if;
if ASIS_GNAT_V (First_A_Idx .. Last_A_Idx) /=
Tree_Version_String (First_T_Idx .. Last_T_Idx)
then
Close (Desc, File_Closed);
Ada.Exceptions.Raise_Exception
(Program_Error'Identity,
"Inconsistent versions of GNAT [" & Tree_Version_String.all &
"] and ASIS [" & ASIS_GNAT_V & ']');
end if;
end if;
-- Check if we are in Ada 2012 mode and need aspects...
-- if Opt.Ada_Version_Config = Ada_2012 then
-- -- For now, reading aspects is protected by the debug '.A' flag
-- Debug.Debug_Flag_Dot_AA := True;
-- end if;
if Operating_Mode /= Check_Semantics then
if Cont_Mode = One_Tree then
-- If in one-tree mode we can not read the only tree we have,
-- there is no reason to continue, so raising an exception
-- is the only choice:
Close (Desc, File_Closed);
-- We did not check File_Closed here, because the fact that the
-- tree is not compile-only seems to be more important for ASIS
Set_Error_Status
(Status => Asis.Errors.Use_Error,
Diagnosis => "Asis.Ada_Environments.Open:"
& ASIS_Line_Terminator
& "tree file "
& Base_Name (A_Name_Buffer (1 .. A_Name_Len))
& " is not compile-only");
raise ASIS_Failed;
elsif Cont_Mode = N_Trees
or else
Cont_Mode = All_Trees
then
-- no need to read the rest of this tree file, but
-- we can continue even if we can not read some trees...
ASIS_Warning
(Message => "Asis.Ada_Environments.Open: "
& ASIS_Line_Terminator
& "tree file "
& Base_Name (A_Name_Buffer (1 .. A_Name_Len))
& " is not compile-only, ignored",
Error => Asis.Errors.Use_Error);
end if;
-- debug stuff...
if (Debug_Flag_O or else
Debug_Lib_Model or else
Debug_Mode)
and then
Cont_Mode /= One_Tree and then
Cont_Mode /= N_Trees
then
Put (Standard_Error, "The tree file ");
Put (Standard_Error, Base_Name (A_Name_Buffer (1 .. A_Name_Len)));
Put (Standard_Error, " is not compile-only");
New_Line (Standard_Error);
end if;
else
Atree.Tree_Read;
Elists.Tree_Read;
Fname.Tree_Read;
Lib.Tree_Read;
Namet.Tree_Read;
Nlists.Tree_Read;
Sem_Aux.Tree_Read;
Sinput.Tree_Read;
Stand.Tree_Read;
Stringt.Tree_Read;
Uintp.Tree_Read;
Urealp.Tree_Read;
Repinfo.Tree_Read;
Aspects.Tree_Read;
Csets.Initialize;
-- debug stuff...
if Debug_Flag_O or else
Debug_Lib_Model or else
Debug_Mode
then
Put (Standard_Error, "The tree file ");
Put (Standard_Error, Base_Name (A_Name_Buffer (1 .. A_Name_Len)));
Put (Standard_Error, " is OK");
New_Line (Standard_Error);
end if;
Success := True;
end if;
Close (Desc, File_Closed);
if not File_Closed then
Raise_ASIS_Failed
(Diagnosis => "Asis.Ada_Environments.Open: " &
"Can not close tree file: " &
Base_Name (A_Name_Buffer (1 .. A_Name_Len)) &
ASIS_Line_Terminator &
"disk is full or file may be used by other program",
Stat => Asis.Errors.Data_Error);
end if;
exception
when Tree_IO.Tree_Format_Error =>
Close (Desc, File_Closed);
Ada.Exceptions.Raise_Exception
(Program_Error'Identity, "Inconsistent versions of GNAT and ASIS");
end Tree_In_With_Version_Check;
end A4G.GNAT_Int;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen
|
|
b5e9c18121ec10fea84bd80542da8a2586fcd024
|
src/security-auth-oauth-facebook.adb
|
src/security-auth-oauth-facebook.adb
|
-----------------------------------------------------------------------
-- security-auth-oauth-facebook -- Facebook OAuth based authentication
-- Copyright (C) 2013 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Beans.Objects;
with Util.Beans.Objects.Time;
with Util.Serialize.Mappers.Record_Mapper;
with Util.Http.Rest;
package body Security.Auth.OAuth.Facebook is
--
TIME_SHIFT : constant Duration := 12 * 3600.0;
type Token_Info_Field_Type is (FIELD_APP_ID, FIELD_IS_VALID,
FIELD_EXPIRES, FIELD_ISSUED_AT,
FIELD_USER_ID, FIELD_EMAIL, FIELD_FIRST_NAME,
FIELD_LAST_NAME, FIELD_NAME, FIELD_LOCALE, FIELD_GENDER);
type Token_Info is record
App_Id : Ada.Strings.Unbounded.Unbounded_String;
Is_Valid : Boolean := False;
Expires : Ada.Calendar.Time;
Issued : Ada.Calendar.Time;
User_Id : Ada.Strings.Unbounded.Unbounded_String;
Email : Ada.Strings.Unbounded.Unbounded_String;
Name : Ada.Strings.Unbounded.Unbounded_String;
First_Name : Ada.Strings.Unbounded.Unbounded_String;
Last_Name : Ada.Strings.Unbounded.Unbounded_String;
Locale : Ada.Strings.Unbounded.Unbounded_String;
Gender : Ada.Strings.Unbounded.Unbounded_String;
end record;
type Token_Info_Access is access all Token_Info;
procedure Set_Member (Into : in out Token_Info;
Field : in Token_Info_Field_Type;
Value : in Util.Beans.Objects.Object);
procedure Set_Member (Into : in out Token_Info;
Field : in Token_Info_Field_Type;
Value : in Util.Beans.Objects.Object) is
begin
case Field is
when FIELD_APP_ID =>
Into.App_Id := Util.Beans.Objects.To_Unbounded_String (Value);
when FIELD_IS_VALID =>
Into.Is_Valid := Util.Beans.Objects.To_Boolean (Value);
when FIELD_EXPIRES =>
Into.Expires := Util.Beans.Objects.Time.To_Time (Value);
when FIELD_ISSUED_AT =>
Into.Issued := Util.Beans.Objects.Time.To_Time (Value);
when FIELD_USER_ID =>
Into.User_Id := Util.Beans.Objects.To_Unbounded_String (Value);
when FIELD_EMAIL =>
Into.Email := Util.Beans.Objects.To_Unbounded_String (Value);
when FIELD_NAME =>
Into.Name := Util.Beans.Objects.To_Unbounded_String (Value);
when FIELD_FIRST_NAME =>
Into.First_Name := Util.Beans.Objects.To_Unbounded_String (Value);
when FIELD_LAST_NAME =>
Into.Last_Name := Util.Beans.Objects.To_Unbounded_String (Value);
when FIELD_LOCALE =>
Into.Locale := Util.Beans.Objects.To_Unbounded_String (Value);
when FIELD_GENDER =>
Into.Gender := Util.Beans.Objects.To_Unbounded_String (Value);
end case;
end Set_Member;
package Token_Info_Mapper is
new Util.Serialize.Mappers.Record_Mapper (Element_Type => Token_Info,
Element_Type_Access => Token_Info_Access,
Fields => Token_Info_Field_Type,
Set_Member => Set_Member);
procedure Get_Token_Info is
new Util.Http.Rest.Rest_Get (Element_Mapper => Token_Info_Mapper);
Token_Info_Map : aliased Token_Info_Mapper.Mapper;
-- ------------------------------
-- Verify the OAuth access token and retrieve information about the user.
-- ------------------------------
overriding
procedure Verify_Access_Token (Realm : in Manager;
Assoc : in Association;
Request : in Parameters'Class;
Token : in Security.OAuth.Clients.Access_Token_Access;
Result : in out Authentication) is
use type Ada.Calendar.Time;
T : constant String := Token.Get_Name;
Info : aliased Token_Info;
Now : constant Ada.Calendar.Time := Ada.Calendar.Clock;
begin
Get_Token_Info ("https://graph.facebook.com/debug_token?access_token=" & T
& "&input_token=" & T,
Token_Info_Map'Access,
"/data",
Info'Unchecked_Access);
if not Info.Is_Valid then
Set_Result (Result, INVALID_SIGNATURE, "invalid access token returned");
elsif Info.Issued + TIME_SHIFT < Now then
Set_Result (Result, INVALID_SIGNATURE, "the access token issued more than 1 hour ago");
elsif Info.Expires + TIME_SHIFT < Now then
Set_Result (Result, INVALID_SIGNATURE, "the access token has expored");
elsif Length (Info.User_Id) = 0 then
Set_Result (Result, INVALID_SIGNATURE, "the access token refers to an empty user_id");
elsif Info.App_Id /= Realm.App.Get_Application_Identifier then
Set_Result (Result, INVALID_SIGNATURE,
"the access token was granted for another application");
else
Result.Identity := To_Unbounded_String ("https://graph.facebook.com/");
Append (Result.Identity, Info.User_Id);
Result.Claimed_Id := Result.Identity;
Get_Token_Info ("https://graph.facebook.com/" & To_String (Info.User_Id)
& "?access_token=" & T,
Token_Info_Map'Access,
"",
Info'Unchecked_Access);
Result.Email := Info.Email;
Result.Full_Name := Info.Name;
Result.First_Name := Info.First_Name;
Result.Last_Name := Info.Last_Name;
Result.Language := Info.Locale;
Result.Gender := Info.Gender;
Set_Result (Result, AUTHENTICATED, "authenticated");
end if;
end Verify_Access_Token;
begin
Token_Info_Map.Add_Mapping ("app_id", FIELD_APP_ID);
Token_Info_Map.Add_Mapping ("expires_at", FIELD_EXPIRES);
Token_Info_Map.Add_Mapping ("issued_at", FIELD_ISSUED_AT);
Token_Info_Map.Add_Mapping ("is_valid", FIELD_IS_VALID);
Token_Info_Map.Add_Mapping ("user_id", FIELD_USER_ID);
Token_Info_Map.Add_Mapping ("email", FIELD_EMAIL);
Token_Info_Map.Add_Mapping ("name", FIELD_NAME);
Token_Info_Map.Add_Mapping ("first_name", FIELD_FIRST_NAME);
Token_Info_Map.Add_Mapping ("last_name", FIELD_LAST_NAME);
Token_Info_Map.Add_Mapping ("locale", FIELD_LOCALE);
Token_Info_Map.Add_Mapping ("gender", FIELD_GENDER);
end Security.Auth.OAuth.Facebook;
|
Implement the Facebook authentication
|
Implement the Facebook authentication
|
Ada
|
apache-2.0
|
stcarrez/ada-security
|
|
123137300d4611e642200af246f15ab1e03c97f6
|
src/util-serialize-mappers-record_mapper.ads
|
src/util-serialize-mappers-record_mapper.ads
|
-----------------------------------------------------------------------
-- Util.Serialize.Mappers.Record_Mapper -- Mapper for record types
-- Copyright (C) 2010, 2011 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Beans.Objects;
with Util.Serialize.IO;
generic
type Element_Type (<>) is limited private;
type Element_Type_Access is access all Element_Type;
type Fields is (<>);
-- The <b>Set_Member</b> procedure will be called by the mapper when a mapping associated
-- with <b>Field</b> is recognized. The <b>Value</b> holds the value that was extracted
-- according to the mapping. The <b>Set_Member</b> procedure should save in the target
-- object <b>Into</b> the value. If an error is detected, the procedure can raise the
-- <b>Util.Serialize.Mappers.Field_Error</b> exception. The exception message will be
-- reported by the IO reader as an error.
with procedure Set_Member (Into : in out Element_Type;
Field : in Fields;
Value : in Util.Beans.Objects.Object);
-- Adding a second function/procedure as generic parameter makes the
-- Vector_Mapper generic package fail to instantiate a valid package.
-- The failure occurs in Vector_Mapper in the 'with package Element_Mapper' instantiation.
--
-- with function Get_Member (From : in Element_Type;
-- Field : in Fields) return Util.Beans.Objects.Object;
package Util.Serialize.Mappers.Record_Mapper is
type Get_Member_Access is
access function (From : in Element_Type;
Field : in Fields) return Util.Beans.Objects.Object;
-- Procedure to give access to the <b>Element_Type</b> object from the context.
type Process_Object is not null
access procedure (Ctx : in out Util.Serialize.Contexts.Context'Class;
Attr : in Mapping'Class;
Value : in Util.Beans.Objects.Object;
Process : not null
access procedure (Attr : in Mapping'Class;
Item : in out Element_Type;
Value : in Util.Beans.Objects.Object));
type Proxy_Object is not null
access procedure (Attr : in Mapping'Class;
Element : in out Element_Type;
Value : in Util.Beans.Objects.Object);
-- Set the attribute member described by the <b>Attr</b> mapping
-- into the value passed in <b>Element</b>. This operation will call
-- the package parameter function of the same name.
procedure Set_Member (Attr : in Mapping'Class;
Element : in out Element_Type;
Value : in Util.Beans.Objects.Object);
-- -----------------------
-- Data context
-- -----------------------
-- Data context to get access to the target element.
type Element_Data is new Util.Serialize.Contexts.Data with private;
type Element_Data_Access is access all Element_Data'Class;
-- Get the element object.
function Get_Element (Data : in Element_Data) return Element_Type_Access;
-- Set the element object. When <b>Release</b> is set, the element <b>Element</b>
-- will be freed when the reader context is deleted (by <b>Finalize</b>).
procedure Set_Element (Data : in out Element_Data;
Element : in Element_Type_Access;
Release : in Boolean := False);
-- Finalize the object when it is removed from the reader context.
-- If the <b>Release</b> parameter was set, the target element will be freed.
overriding
procedure Finalize (Data : in out Element_Data);
-- -----------------------
-- Record mapper
-- -----------------------
type Mapper is new Util.Serialize.Mappers.Mapper with private;
type Mapper_Access is access all Mapper'Class;
-- Execute the mapping operation on the object associated with the current context.
-- The object is extracted from the context and the <b>Execute</b> operation is called.
procedure Execute (Handler : in Mapper;
Map : in Mapping'Class;
Ctx : in out Util.Serialize.Contexts.Context'Class;
Value : in Util.Beans.Objects.Object);
-- Add a mapping for setting a member. When the attribute rule defined by <b>Path</b>
-- is matched, the <b>Set_Member</b> procedure will be called with the value and the
-- <b>Field</b> identification.
procedure Add_Mapping (Into : in out Mapper;
Path : in String;
Field : in Fields);
-- Add a mapping associated with the path and described by a mapper object.
-- The <b>Proxy</b> procedure is in charge of giving access to the target
-- object used by the <b>Map</b> mapper.
procedure Add_Mapping (Into : in out Mapper;
Path : in String;
Map : in Util.Serialize.Mappers.Mapper_Access;
Proxy : in Proxy_Object);
-- Clone the <b>Handler</b> instance and get a copy of that single object.
overriding
function Clone (Handler : in Mapper) return Util.Serialize.Mappers.Mapper_Access;
--
procedure Bind (Into : in out Mapper;
Getter : in Get_Member_Access);
procedure Bind (Into : in out Mapper;
From : in Mapper_Access);
function Get_Getter (From : in Mapper) return Get_Member_Access;
-- Set the element in the context. When <b>Release</b> is set, the element <b>Element</b>
-- will be freed when the reader context is deleted (by <b>Finalize</b>).
procedure Set_Context (Ctx : in out Util.Serialize.Contexts.Context'Class;
Element : in Element_Type_Access;
Release : in Boolean := False);
-- Build a default mapping based on the <b>Fields</b> enumeration.
-- The enumeration name is used for the mapping name with the optional <b>FIELD_</b>
-- prefix stripped.
procedure Add_Default_Mapping (Into : in out Mapper);
-- Write the element on the stream using the mapper description.
procedure Write (Handler : in Mapper;
Stream : in out Util.Serialize.IO.Output_Stream'Class;
Element : in Element_Type);
-- Write the element on the stream using the mapper description.
procedure Write (Handler : in Util.Serialize.Mappers.Mapper'Class;
Getter : in Get_Member_Access;
Stream : in out Util.Serialize.IO.Output_Stream'Class;
Element : in Element_Type);
private
type Element_Data is new Util.Serialize.Contexts.Data with record
Element : Element_Type_Access;
Release : Boolean;
end record;
type Mapper is new Util.Serialize.Mappers.Mapper with record
Execute : Proxy_Object := Set_Member'Access;
Get_Member : Get_Member_Access;
end record;
type Attribute_Mapping is new Mapping with record
Index : Fields;
end record;
type Attribute_Mapping_Access is access all Attribute_Mapping'Class;
procedure Set_Member (Attr : in Attribute_Mapping;
Element : in out Element_Type;
Value : in Util.Beans.Objects.Object);
type Proxy_Mapper is new Mapper with null record;
type Proxy_Mapper_Access is access all Proxy_Mapper'Class;
-- Find the mapper associated with the given name.
-- Returns null if there is no mapper.
overriding
function Find_Mapper (Controller : in Proxy_Mapper;
Name : in String;
Attribute : in Boolean := False)
return Util.Serialize.Mappers.Mapper_Access;
end Util.Serialize.Mappers.Record_Mapper;
|
-----------------------------------------------------------------------
-- Util.Serialize.Mappers.Record_Mapper -- Mapper for record types
-- Copyright (C) 2010, 2011, 2012 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Beans.Objects;
with Util.Serialize.IO;
generic
type Element_Type (<>) is limited private;
type Element_Type_Access is access all Element_Type;
type Fields is (<>);
-- The <b>Set_Member</b> procedure will be called by the mapper when a mapping associated
-- with <b>Field</b> is recognized. The <b>Value</b> holds the value that was extracted
-- according to the mapping. The <b>Set_Member</b> procedure should save in the target
-- object <b>Into</b> the value. If an error is detected, the procedure can raise the
-- <b>Util.Serialize.Mappers.Field_Error</b> exception. The exception message will be
-- reported by the IO reader as an error.
with procedure Set_Member (Into : in out Element_Type;
Field : in Fields;
Value : in Util.Beans.Objects.Object);
-- Adding a second function/procedure as generic parameter makes the
-- Vector_Mapper generic package fail to instantiate a valid package.
-- The failure occurs in Vector_Mapper in the 'with package Element_Mapper' instantiation.
--
-- with function Get_Member (From : in Element_Type;
-- Field : in Fields) return Util.Beans.Objects.Object;
package Util.Serialize.Mappers.Record_Mapper is
type Get_Member_Access is
access function (From : in Element_Type;
Field : in Fields) return Util.Beans.Objects.Object;
-- Procedure to give access to the <b>Element_Type</b> object from the context.
type Process_Object is not null
access procedure (Ctx : in out Util.Serialize.Contexts.Context'Class;
Attr : in Mapping'Class;
Value : in Util.Beans.Objects.Object;
Process : not null
access procedure (Attr : in Mapping'Class;
Item : in out Element_Type;
Value : in Util.Beans.Objects.Object));
type Proxy_Object is not null
access procedure (Attr : in Mapping'Class;
Element : in out Element_Type;
Value : in Util.Beans.Objects.Object);
-- Set the attribute member described by the <b>Attr</b> mapping
-- into the value passed in <b>Element</b>. This operation will call
-- the package parameter function of the same name.
procedure Set_Member (Attr : in Mapping'Class;
Element : in out Element_Type;
Value : in Util.Beans.Objects.Object);
-- -----------------------
-- Data context
-- -----------------------
-- Data context to get access to the target element.
type Element_Data is new Util.Serialize.Contexts.Data with private;
type Element_Data_Access is access all Element_Data'Class;
-- Get the element object.
function Get_Element (Data : in Element_Data) return Element_Type_Access;
-- Set the element object. When <b>Release</b> is set, the element <b>Element</b>
-- will be freed when the reader context is deleted (by <b>Finalize</b>).
procedure Set_Element (Data : in out Element_Data;
Element : in Element_Type_Access;
Release : in Boolean := False);
-- Finalize the object when it is removed from the reader context.
-- If the <b>Release</b> parameter was set, the target element will be freed.
overriding
procedure Finalize (Data : in out Element_Data);
-- -----------------------
-- Record mapper
-- -----------------------
type Mapper is new Util.Serialize.Mappers.Mapper with private;
type Mapper_Access is access all Mapper'Class;
-- Execute the mapping operation on the object associated with the current context.
-- The object is extracted from the context and the <b>Execute</b> operation is called.
procedure Execute (Handler : in Mapper;
Map : in Mapping'Class;
Ctx : in out Util.Serialize.Contexts.Context'Class;
Value : in Util.Beans.Objects.Object);
-- Add a mapping for setting a member. When the attribute rule defined by <b>Path</b>
-- is matched, the <b>Set_Member</b> procedure will be called with the value and the
-- <b>Field</b> identification.
procedure Add_Mapping (Into : in out Mapper;
Path : in String;
Field : in Fields);
-- Add a mapping associated with the path and described by a mapper object.
-- The <b>Proxy</b> procedure is in charge of giving access to the target
-- object used by the <b>Map</b> mapper.
procedure Add_Mapping (Into : in out Mapper;
Path : in String;
Map : in Util.Serialize.Mappers.Mapper_Access;
Proxy : in Proxy_Object);
-- Clone the <b>Handler</b> instance and get a copy of that single object.
overriding
function Clone (Handler : in Mapper) return Util.Serialize.Mappers.Mapper_Access;
--
procedure Bind (Into : in out Mapper;
Getter : in Get_Member_Access);
procedure Bind (Into : in out Mapper;
From : in Mapper_Access);
function Get_Getter (From : in Mapper) return Get_Member_Access;
-- Set the element in the context. When <b>Release</b> is set, the element <b>Element</b>
-- will be freed when the reader context is deleted (by <b>Finalize</b>).
procedure Set_Context (Ctx : in out Util.Serialize.Contexts.Context'Class;
Element : in Element_Type_Access;
Release : in Boolean := False);
-- Build a default mapping based on the <b>Fields</b> enumeration.
-- The enumeration name is used for the mapping name with the optional <b>FIELD_</b>
-- prefix stripped.
procedure Add_Default_Mapping (Into : in out Mapper);
-- Write the element on the stream using the mapper description.
procedure Write (Handler : in Mapper;
Stream : in out Util.Serialize.IO.Output_Stream'Class;
Element : in Element_Type);
-- Write the element on the stream using the mapper description.
procedure Write (Handler : in Util.Serialize.Mappers.Mapper'Class;
Getter : in Get_Member_Access;
Stream : in out Util.Serialize.IO.Output_Stream'Class;
Element : in Element_Type);
private
type Element_Data is new Util.Serialize.Contexts.Data with record
Element : Element_Type_Access;
Release : Boolean;
end record;
type Mapper is new Util.Serialize.Mappers.Mapper with record
Execute : Proxy_Object := Set_Member'Access;
Get_Member : Get_Member_Access;
end record;
type Attribute_Mapping is new Mapping with record
Index : Fields;
end record;
type Attribute_Mapping_Access is access all Attribute_Mapping'Class;
procedure Set_Member (Attr : in Attribute_Mapping;
Element : in out Element_Type;
Value : in Util.Beans.Objects.Object);
type Proxy_Mapper is new Mapper with null record;
type Proxy_Mapper_Access is access all Proxy_Mapper'Class;
-- Find the mapper associated with the given name.
-- Returns null if there is no mapper.
overriding
function Find_Mapper (Controller : in Proxy_Mapper;
Name : in String;
Attribute : in Boolean := False)
return Util.Serialize.Mappers.Mapper_Access;
end Util.Serialize.Mappers.Record_Mapper;
|
Fix header
|
Fix header
|
Ada
|
apache-2.0
|
flottokarotto/ada-util,Letractively/ada-util,flottokarotto/ada-util,Letractively/ada-util
|
1e9f773279eb4ffb37ff960027b3727a3fec1a36
|
mat/regtests/mat-targets-tests.adb
|
mat/regtests/mat-targets-tests.adb
|
-----------------------------------------------------------------------
-- mat-readers-tests -- Unit tests for MAT readers
-- Copyright (C) 2014 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Directories;
with Util.Test_Caller;
with MAT.Readers.Files;
package body MAT.Targets.Tests is
use Util.Tests;
package Caller is new Util.Test_Caller (Test, "Files");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test MAT.Targets.Read_File",
Test_Read_File'Access);
end Add_Tests;
-- ------------------------------
-- Test reading a file into a string
-- Reads this ada source file and checks we have read it correctly
-- ------------------------------
procedure Test_Read_File (T : in out Test) is
Path : constant String := Util.Tests.Get_Test_Path ("regtests/files/file-v1.dat");
Target : MAT.Targets.Target_Type;
Reader : MAT.Readers.Files.File_Reader_Type;
begin
Target.Initialize (Reader);
Reader.Open (Path);
Reader.Read_All;
end Test_Read_File;
end MAT.Targets.Tests;
|
Implement a simple unit test for MAT.Targets package
|
Implement a simple unit test for MAT.Targets package
|
Ada
|
apache-2.0
|
stcarrez/mat,stcarrez/mat,stcarrez/mat
|
|
ad5b7a1b117d1cc2161866b1a571986d98a5d698
|
tools/druss-commands-ping.adb
|
tools/druss-commands-ping.adb
|
-----------------------------------------------------------------------
-- druss-commands-devices -- Print information about the devices
-- Copyright (C) 2017 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Properties;
with Bbox.API;
with Druss.Gateways;
with Ada.Strings.Unbounded;
package body Druss.Commands.Ping is
use Ada.Strings.Unbounded;
-- ------------------------------
-- Execute the wifi 'status' command to print the Wifi current status.
-- ------------------------------
procedure Do_Ping (Command : in Command_Type;
Args : in Argument_List'Class;
Context : in out Context_Type) is
pragma Unreferenced (Command);
Console : constant Druss.Commands.Consoles.Console_Access := Context.Console;
procedure Box_Status (Gateway : in out Druss.Gateways.Gateway_Type) is
Box : Bbox.API.Client_Type;
procedure Ping_Device (Manager : in Util.Properties.Manager;
Name : in String) is
Link : constant String := Manager.Get (Name & ".link", "");
Id : constant String := Manager.Get (Name & ".id", "");
begin
if Manager.Get (Name & ".active", "") = "0" then
return;
end if;
Box.Post ("hosts/" & Id, "action=ping");
end Ping_Device;
begin
if Ada.Strings.Unbounded.Length (Gateway.Passwd) = 0 then
return;
end if;
Gateway.Refresh;
Box.Set_Server (To_String (Gateway.IP));
Box.Login (To_String (Gateway.Passwd));
Bbox.API.Iterate (Gateway.Hosts, "hosts.list", Ping_Device'Access);
end Box_Status;
begin
Console.Start_Title;
Console.Print_Title (F_BBOX_IP_ADDR, "Bbox IP", 16);
Console.Print_Title (F_IP_ADDR, "Device IP", 16);
Console.Print_Title (F_ETHERNET, "Ethernet", 20);
Console.Print_Title (F_HOSTNAME, "Hostname", 28);
Console.Print_Title (F_DEVTYPE, "Type", 6);
-- Console.Print_Title (F_ACTIVE, "Active", 8);
Console.Print_Title (F_LINK, "Link", 18);
Console.End_Title;
Druss.Gateways.Iterate (Context.Gateways, Gateways.ITER_ENABLE, Box_Status'Access);
end Do_Ping;
-- Execute a status command to report information about the Bbox.
overriding
procedure Execute (Command : in Command_Type;
Name : in String;
Args : in Argument_List'Class;
Context : in out Context_Type) is
pragma Unreferenced (Name);
begin
Command.Do_Ping (Args, Context);
end Execute;
-- Write the help associated with the command.
overriding
procedure Help (Command : in Command_Type;
Context : in out Context_Type) is
pragma Unreferenced (Command);
Console : constant Druss.Commands.Consoles.Console_Access := Context.Console;
begin
Console.Notice (N_HELP, "devices: Print information about the devices");
Console.Notice (N_HELP, "Usage: devices [options]");
Console.Notice (N_HELP, "");
end Help;
end Druss.Commands.Ping;
|
Implement the ping command to ask the bbox to ping the known devices
|
Implement the ping command to ask the bbox to ping the known devices
|
Ada
|
apache-2.0
|
stcarrez/bbox-ada-api
|
|
d80ad0f06e04a8996259c2c0cdf0726920612453
|
src/util-beans-objects-maps.ads
|
src/util-beans-objects-maps.ads
|
-----------------------------------------------------------------------
-- Util.Beans.Objects.Maps -- Object maps
-- Copyright (C) 2010 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 Ada.Containers.Hashed_Maps;
with Ada.Strings.Unbounded.Hash;
package Util.Beans.Objects.Maps is new
Ada.Containers.Hashed_Maps (Key_Type => Unbounded_String,
Element_Type => Object,
Hash => Ada.Strings.Unbounded.Hash,
Equivalent_Keys => "=");
|
Integrate the EL.Objects, EL.Beans framework from Ada EL (See http://code.google.com/p/ada-el/) - Integrate the object map
|
Integrate the EL.Objects, EL.Beans framework from Ada EL
(See http://code.google.com/p/ada-el/)
- Integrate the object map
|
Ada
|
apache-2.0
|
flottokarotto/ada-util,Letractively/ada-util,flottokarotto/ada-util,Letractively/ada-util
|
|
44ea12be3279eec8f48675c0ecadac4db909c9f6
|
src/util-concurrent-arrays.ads
|
src/util-concurrent-arrays.ads
|
-----------------------------------------------------------------------
-- Util.Concurrent.Arrays -- Concurrent Arrays
-- Copyright (C) 2012 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Finalization;
with Util.Concurrent.Counters;
-- The <b>Util.Concurrent.Vectors</b> generic package defines a vector which provides a
-- concurrent read only access and a protected exclusive write access. This implementation
-- is intended to be used in applications that have to frequently iterate over the vector
-- content. Adding or removing elements in the vector is assumed to be a not so frequent
-- operation. Based on these assumptions, updating the vector array is implemented by
-- using the <tt>copy on write</tt> design pattern. Read access is provided through a
-- reference object that can be shared by multiple readers.
--
-- The vector instance is declared and elements are added as follows:
--
-- C : Vector;
--
-- C.Append (E1);
--
-- To read and iterate over the vector, a task will get a reference to the vector array
-- and it will iterate over it. The reference will be held until the reference object is
-- finalized. While doing so, if another task updates the vector, a new vector array will
-- be associated with the vector instance (but this will not change the reader's references).
--
-- R : Ref := C.Get;
--
-- R.Iterate (Process'Access);
-- ...
-- R.Iterate (Process'Access);
--
-- In the above example, the two <b>Iterate</b> operations will iterate over the same list of
-- elements, even if another task appends an element in the middle.
--
-- Notes:
-- o This package is close to the Java class <tt>java.util.concurrent.CopyOnWriteArrayList</tt>.
-- o The package implements voluntarily a very small subset of Ada.Containers.Vectors.
-- o The implementation does not use the Ada container for performance and size reasons.
-- o The Iterate and Reverse_Iterate operation give a direct access to the element
generic
-- type Index_Type is range <>;
type Element_Type is private;
with function "=" (Left, Right : in Element_Type) return Boolean is <>;
package Util.Concurrent.Arrays is
-- The reference to the read-only vector elements.
type Ref is tagged private;
-- Returns True if the container is empty.
function Is_Empty (Container : in Ref) return Boolean;
-- Iterate over the vector elements and execute the <b>Process</b> procedure
-- with the element as parameter.
procedure Iterate (Container : in Ref;
Process : not null access procedure (Item : in Element_Type));
-- Iterate over the vector elements in reverse order and execute the <b>Process</b> procedure
-- with the element as parameter.
procedure Reverse_Iterate (Container : in Ref;
Process : not null access procedure (Item : in Element_Type));
-- Vector of elements.
type Vector is new Ada.Finalization.Limited_Controlled with private;
-- Get a read-only reference to the vector elements. The referenced vector will never
-- be modified.
function Get (Container : in Vector'Class) return Ref;
-- Append the element to the vector. The modification will not be visible to readers
-- until they call the <b>Get</b> function.
procedure Append (Container : in out Vector;
Item : in Element_Type);
-- Remove the element represented by <b>Item</b> from the vector. The modification will
-- not be visible to readers until they call the <b>Get</b> function.
procedure Remove (Container : in out Vector;
Item : in Element_Type);
-- Release the vector elements.
overriding
procedure Finalize (Object : in out Vector);
private
-- To store the vector elements, we use an array which is allocated dynamically.
-- The generated code is smaller compared to the use of Ada vectors container.
type Element_Array is array (Positive range <>) of Element_Type;
type Element_Array_Access is access all Element_Array;
Null_Element_Array : constant Element_Array_Access := null;
type Vector_Record (Len : Positive) is record
Ref_Counter : Util.Concurrent.Counters.Counter;
List : Element_Array (1 .. Len);
end record;
type Vector_Record_Access is access all Vector_Record;
type Ref is new Ada.Finalization.Controlled with record
Target : Vector_Record_Access := null;
end record;
-- Release the reference. Invoke <b>Finalize</b> and free the storage if it was
-- the last reference.
overriding
procedure Finalize (Obj : in out Ref);
-- Update the reference counter after an assignment.
overriding
procedure Adjust (Obj : in out Ref);
-- Vector of objects
protected type Protected_Vector is
-- Get a readonly reference to the vector.
function Get return Ref;
-- Append the element to the vector.
procedure Append (Item : in Element_Type);
-- Remove the element from the vector.
procedure Remove (Item : in Element_Type);
private
Elements : Ref;
-- Elements : Vector_Record_Access := null;
end Protected_Vector;
type Vector is new Ada.Finalization.Limited_Controlled with record
List : Protected_Vector;
end record;
end Util.Concurrent.Arrays;
|
-----------------------------------------------------------------------
-- Util.Concurrent.Arrays -- Concurrent Arrays
-- Copyright (C) 2012 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Finalization;
with Util.Concurrent.Counters;
-- == Introduction ==
-- The <b>Util.Concurrent.Arrays</b> generic package defines an array which provides a
-- concurrent read only access and a protected exclusive write access. This implementation
-- is intended to be used in applications that have to frequently iterate over the array
-- content. Adding or removing elements in the array is assumed to be a not so frequent
-- operation. Based on these assumptions, updating the array is implemented by
-- using the <tt>copy on write</tt> design pattern. Read access is provided through a
-- reference object that can be shared by multiple readers.
--
-- == Declaration ==
-- The package must be instantiated using the element type representing the array element.
--
-- package My_Array is new Util.Concurrent.Arrays (Element_Type => Integer);
--
-- == Adding Elements ==
-- The vector instance is declared and elements are added as follows:
--
-- C : My_Array.Vector;
--
-- C.Append (E1);
--
-- == Iterating over the array ==
-- To read and iterate over the vector, a task will get a reference to the vector array
-- and it will iterate over it. The reference will be held until the reference object is
-- finalized. While doing so, if another task updates the vector, a new vector array will
-- be associated with the vector instance (but this will not change the reader's references).
--
-- R : My_Array.Ref := C.Get;
--
-- R.Iterate (Process'Access);
-- ...
-- R.Iterate (Process'Access);
--
-- In the above example, the two `Iterate` operations will iterate over the same list of
-- elements, even if another task appends an element in the middle.
--
-- Notes:
-- * This package is close to the Java class `java.util.concurrent.CopyOnWriteArrayList`.
-- * The package implements voluntarily a very small subset of `Ada.Containers.Vectors`.
-- * The implementation does not use the Ada container for performance and size reasons.
-- * The `Iterate` and `Reverse_Iterate` operation give a direct access to the element.
generic
type Element_Type is private;
with function "=" (Left, Right : in Element_Type) return Boolean is <>;
package Util.Concurrent.Arrays is
-- The reference to the read-only vector elements.
type Ref is tagged private;
-- Returns True if the container is empty.
function Is_Empty (Container : in Ref) return Boolean;
-- Iterate over the vector elements and execute the <b>Process</b> procedure
-- with the element as parameter.
procedure Iterate (Container : in Ref;
Process : not null access procedure (Item : in Element_Type));
-- Iterate over the vector elements in reverse order and execute the <b>Process</b> procedure
-- with the element as parameter.
procedure Reverse_Iterate (Container : in Ref;
Process : not null access procedure (Item : in Element_Type));
-- Vector of elements.
type Vector is new Ada.Finalization.Limited_Controlled with private;
-- Get a read-only reference to the vector elements. The referenced vector will never
-- be modified.
function Get (Container : in Vector'Class) return Ref;
-- Append the element to the vector. The modification will not be visible to readers
-- until they call the <b>Get</b> function.
procedure Append (Container : in out Vector;
Item : in Element_Type);
-- Remove the element represented by <b>Item</b> from the vector. The modification will
-- not be visible to readers until they call the <b>Get</b> function.
procedure Remove (Container : in out Vector;
Item : in Element_Type);
-- Release the vector elements.
overriding
procedure Finalize (Object : in out Vector);
private
-- To store the vector elements, we use an array which is allocated dynamically.
-- The generated code is smaller compared to the use of Ada vectors container.
type Element_Array is array (Positive range <>) of Element_Type;
type Element_Array_Access is access all Element_Array;
Null_Element_Array : constant Element_Array_Access := null;
type Vector_Record (Len : Positive) is record
Ref_Counter : Util.Concurrent.Counters.Counter;
List : Element_Array (1 .. Len);
end record;
type Vector_Record_Access is access all Vector_Record;
type Ref is new Ada.Finalization.Controlled with record
Target : Vector_Record_Access := null;
end record;
-- Release the reference. Invoke <b>Finalize</b> and free the storage if it was
-- the last reference.
overriding
procedure Finalize (Obj : in out Ref);
-- Update the reference counter after an assignment.
overriding
procedure Adjust (Obj : in out Ref);
-- Vector of objects
protected type Protected_Vector is
-- Get a readonly reference to the vector.
function Get return Ref;
-- Append the element to the vector.
procedure Append (Item : in Element_Type);
-- Remove the element from the vector.
procedure Remove (Item : in Element_Type);
private
Elements : Ref;
end Protected_Vector;
type Vector is new Ada.Finalization.Limited_Controlled with record
List : Protected_Vector;
end record;
end Util.Concurrent.Arrays;
|
Update the documentation to be extracted by dynamo
|
Update the documentation to be extracted by dynamo
|
Ada
|
apache-2.0
|
flottokarotto/ada-util,flottokarotto/ada-util,Letractively/ada-util,Letractively/ada-util
|
6d46fe25a57086cd13356b1009cf020499952c38
|
src/base/log/util-log-appenders-rolling_files.adb
|
src/base/log/util-log-appenders-rolling_files.adb
|
-----------------------------------------------------------------------
-- util-log-appenders-rolling_files -- Rolling file log appenders
-- Copyright (C) 2001 - 2021 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Finalization;
with Ada.Directories;
with Util.Properties.Basic;
with Util.Log.Appenders.Formatter;
package body Util.Log.Appenders.Rolling_Files is
use Ada;
use Ada.Finalization;
package Bool_Prop renames Util.Properties.Basic.Boolean_Property;
package Int_Prop renames Util.Properties.Basic.Integer_Property;
-- ------------------------------
-- Finalize the referenced object. This is called before the object is freed.
-- ------------------------------
overriding
procedure Finalize (Object : in out File_Entity) is
begin
Text_IO.Close (File => Object.Output);
end Finalize;
protected body Rolling_File is
procedure Initialize (Name : in String;
Base : in String;
Properties : in Util.Properties.Manager) is
function Get_Policy return Util.Files.Rolling.Policy_Type with Inline;
function Get_Strategy return Util.Files.Rolling.Strategy_Type with Inline;
File : constant String := Properties.Get (Base & ".fileName", Name & ".log");
Pat : constant String := Properties.Get (Base & ".filePattern", Base & "-%i.log");
function Get_Policy return Util.Files.Rolling.Policy_Type is
Str : constant String := Properties.Get (Base & ".policy", "time");
Inter : constant Integer := Int_Prop.Get (Properties, Base & ".policyInterval", 1);
Size : constant String := Properties.Get (Base & ".minSize", "1000000");
begin
if Str = "none" then
return (Kind => Util.Files.Rolling.No_Policy);
elsif Str = "time" then
return (Kind => Util.Files.Rolling.Time_Policy,
Interval => Inter);
else
return (Kind => Util.Files.Rolling.Size_Policy,
Size => Ada.Directories.File_Size'Value (Size));
end if;
exception
when others =>
return (Kind => Util.Files.Rolling.No_Policy);
end Get_Policy;
function Get_Strategy return Util.Files.Rolling.Strategy_Type is
Str : constant String := Properties.Get (Base & ".strategy", "ascending");
Min : constant Integer := Int_Prop.Get (Properties, Base & ".policyMin", 0);
Max : constant Integer := Int_Prop.Get (Properties, Base & ".policyMax", 0);
begin
if Str = "direct" then
return (Kind => Util.Files.Rolling.Direct_Strategy,
Max_Files => Max);
elsif Str = "descending" then
return (Kind => Util.Files.Rolling.Descending_Strategy,
Min_Index => Min,
Max_Index => Max);
else
return (Kind => Util.Files.Rolling.Ascending_Strategy,
Min_Index => Min,
Max_Index => Max);
end if;
end Get_Strategy;
begin
Append := Bool_Prop.Get (Properties, Base & ".append", True);
Manager.Initialize (Path => File,
Pattern => Pat,
Policy => Get_Policy,
Strategy => Get_Strategy);
end Initialize;
procedure Openlog (File : out File_Refs.Ref) is
begin
if not Manager.Is_Rollover_Necessary then
File := Current;
return;
end if;
Closelog;
Current := File_Refs.Create;
Manager.Rollover;
declare
Path : constant String := Manager.Get_Current_Path;
Dir : constant String := Ada.Directories.Containing_Directory (Path);
begin
if not Ada.Directories.Exists (Dir) then
Ada.Directories.Create_Path (Dir);
end if;
if not Ada.Directories.Exists (Path) then
Text_IO.Create (File => Current.Value.Output,
Name => Path);
else
Text_IO.Open (File => Current.Value.Output,
Name => Path,
Mode => (if Append then Text_IO.Append_File
else Text_IO.Out_File));
end if;
end;
end Openlog;
procedure Flush (File : out File_Refs.Ref) is
begin
if not Current.Is_Null then
File := Current;
end if;
end Flush;
procedure Closelog is
Empty : File_Refs.Ref;
begin
-- Close the current log by releasing its reference counter.
Current := Empty;
end Closelog;
end Rolling_File;
overriding
procedure Append (Self : in out File_Appender;
Message : in Util.Strings.Builders.Builder;
Date : in Ada.Calendar.Time;
Level : in Level_Type;
Logger : in String) is
begin
if Self.Level >= Level then
declare
File : File_Refs.Ref;
procedure Write_File (Data : in String) with Inline_Always;
procedure Write_File (Data : in String) is
begin
Text_IO.Put (File.Value.Output, Data);
end Write_File;
procedure Write is new Formatter (Write_File);
begin
Self.File.Openlog (File);
if not File.Is_Null then
Write (Self, Message, Date, Level, Logger);
Text_IO.New_Line (File.Value.Output);
if Self.Immediate_Flush then
Text_IO.Flush (File.Value.Output);
end if;
end if;
end;
end if;
end Append;
-- ------------------------------
-- Flush the log events.
-- ------------------------------
overriding
procedure Flush (Self : in out File_Appender) is
File : File_Refs.Ref;
begin
Self.File.Flush (File);
if not File.Is_Null then
Text_IO.Flush (File.Value.Output);
end if;
end Flush;
-- ------------------------------
-- Flush and close the file.
-- ------------------------------
overriding
procedure Finalize (Self : in out File_Appender) is
begin
Self.File.Closelog;
end Finalize;
-- ------------------------------
-- Create a file appender and configure it according to the properties
-- ------------------------------
function Create (Name : in String;
Properties : in Util.Properties.Manager;
Default : in Level_Type)
return Appender_Access is
Base : constant String := "appender." & Name;
Result : constant File_Appender_Access
:= new File_Appender '(Limited_Controlled with Length => Name'Length,
Name => Name,
others => <>);
begin
Result.Set_Level (Name, Properties, Default);
Result.Set_Layout (Name, Properties, FULL);
Result.Immediate_Flush := Bool_Prop.Get (Properties, Base & ".immediateFlush", True);
Result.File.Initialize (Name, Base, Properties);
return Result.all'Access;
end Create;
end Util.Log.Appenders.Rolling_Files;
|
Add support for rolling file appender
|
Add support for rolling file appender
|
Ada
|
apache-2.0
|
stcarrez/ada-util,stcarrez/ada-util
|
|
ed82d743c8f601467a6253dc344f98cfcead9aa9
|
regtests/dlls/util-systems-dlls-tests.adb
|
regtests/dlls/util-systems-dlls-tests.adb
|
-----------------------------------------------------------------------
-- util-systems-dlls-tests -- Unit tests for shared libraries
-- Copyright (C) 2013 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Test_Caller;
with Util.Systems.Os;
package body Util.Systems.DLLs.Tests is
use Util.Tests;
use type System.Address;
function Get_Test_Library return String;
function Get_Test_Symbol return String;
package Caller is new Util.Test_Caller (Test, "Systems.Dlls");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test Util.Systems.Dlls.Load",
Test_Load'Access);
Caller.Add_Test (Suite, "Test Util.Systems.Dlls.Get_Symbol",
Test_Get_Symbol'Access);
end Add_Tests;
function Get_Test_Library return String is
begin
if Util.Systems.Os.Directory_Separator = '/' then
return "libcrypto.so";
else
return "libz.dll";
end if;
end Get_Test_Library;
function Get_Test_Symbol return String is
begin
if Util.Systems.Os.Directory_Separator = '/' then
return "inflate";
else
return "compress";
end if;
end Get_Test_Symbol;
-- ------------------------------
-- Test the loading a shared library.
-- ------------------------------
procedure Test_Load (T : in out Test) is
Lib : Handle;
begin
Lib := Util.Systems.DLLs.Load (Get_Test_Library);
T.Assert (Lib /= Null_Handle, "Load operation returned null");
begin
Lib := Util.Systems.DLLs.Load ("some-invalid-library");
T.Fail ("Load must raise an exception");
exception
when Load_Error =>
null;
end;
end Test_Load;
-- ------------------------------
-- Test getting a shared library symbol.
-- ------------------------------
procedure Test_Get_Symbol (T : in out Test) is
Lib : Handle;
Sym : System.Address;
begin
Lib := Util.Systems.DLLs.Load (Get_Test_Library);
T.Assert (Lib /= Null_Handle, "Load operation returned null");
Sym := Util.Systems.DLLs.Get_Symbol (Lib, Get_Test_Symbol);
T.Assert (Sym /= System.Null_Address, "Get_Symbol returned null");
begin
Sym := Util.Systems.DLLs.Get_Symbol (Lib, "some-invalid-symbol");
T.Fail ("The Get_Symbol operation must raise an exception");
exception
when Not_Found =>
null;
end;
end Test_Get_Symbol;
end Util.Systems.DLLs.Tests;
|
-----------------------------------------------------------------------
-- util-systems-dlls-tests -- Unit tests for shared libraries
-- Copyright (C) 2013 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Test_Caller;
with Util.Systems.Os;
package body Util.Systems.DLLs.Tests is
use Util.Tests;
use type System.Address;
function Get_Test_Library return String;
function Get_Test_Symbol return String;
package Caller is new Util.Test_Caller (Test, "Systems.Dlls");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test Util.Systems.Dlls.Load",
Test_Load'Access);
Caller.Add_Test (Suite, "Test Util.Systems.Dlls.Get_Symbol",
Test_Get_Symbol'Access);
end Add_Tests;
function Get_Test_Library return String is
begin
if Util.Systems.Os.Directory_Separator = '/' then
return "libcrypto.so";
else
return "libz.dll";
end if;
end Get_Test_Library;
function Get_Test_Symbol return String is
begin
if Util.Systems.Os.Directory_Separator = '/' then
return "EVP_sha";
else
return "compress";
end if;
end Get_Test_Symbol;
-- ------------------------------
-- Test the loading a shared library.
-- ------------------------------
procedure Test_Load (T : in out Test) is
Lib : Handle;
begin
Lib := Util.Systems.DLLs.Load (Get_Test_Library);
T.Assert (Lib /= Null_Handle, "Load operation returned null");
begin
Lib := Util.Systems.DLLs.Load ("some-invalid-library");
T.Fail ("Load must raise an exception");
exception
when Load_Error =>
null;
end;
end Test_Load;
-- ------------------------------
-- Test getting a shared library symbol.
-- ------------------------------
procedure Test_Get_Symbol (T : in out Test) is
Lib : Handle;
Sym : System.Address;
begin
Lib := Util.Systems.DLLs.Load (Get_Test_Library);
T.Assert (Lib /= Null_Handle, "Load operation returned null");
Sym := Util.Systems.DLLs.Get_Symbol (Lib, Get_Test_Symbol);
T.Assert (Sym /= System.Null_Address, "Get_Symbol returned null");
begin
Sym := Util.Systems.DLLs.Get_Symbol (Lib, "some-invalid-symbol");
T.Fail ("The Get_Symbol operation must raise an exception");
exception
when Not_Found =>
null;
end;
end Test_Get_Symbol;
end Util.Systems.DLLs.Tests;
|
Change the symbol name to use a symbol that hopefully exists in almost all installation of libcrypto on Unix
|
Change the symbol name to use a symbol that hopefully exists in almost all installation of libcrypto on Unix
|
Ada
|
apache-2.0
|
Letractively/ada-util,flottokarotto/ada-util,flottokarotto/ada-util,Letractively/ada-util
|
f3d0cd715516dfc5aa8eb80bbc046487401693b6
|
regtests/util-events-timers-tests.ads
|
regtests/util-events-timers-tests.ads
|
-----------------------------------------------------------------------
-- util-events-timers-tests -- Unit tests for timers
-- Copyright (C) 2017 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Tests;
package Util.Events.Timers.Tests is
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite);
type Test is new Util.Tests.Test
and Util.Events.Timers.Timer with record
Count : Natural := 0;
end record;
overriding
procedure Time_Handler (Sub : in out Test;
Event : in out Timer_Ref'Class);
procedure Test_Timer_Event (T : in out Test);
end Util.Events.Timers.Tests;
|
Add new unit tests for the timer management package
|
Add new unit tests for the timer management package
|
Ada
|
apache-2.0
|
stcarrez/ada-util,stcarrez/ada-util
|
|
1a38878bbd8541a4d274ca718a756dccf80dad5b
|
src/gnat/lib-list.adb
|
src/gnat/lib-list.adb
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- L I B . L I S T --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2009, 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. --
-- --
------------------------------------------------------------------------------
separate (Lib)
procedure List (File_Names_Only : Boolean := False) is
Num_Units : constant Nat := Int (Units.Last) - Int (Units.First) + 1;
-- Number of units in file table
Sorted_Units : Unit_Ref_Table (1 .. Num_Units);
-- Table of unit numbers that we will sort
Unit_Hed : constant String := "Unit name ";
Unit_Und : constant String := "--------- ";
Unit_Bln : constant String := " ";
File_Hed : constant String := "File name ";
File_Und : constant String := "--------- ";
File_Bln : constant String := " ";
Time_Hed : constant String := "Time stamp";
Time_Und : constant String := "----------";
Unit_Length : constant Natural := Unit_Hed'Length;
File_Length : constant Natural := File_Hed'Length;
begin
-- First step is to make a sorted table of units
for J in 1 .. Num_Units loop
Sorted_Units (J) := Unit_Number_Type (Int (Units.First) + J - 1);
end loop;
Sort (Sorted_Units);
-- Now we can generate the unit table listing
Write_Eol;
if not File_Names_Only then
Write_Str (Unit_Hed);
Write_Str (File_Hed);
Write_Str (Time_Hed);
Write_Eol;
Write_Str (Unit_Und);
Write_Str (File_Und);
Write_Str (Time_Und);
Write_Eol;
Write_Eol;
end if;
for R in Sorted_Units'Range loop
if File_Names_Only then
if not Is_Internal_File_Name
(File_Name (Source_Index (Sorted_Units (R))))
then
Write_Name (Full_File_Name (Source_Index (Sorted_Units (R))));
Write_Eol;
end if;
else
Write_Unit_Name (Unit_Name (Sorted_Units (R)));
if Name_Len > (Unit_Length - 1) then
Write_Eol;
Write_Str (Unit_Bln);
else
for J in Name_Len + 1 .. Unit_Length loop
Write_Char (' ');
end loop;
end if;
Write_Name (Full_File_Name (Source_Index (Sorted_Units (R))));
if Name_Len > (File_Length - 1) then
Write_Eol;
Write_Str (Unit_Bln);
Write_Str (File_Bln);
else
for J in Name_Len + 1 .. File_Length loop
Write_Char (' ');
end loop;
end if;
Write_Str (String (Time_Stamp (Source_Index (Sorted_Units (R)))));
Write_Eol;
end if;
end loop;
Write_Eol;
end List;
|
Add GNAT files for ASIS
|
Add GNAT files for ASIS
|
Ada
|
apache-2.0
|
stcarrez/dynamo,stcarrez/dynamo,stcarrez/dynamo
|
|
abaf2324431a7be2780ba4618a34596dd46e0e10
|
src/security-auth-openid.ads
|
src/security-auth-openid.ads
|
-----------------------------------------------------------------------
-- security-openid -- OpenID 2.0 Support
-- Copyright (C) 2009, 2010, 2011, 2012 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.
-----------------------------------------------------------------------
-- == OpenID ==
-- The <b>Security.OpenID</b> package implements an authentication framework based
-- on OpenID 2.0.
--
-- See OpenID Authentication 2.0 - Final
-- http://openid.net/specs/openid-authentication-2_0.html
--
-- There are basically two steps that an application must implement:
--
-- * <b>Discovery</b>: to resolve and use the OpenID provider and redirect the user to the
-- provider authentication form.
-- * <b>Verify</b>: to decode the authentication and check its result.
--
-- [http://ada-security.googlecode.com/svn/wiki/OpenID.png]
--
-- The authentication process is the following:
--
-- * The application should redirect the user to the authentication URL.
-- * The OpenID provider authenticate the user and redirects the user to the callback CB.
-- * The association is decoded from the callback parameter.
-- * The <b>Verify</b> procedure is called with the association to check the result and
-- obtain the authentication results.
--
-- === Initialization ===
-- The initialization process must be done before each two steps (discovery and verify).
-- The OpenID manager must be declared and configured.
--
-- Mgr : Security.OpenID.Manager;
--
-- For the configuration, the <b>Initialize</b> procedure is called to configure
-- the OpenID realm and set the OpenID return callback URL. The return callback
-- must be a valid URL that is based on the realm. Example:
--
-- Mgr.Initialize (Name => "http://app.site.com/auth",
-- Return_To => "http://app.site.com/auth/verify");
--
-- After this initialization, the OpenID manager can be used in the authentication process.
--
-- === Discovery: creating the authentication URL ===
-- The first step is to create an authentication URL to which the user must be redirected.
-- In this step, we have to create an OpenID manager, discover the OpenID provider,
-- do the association and get an <b>End_Point</b>. The OpenID provider is specified as an
-- URL, below is an example for Google OpenID:
--
-- Provider : constant String := "https://www.google.com/accounts/o8/id";
-- OP : Security.OpenID.End_Point;
-- Assoc : constant Security.OpenID.Association_Access := new Security.OpenID.Association;
--
-- The following steps are performed:
--
-- * The <b>Discover</b> procedure is called to retrieve from the OpenID provider the XRDS
-- stream and identify the provider. An <b>End_Point</b> is returned in <tt>OP</tt>.
-- * The <b>Associate</b> procedure is called to make the association with the <b>End_Point</b>.
-- The <b>Association</b> record holds session, and authentication.
--
-- Mgr.Discover (Provider, OP); -- Yadis discovery (get the XRDS file).
-- Mgr.Associate (OP, Assoc.all);-- Associate and get an end-point with a key.
--
-- After this first step, you must manage to save the association in the HTTP session.
-- Then you must redirect to the authentication URL that is obtained by using:
--
-- Auth_URL : constant String := Mgr.Get_Authentication_URL (OP, Assoc.all);
--
-- === Verify: acknowledge the authentication in the callback URL ===
-- The second step is done when the user has finished the authentication successfully or not.
-- For this step, the application must get back the association that was saved in the session.
-- It must also prepare a parameters object that allows the OpenID framework to get the
-- URI parameters from the return callback.
--
-- Assoc : Association_Access := ...; -- Get the association saved in the session.
-- Auth : OpenID.Authentication;
-- Params : Auth_Params;
--
-- The OpenID manager must be initialized and the <b>Verify</b> procedure is called with
-- the association, parameters and the authentication result. The <b>Get_Status</b> function
-- must be used to check that the authentication succeeded.
--
-- Mgr.Verify (Assoc.all, Params, Auth);
-- if Security.OpenID.Get_Status (Auth) = Security.OpenID.AUTHENTICATED then ... -- Success.
--
-- === Principal creation ===
-- After the user is successfully authenticated, a user principal can be created and saved in
-- the session. The user principal can then be used to assign permissions to that user and
-- enforce the application permissions using the security policy manger.
--
-- P : Security.OpenID.Principal_Access := Security.OpenID.Create_Principal (Auth);
--
private package Security.Auth.OpenID is
-- ------------------------------
-- OpenID Manager
-- ------------------------------
-- The <b>Manager</b> provides the core operations for the OpenID process.
type Manager is new Security.Auth.Manager with private;
-- Initialize the authentication realm.
overriding
procedure Initialize (Realm : in out Manager;
Params : in Parameters'Class;
Provider : in String := PROVIDER_OPENID);
-- Discover the OpenID provider that must be used to authenticate the user.
-- The <b>Name</b> can be an URL or an alias that identifies the provider.
-- A cached OpenID provider can be returned.
-- Read the XRDS document from the URI and initialize the OpenID provider end point.
-- (See OpenID Section 7.3 Discovery)
overriding
procedure Discover (Realm : in out Manager;
Name : in String;
Result : out End_Point);
-- Associate the application (relying party) with the OpenID provider.
-- The association can be cached.
-- (See OpenID Section 8 Establishing Associations)
overriding
procedure Associate (Realm : in out Manager;
OP : in End_Point;
Result : out Association);
overriding
function Get_Authentication_URL (Realm : in Manager;
OP : in End_Point;
Assoc : in Association) return String;
-- Verify the authentication result
overriding
procedure Verify (Realm : in out Manager;
Assoc : in Association;
Request : in Parameters'Class;
Result : out Authentication);
-- Verify the authentication result
procedure Verify_Discovered (Realm : in out Manager;
Assoc : in Association;
Request : in Parameters'Class;
Result : out Authentication);
-- Verify the signature part of the result
procedure Verify_Signature (Realm : in Manager;
Assoc : in Association;
Request : in Parameters'Class;
Result : in out Authentication);
-- Extract from the XRDS content the OpenID provider URI.
-- The default implementation is very basic as it returns the first <URI>
-- available in the stream without validating the XRDS document.
-- Raises the <b>Invalid_End_Point</b> exception if the URI cannot be found.
procedure Extract_XRDS (Realm : in out Manager;
Content : in String;
Result : out End_Point);
private
type Manager is new Security.Auth.Manager with record
Return_To : Unbounded_String;
Realm : Unbounded_String;
end record;
end Security.Auth.OpenID;
|
Refactor the OpenID authentication to be based on the generic authentication framework
|
Refactor the OpenID authentication to be based on the generic authentication framework
|
Ada
|
apache-2.0
|
Letractively/ada-security
|
|
163d4c95d2b35f21824f62d17a7b2742a581716c
|
src/asis/a4g-vcheck.adb
|
src/asis/a4g-vcheck.adb
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . V C H E C K --
-- --
-- B o d y --
-- --
-- Copyright (C) 1995-2012, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adaccore.com). --
-- --
------------------------------------------------------------------------------
with Ada.Characters.Handling; use Ada.Characters.Handling;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with Asis.Compilation_Units; use Asis.Compilation_Units;
with Asis.Elements; use Asis.Elements;
with Asis.Exceptions; use Asis.Exceptions;
with Asis.Implementation; use Asis.Implementation;
with Asis.Set_Get; use Asis.Set_Get;
with Asis.Text.Set_Get; use Asis.Text.Set_Get;
with A4G.A_Debug; use A4G.A_Debug;
with A4G.A_Opt; use A4G.A_Opt;
with A4G.A_Output; use A4G.A_Output;
with Fname; use Fname;
with Gnatvsn; use Gnatvsn;
with Lib; use Lib;
with Namet; use Namet;
with Output; use Output;
with Sinput; use Sinput;
with Types; use Types;
package body A4G.Vcheck is
----------------
-- Local Data --
----------------
Recursion_Count : Natural := 0;
-- Used in Report_ASIS_Bug to prevent too many runaway recursion steps to
-- be done if something bad happens while reporting an ASIS bug. The
-- problem is that ASIS queries are used to form the diagnostic message,
-- and some circularities are possible here.
Max_Recursions_Allowed : constant Positive := 1;
-- This constant limits the number of recursion calls of Report_ASIS_Bug.
-- When this limit is achieved, we try once again, but with turning OFF
-- including the text position into Element's debug image. If this last
-- step also results in resursive call to Report_ASIS_Bug, we
-- unconditionally do OS_Abort.
--
-- Until we finish the revising of all the exception handlers in the
-- ASIS implementation code, we limit the recursion depth by one, because
-- some circularities are possible in the routines that are not "terminal"
-- ASIS queries but which make use of ASIS queries and contain exception
-- handlers forming or modifying diagnostic info.
LT : String renames A4G.A_Types.ASIS_Line_Terminator;
Current_Pos : Natural range 0 .. Diagnosis_String_Length;
-- The pointer to the last filled position in the logical text line
-- in the Diagnosis buffer
-----------------------
-- Local subprograms --
-----------------------
procedure Add_Str (Str : String);
-- This procedure is similar to Add, but it tries to keep the lengths
-- of strings stores in Diagnosis_Buffer under 76 characters. Str should
-- not contain any character(s) caused line breaks. If (a part of) the
-- argument can be added to the current Diagnosis string and if this string
-- already contains some text, (a part of) the argument is separated by a
-- space character.
procedure Close_Str;
-- Closes a current string in the Diagnosis buffer
procedure Reset_Diagnosis_Buffer;
-- Resets the Diagnosis buffer
-- ??? The diagnosis buffer needs a proper documentation!!!!
procedure Set_Error_Status_Internal
(Status : Error_Kinds := Not_An_Error;
Diagnosis : String := Nil_Asis_String;
Query : String := Nil_Asis_String);
-- This procedure allows to avoid dynamicaly allocated strings in calls
-- to Set_Error_Status in Check_Validity. Check_Validity is called in
-- all ASIS structural and semantic queries, so a dynamic string as an
-- argument of internal call results in significant performance penalties.
-- (See E705-008).
---------
-- Add --
---------
procedure Add (Phrase : String) is
begin
if Diagnosis_Len = Max_Diagnosis_Length then
return;
end if;
for I in Phrase'Range loop
Diagnosis_Len := Diagnosis_Len + 1;
Diagnosis_Buffer (Diagnosis_Len) := Phrase (I);
if Diagnosis_Len = Max_Diagnosis_Length then
exit;
end if;
end loop;
end Add;
-------------
-- Add_Str --
-------------
procedure Add_Str (Str : String) is
First_Idx : Natural := Str'First;
Last_Idx : Natural := First_Idx;
-- Indexes of the first and last subwords in Str
Word_Len : Positive;
Available : Positive;
Str_Last : constant Positive := Str'Last;
begin
while Last_Idx < Str_Last loop
Last_Idx := Str_Last;
for J in First_Idx .. Str_Last loop
if Str (J) = ' ' then
Last_Idx := J - 1;
exit;
end if;
end loop;
Word_Len := Last_Idx - First_Idx;
if Current_Pos = 0 then
Available := Diagnosis_String_Length;
else
Available := Diagnosis_String_Length - (Current_Pos + 1);
end if;
if Word_Len <= Available then
if Current_Pos > 0 then
Add (" ");
Current_Pos := Current_Pos + 1;
end if;
Add (Str (First_Idx .. Last_Idx));
Current_Pos := Current_Pos + Word_Len;
else
Add (ASIS_Line_Terminator);
Add (Str (First_Idx .. Last_Idx));
Current_Pos := Word_Len;
end if;
if Current_Pos >=
Diagnosis_String_Length - ASIS_Line_Terminator'Length
then
Add (ASIS_Line_Terminator);
Current_Pos := 0;
end if;
First_Idx := Last_Idx + 2;
end loop;
end Add_Str;
----------------------
-- Check_Validity --
----------------------
procedure Check_Validity
(Compilation_Unit : Asis.Compilation_Unit;
Query : String) is
begin
if Not_Nil (Compilation_Unit) and then
not Valid (Compilation_Unit)
then
Set_Error_Status_Internal
(Status => Value_Error,
Diagnosis => "Invalid Unit value in ",
Query => Query);
raise ASIS_Inappropriate_Compilation_Unit;
end if;
end Check_Validity;
procedure Check_Validity (Element : Asis.Element;
Query : String) is
begin
if Kind (Element) /= Not_An_Element and then
not Valid (Element)
then
Set_Error_Status_Internal
(Status => Value_Error,
Diagnosis => "Invalid Element value in ",
Query => Query);
raise ASIS_Inappropriate_Element;
end if;
end Check_Validity;
procedure Check_Validity
(Line : Asis.Text.Line;
Query : String)
is
begin
if not Asis.Text.Is_Nil (Line) and then not Valid (Line) then
Set_Error_Status_Internal
(Status => Value_Error,
Diagnosis => "Invalid Line value in ",
Query => Query);
raise ASIS_Inappropriate_Line;
end if;
end Check_Validity;
procedure Check_Validity (Context : Asis.Context;
Query : String) is
begin
if not Valid (Context) then
Set_Error_Status_Internal
(Status => Value_Error,
Diagnosis => "Unopened Context argument in ",
Query => Query);
raise ASIS_Inappropriate_Context;
end if;
end Check_Validity;
---------------
-- Close_Str --
---------------
procedure Close_Str is
begin
Add (ASIS_Line_Terminator);
Current_Pos := 0;
end Close_Str;
---------------------
-- Report_ASIS_Bug --
---------------------
procedure Report_ASIS_Bug
(Query_Name : String;
Ex : Exception_Occurrence;
Arg_Element : Asis.Element := Nil_Element;
Arg_Element_2 : Asis.Element := Nil_Element;
Arg_CU : Asis.Compilation_Unit := Nil_Compilation_Unit;
Arg_CU_2 : Asis.Compilation_Unit := Nil_Compilation_Unit;
Arg_Line : Asis.Text.Line := Nil_Line;
Arg_Span : Asis.Text.Span := Nil_Span;
Bool_Par_ON : Boolean := False;
Context_Par : Boolean := False
-- What else???
)
is
Is_GPL_Version : constant Boolean := Gnatvsn.Build_Type = GPL;
Is_FSF_Version : constant Boolean := Gnatvsn.Build_Type = FSF;
procedure Repeat_Char (Char : Character; Col : Nat; After : Character);
-- This procedure is similar to Comperr.Repeat_Char, but it does nothing
-- if Generate_Bug_Box is set OFF.
--
-- Output Char until current column is at or past Col, and then output
-- the character given by After (if column is already past Col on entry,
-- then the effect is simply to output the After character).
procedure End_Line;
-- This procedure is similar to Comperr.End_Line, but it does nothing
-- if Generate_Bug_Box is set OFF.
--
-- Add blanks up to column 76, and then a final vertical bar
procedure Write_Char (C : Character);
procedure Write_Str (S : String);
procedure Write_Eol;
-- These three subprograms are similar to the procedures with the same
-- names from the GNAT Output package except that they do nothing in
-- case if Generate_Bug_Box is set OFF.
procedure End_Line is
begin
if Generate_Bug_Box then
Repeat_Char (' ', 76, '|');
Write_Eol;
end if;
end End_Line;
procedure Repeat_Char (Char : Character; Col : Nat; After : Character) is
begin
if Generate_Bug_Box then
while Column < Col loop
Write_Char (Char);
end loop;
Write_Char (After);
end if;
end Repeat_Char;
procedure Write_Char (C : Character) is
begin
if Generate_Bug_Box then
Output.Write_Char (C);
end if;
end Write_Char;
procedure Write_Str (S : String) is
begin
if Generate_Bug_Box then
Output.Write_Str (S);
end if;
end Write_Str;
procedure Write_Eol is
begin
if Generate_Bug_Box then
Output.Write_Eol;
end if;
end Write_Eol;
begin
if Recursion_Count >= Max_Recursions_Allowed then
if Debug_Flag_I then
-- We can not do anything reasonable any more:
OS_Abort;
else
-- We will try the last time with turning off span computing
-- as a part of debug output
Debug_Flag_I := True;
-- It is not safe to put this flag OFF (it it was set OFF before
-- the call to Report_ASIS_Bug), because it may be some
-- circularities (see the comment for Max_Recursions_Allowed
-- global variable). We may want to revise this decision when
-- the revision of all the exception handlers in the ASIS code
-- is complete.
end if;
end if;
Recursion_Count := Recursion_Count + 1;
-- This procedure is called in case of an ASIS implementation bug, so
-- we do not care very much about efficiency
Set_Standard_Error;
-- Generate header for bug box
Write_Eol;
Write_Char ('+');
Repeat_Char ('=', 29, 'A');
Write_Str ("SIS BUG DETECTED");
Repeat_Char ('=', 76, '+');
Write_Eol;
-- Output ASIS version identification
Write_Str ("| ");
Write_Str (To_String (ASIS_Implementor_Version));
-- Output the exception info:
Write_Str (" ");
Write_Str (Exception_Name (Ex));
Write_Char (' ');
Write_Str (Exception_Message (Ex));
End_Line;
-- Output the query name and call details
Write_Str ("| when processing ");
Write_Str (Query_Name);
if Bool_Par_ON then
Write_Str (" (Boolean par => ON)");
elsif Context_Par then
Write_Str (" (with Context parameter)");
end if;
End_Line;
-- Add to ASIS Diagnosis:
Reset_Diagnosis_Buffer;
Add_Str ("ASIS internal implementation error detected for");
Close_Str;
Add_Str (Query_Name);
if Bool_Par_ON then
Add_Str ("(Boolean par => ON)");
elsif Context_Par then
Add_Str ("(with Context parameter)");
end if;
Close_Str;
-- Add information about the argument of the call (bug box)
if not Is_Nil (Arg_Element) or else
not Is_Nil (Arg_CU)
then
Write_Str ("| ");
Write_Str ("called with ");
if not Is_Nil (Arg_Element) then
Write_Str (Int_Kind (Arg_Element)'Img);
Write_Str (" Element");
End_Line;
elsif not Is_Nil (Arg_CU) then
Write_Str (Kind (Arg_CU)'Img);
Write_Str (" Compilation Unit");
End_Line;
end if;
Write_Str ("| (for full details see the debug image after the box)");
End_Line;
end if;
-- Add information about the argument of the call (Diagnosis string)
if not Is_Nil (Arg_Element) or else
not Is_Nil (Arg_CU)
then
Add_Str ("called with");
Close_Str;
if not Is_Nil (Arg_Element) then
Debug_String (Arg_Element, No_Abort => True);
Add (Debug_Buffer (1 .. Debug_Buffer_Len));
elsif not Is_Nil (Arg_CU) then
Debug_String (Arg_CU, No_Abort => True);
Add (Debug_Buffer (1 .. Debug_Buffer_Len));
end if;
Close_Str;
-- Note, that if we do not generate the bug box, in case if the query
-- have two Element or CU parameters, the information about the
-- second parameter is missed in the ASIS Diagnosis
end if;
Add_Str (Exception_Name (Ex));
Add (" ");
Add_Str (Exception_Message (Ex));
if not Generate_Bug_Box then
Close_Str;
Add_Str ("For more details activate the ASIS bug box");
end if;
-- Completing the bug box
if Is_FSF_Version then
Write_Str
("| Please submit a bug report; see" &
" http://gcc.gnu.org/bugs.html.");
End_Line;
elsif Is_GPL_Version then
Write_Str
("| Please submit a bug report by email " &
"to [email protected].");
End_Line;
Write_Str
("| GAP members can alternatively use GNAT Tracker:");
End_Line;
Write_Str
("| http://www.adacore.com/ " &
"section 'send a report'.");
End_Line;
Write_Str
("| See gnatinfo.txt for full info on procedure " &
"for submitting bugs.");
End_Line;
else
Write_Str
("| Please submit a bug report using GNAT Tracker:");
End_Line;
Write_Str
("| http://www.adacore.com/gnattracker/ " &
"section 'send a report'.");
End_Line;
Write_Str
("| alternatively submit a bug report by email " &
"to [email protected],");
End_Line;
Write_Str
("| including your customer number #nnn " &
"in the subject line.");
End_Line;
end if;
Write_Str
("| Use a subject line meaningful to you and us to track the bug.");
End_Line;
Write_Str
("| Include the entire contents of this bug " &
"box and the ASIS debug info");
End_Line;
Write_Str ("| in the report.");
End_Line;
Write_Str
("| Include the exact list of the parameters of the ASIS queries ");
End_Line;
Write_Str
("| Asis.Implementation.Initialize and " &
"Asis.Ada_Environments.Associate");
End_Line;
Write_Str
("| from the ASIS application for which the bug is detected");
End_Line;
Write_Str
("| Also include sources listed below in gnatchop format");
End_Line;
Write_Str
("| (concatenated together with no headers between files).");
End_Line;
if not Is_FSF_Version then
Write_Str ("| Use plain ASCII or MIME attachment.");
End_Line;
end if;
Write_Str
("| NOTE: ASIS bugs may be submitted to [email protected]");
End_Line;
-- Complete output of bug box
Write_Char ('+');
Repeat_Char ('=', 76, '+');
Write_Eol;
Write_Eol;
-- Argument debug image(s)
if not Is_Nil (Arg_Element) or else
not Is_Nil (Arg_CU) or else
not Is_Nil (Arg_Line)
then
Write_Str ("The debug image(s) of the argument(s) of the call");
Write_Eol;
if not (Is_Nil (Arg_Element_2) and then Is_Nil (Arg_CU_2)) then
Write_Str ("***First argument***");
Write_Eol;
end if;
Write_Str (Debug_Buffer (1 .. Debug_Buffer_Len));
Write_Eol;
Write_Eol;
if not Is_Nil (Arg_Element_2) then
Debug_String (Arg_Element_2, No_Abort => True);
elsif not Is_Nil (Arg_CU_2) then
Debug_String (Arg_CU_2, No_Abort => True);
end if;
if not (Is_Nil (Arg_Element_2) and then Is_Nil (Arg_CU_2)) then
Write_Str ("***Second argument***");
Write_Eol;
Write_Str (Debug_Buffer (1 .. Debug_Buffer_Len));
Write_Eol;
Write_Eol;
end if;
if not Is_Nil (Arg_Line) then
if not Is_Nil (Arg_Element) then
Write_Str ("***Line argument***");
Write_Eol;
end if;
if Recursion_Count >= Max_Recursions_Allowed and then
Debug_Flag_I
then
-- There is a real possibility that we can not output the
-- debug image of the argument line because of the bug being
-- reported:
Write_Str ("Line image can not be reported ");
Write_Str ("because of the internal error");
Write_Eol;
Write_Eol;
else
Write_Str (To_String (Debug_Image (Arg_Line)));
Write_Eol;
Write_Eol;
end if;
end if;
if not Is_Nil (Arg_Span) then
if not Is_Nil (Arg_Element) then
Write_Str ("***Span argument***");
Write_Eol;
end if;
Write_Str ("First_Line =>");
Write_Str (Arg_Span.First_Line'Img);
Write_Eol;
Write_Str ("First_Column =>");
Write_Str (Arg_Span.First_Column'Img);
Write_Eol;
Write_Str ("Last_Line =>");
Write_Str (Arg_Span.Last_Line'Img);
Write_Eol;
Write_Str ("Last_Column =>");
Write_Str (Arg_Span.Last_Column'Img);
Write_Eol;
Write_Eol;
end if;
end if;
Write_Str ("Please include these source files with error report");
Write_Eol;
Write_Str ("Note that list may not be accurate in some cases, ");
Write_Eol;
Write_Str ("so please double check that the problem can still ");
Write_Eol;
Write_Str ("be reproduced with the set of files listed.");
Write_Eol;
Write_Eol;
if Generate_Bug_Box then
for U in Main_Unit .. Last_Unit loop
begin
if not Is_Internal_File_Name
(File_Name (Source_Index (U)))
then
Write_Name (Full_File_Name (Source_Index (U)));
Write_Eol;
end if;
-- No point in double bug box if we blow up trying to print
-- the list of file names! Output informative msg and quit.
exception
when others =>
Write_Str ("list may be incomplete");
exit;
end;
end loop;
end if;
Write_Eol;
Set_Standard_Output;
if Keep_Going then
-- Raise ASIS_Failed and go ahead (the Diagnosis is already formed)
Status_Indicator := Unhandled_Exception_Error;
Recursion_Count := Recursion_Count - 1;
raise ASIS_Failed;
else
OS_Exit (1);
end if;
exception
when ASIS_Failed =>
raise;
when Internal_Ex : others =>
Write_Eol;
Write_Str ("The diagnostis can not be completed because of " &
"the following error:");
Write_Eol;
Write_Str (Exception_Name (Ex));
Write_Char (' ');
Write_Str (Exception_Message (Ex));
Write_Eol;
Close_Str;
Add_Str ("The diagnostis can not be completed because of " &
"the following error:");
Close_Str;
Add_Str (Exception_Name (Ex));
Add (" ");
Add_Str (Exception_Message (Ex));
Add_Str (Exception_Information (Internal_Ex));
Set_Standard_Output;
if Keep_Going then
Status_Indicator := Unhandled_Exception_Error;
-- Debug_Flag_I := Skip_Span_In_Debug_Image;
raise ASIS_Failed;
else
OS_Exit (1);
end if;
end Report_ASIS_Bug;
----------------------------
-- Reset_Diagnosis_Buffer --
----------------------------
procedure Reset_Diagnosis_Buffer is
begin
Diagnosis_Len := 0;
Current_Pos := 0;
end Reset_Diagnosis_Buffer;
-----------------------------
-- Raise_ASIS_Failed (new) --
-----------------------------
procedure Raise_ASIS_Failed
(Diagnosis : String;
Argument : Asis.Element := Nil_Element;
Stat : Asis.Errors.Error_Kinds := Internal_Error;
Bool_Par : Boolean := False;
Internal_Bug : Boolean := True)
is
begin
Diagnosis_Len := 0;
if Internal_Bug then
Add ("Internal implementation error: ");
end if;
Add (Diagnosis);
if Bool_Par then
Add (LT & "(Boolean parameter is TRUE)");
end if;
if not Is_Nil (Argument) then
Add (LT & "when processing ");
Debug_String (Argument);
Add (Debug_Buffer (1 .. Debug_Buffer_Len));
end if;
Status_Indicator := Stat;
raise ASIS_Failed;
end Raise_ASIS_Failed;
-------------------------------------
-- Raise_ASIS_Failed_In_Traversing --
-------------------------------------
procedure Raise_ASIS_Failed_In_Traversing
(Start_Element : Asis.Element;
Failure_At : Asis.Element;
Pre_Op : Boolean;
Exception_Info : String)
is
begin
Diagnosis_Len := 0;
Add ("Traversal failure. Tarversal started at:" & LT);
Debug_String (Start_Element);
Add (Debug_Buffer (1 .. Debug_Buffer_Len) & LT);
if Pre_Op then
Add ("Pre-operation");
else
Add ("Post-operation");
end if;
Add (" failed at:" & LT);
Debug_String (Failure_At);
Add (Debug_Buffer (1 .. Debug_Buffer_Len));
Add (LT & Exception_Info);
Status_Indicator := Unhandled_Exception_Error;
raise ASIS_Failed;
end Raise_ASIS_Failed_In_Traversing;
---------------------------------------------------------------
procedure Raise_ASIS_Inappropriate_Compilation_Unit
(Diagnosis : String) is
begin
Set_Error_Status (Status => Value_Error,
Diagnosis => "Inappropriate Unit Kind in "
& Diagnosis);
raise ASIS_Inappropriate_Compilation_Unit;
end Raise_ASIS_Inappropriate_Compilation_Unit;
----------------------------------------------------------------------
procedure Raise_ASIS_Inappropriate_Element
(Diagnosis : String;
Wrong_Kind : Internal_Element_Kinds;
Status : Error_Kinds := Value_Error) is
begin
Set_Error_Status (Status => Status,
Diagnosis => "Inappropriate Element Kind in " &
Diagnosis &
" (" & Wrong_Kind'Img & ")");
raise ASIS_Inappropriate_Element;
end Raise_ASIS_Inappropriate_Element;
----------------------------------------------------------------------
procedure Raise_ASIS_Inappropriate_Line_Number
(Diagnosis : String;
Status : Error_Kinds := Value_Error) is
begin
Set_Error_Status (Status => Status,
Diagnosis => "Inappropriate Lines/Span Kind in "
& Diagnosis);
raise ASIS_Inappropriate_Line_Number;
end Raise_ASIS_Inappropriate_Line_Number;
----------------------------------------------------------------------
procedure Not_Implemented_Yet (Diagnosis : String) is
begin
Set_Error_Status (Status => Not_Implemented_Error,
Diagnosis => "Not Implemented Query:" & LT
& Diagnosis);
raise ASIS_Failed;
end Not_Implemented_Yet;
--------------------------------------------------------------------
procedure Set_Error_Status
(Status : Error_Kinds := Not_An_Error;
Diagnosis : String := Nil_Asis_String)
is
begin
if Status = Not_An_Error and then
Diagnosis /= Nil_Asis_String
then
Status_Indicator := Internal_Error;
Diagnosis_Len := Incorrect_Setting_Len + ASIS_Line_Terminator_Len;
Diagnosis_Buffer (1 .. Diagnosis_Len)
:= Incorrect_Setting & ASIS_Line_Terminator;
raise ASIS_Failed;
end if;
Status_Indicator := Status;
Diagnosis_Len := Diagnosis'Length;
Diagnosis_Buffer (1 .. Diagnosis_Len) := Diagnosis;
end Set_Error_Status;
procedure Set_Error_Status_Internal
(Status : Error_Kinds := Not_An_Error;
Diagnosis : String := Nil_Asis_String;
Query : String := Nil_Asis_String)
is
begin
Set_Error_Status
(Status => Status,
Diagnosis => Diagnosis & Query);
end Set_Error_Status_Internal;
----------------------------------------------------------------------
--------------------------
-- Add_Call_Information --
--------------------------
procedure Add_Call_Information
(Outer_Call : String;
Argument : Asis.Element := Nil_Element;
Bool_Par : Boolean := False)
is
begin
Add (LT & "called in " & Outer_Call);
if Bool_Par then
Add (LT & "(Boolean parameter is TRUE)");
end if;
if not Is_Nil (Argument) then
Add (LT & "with the argument : ");
Debug_String (Argument);
Add (Debug_Buffer (1 .. Debug_Buffer_Len));
end if;
end Add_Call_Information;
end A4G.Vcheck;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen
|
|
1fdd3a7d6a46a0b94aa29b3ad90b4da207414686
|
src/asis/a4g-a_stand.ads
|
src/asis/a4g-a_stand.ads
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . A _ S T A N D --
-- --
-- S p e c --
-- --
-- $Revision: 15117 $
-- --
-- Copyright (c) 2002, 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). --
-- --
------------------------------------------------------------------------------
-- We need this renaming because the GNAT Stand package and the ASIS A4G.Stand
-- package conflict if mentioned in the same context clause. This renaming
-- seems to be the cheapest way to correct the old bad choice of the name
-- of the ASIS package (A4G.Stand)
with A4G.Stand;
package A4G.A_Stand renames A4G.Stand;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
stcarrez/dynamo,stcarrez/dynamo,stcarrez/dynamo
|
|
78fee0e7d2d9aaf6d1c7cccbb7a1fc555ac6f1f6
|
src/asf-beans-injections.adb
|
src/asf-beans-injections.adb
|
-----------------------------------------------------------------------
-- asf-beans-injections -- Injection of parameters, headers, cookies in beans
-- Copyright (C) 2015 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Beans.Objects;
with ASF.Cookies;
package body ASF.Beans.Injections is
-- ------------------------------
-- Inject the request header whose name is defined by Descriptor.Param.
-- ------------------------------
procedure Header (Bean : in out Util.Beans.Basic.Bean'Class;
Descriptor : in Inject_Type;
Request : in ASF.Requests.Request'Class) is
Value : constant String := Request.Get_Header (Descriptor.Param.all);
begin
Bean.Set_Value (Descriptor.Name.all, Util.Beans.Objects.To_Object (Value));
end Header;
-- ------------------------------
-- Inject the request query string parameter whose name is defined by Descriptor.Param.
-- ------------------------------
procedure Query_Param (Bean : in out Util.Beans.Basic.Bean'Class;
Descriptor : in Inject_Type;
Request : in ASF.Requests.Request'Class) is
Value : constant String := Request.Get_Parameter (Descriptor.Param.all);
begin
Bean.Set_Value (Descriptor.Name.all, Util.Beans.Objects.To_Object (Value));
end Query_Param;
-- ------------------------------
-- Inject the request cookie whose name is defined by Descriptor.Param.
-- ------------------------------
procedure Cookie (Bean : in out Util.Beans.Basic.Bean'Class;
Descriptor : in Inject_Type;
Request : in ASF.Requests.Request'Class) is
Cookies : constant ASF.Cookies.Cookie_Array := Request.Get_Cookies;
begin
for I in Cookies'Range loop
if ASF.Cookies.Get_Name (Cookies (I)) = Descriptor.Param.all then
Bean.Set_Value (Descriptor.Name.all,
Util.Beans.Objects.To_Object (ASF.Cookies.Get_Value (Cookies (I))));
end if;
end loop;
end Cookie;
-- ------------------------------
-- Inject the request URI path component whose position is defined by Descriptor.Pos.
-- ------------------------------
procedure Path_Param (Bean : in out Util.Beans.Basic.Bean'Class;
Descriptor : in Inject_Type;
Request : in ASF.Requests.Request'Class) is
URI : constant String := Request.Get_Path_Info;
Pos : Natural := URI'First;
Count : Natural := Descriptor.Pos;
Next_Pos : Natural;
begin
while Count > 0 and Pos < URI'Last loop
Next_Pos := Util.Strings.Index (URI, '/', Pos + 1);
Count := Count - 1;
if Count = 0 then
if Next_Pos = 0 then
Next_Pos := URI'Last;
else
Next_Pos := Next_Pos - 1;
end if;
Bean.Set_Value (Descriptor.Name.all,
Util.Beans.Objects.To_Object (URI (Pos + 1 .. Next_Pos)));
return;
end if;
Pos := Next_Pos;
end loop;
end Path_Param;
-- ------------------------------
-- Inject into the Ada bean a set of information extracted from the request object.
-- The value is obtained from a request header, a cookie, a query string parameter or
-- from a URI path component. The value is injected by using the bean operation
-- <tt>Set_Value</tt>.
-- ------------------------------
procedure Inject (Into : in out Util.Beans.Basic.Bean'Class;
List : in Inject_Array_Type;
Request : in ASF.Requests.Request'Class) is
begin
for I in List'Range loop
List (I).Handler (Into, List (I), Request);
end loop;
end Inject;
end ASF.Beans.Injections;
|
Implement the Inject, Header, Path_Param, Cookie and Query_Param procedures
|
Implement the Inject, Header, Path_Param, Cookie and Query_Param
procedures
|
Ada
|
apache-2.0
|
stcarrez/ada-asf,stcarrez/ada-asf,stcarrez/ada-asf
|
|
104dbe653fe750609f1430a31186caf93142aa53
|
src/security-policies.adb
|
src/security-policies.adb
|
-----------------------------------------------------------------------
-- security-policies -- Security Policies
-- Copyright (C) 2010, 2011, 2012 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Finalization;
with Ada.Strings.Unbounded;
with Ada.Containers.Hashed_Maps;
with Ada.Containers.Vectors;
with Util.Log.Loggers;
with Util.Strings;
with Util.Refs;
with Util.Beans.Objects;
with Util.Beans.Objects.Vectors;
with Util.Serialize.IO.XML;
with GNAT.Regexp;
with Security.Permissions;
package body Security.Policies is
-- The logger
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Security.Policies");
-- Get the policy name.
function Get_Name (From : in Policy) return String is
begin
return "";
end Get_Name;
-- ------------------------------
-- Permission Manager
-- ------------------------------
-- Add the policy to the policy manager. After a policy is added in the manager,
-- it can participate in the security policy.
procedure Add_Policy (Manager : in out Policy_Manager;
Policy : in Policy_Access) is
begin
null;
end Add_Policy;
procedure Add_Permission (Manager : in out Policy_Manager;
Name : in String;
Permission : in Controller_Access) is
begin
null;
end Add_Permission;
-- Get the security controller associated with the permission index <b>Index</b>.
-- Returns null if there is no such controller.
function Get_Controller (Manager : in Policy_Manager'Class;
Index : in Permissions.Permission_Index) return Controller_Access is
use type Permissions.Permission_Index;
begin
if Index >= Manager.Last_Index then
return null;
else
return Manager.Permissions (Index);
end if;
end Get_Controller;
-- Read the policy file
procedure Read_Policy (Manager : in out Policy_Manager;
File : in String) is
use Util;
Reader : Util.Serialize.IO.XML.Parser;
package Policy_Config is
new Reader_Config (Reader, Manager'Unchecked_Access);
package Role_Config is
new Security.Controllers.Roles.Reader_Config (Reader, Manager'Unchecked_Access);
pragma Warnings (Off, Policy_Config);
pragma Warnings (Off, Role_Config);
begin
Log.Info ("Reading policy file {0}", File);
Reader.Parse (File);
end Read_Policy;
-- Initialize the permission manager.
overriding
procedure Initialize (Manager : in out Policy_Manager) is
begin
null;
end Initialize;
-- Finalize the permission manager.
overriding
procedure Finalize (Manager : in out Policy_Manager) is
begin
null;
end Finalize;
end Security.Policies;
|
Implement the Security.Policies package
|
Implement the Security.Policies package
|
Ada
|
apache-2.0
|
Letractively/ada-security
|
|
879458576413d94021e5d6eaa5c8cda3d48832cd
|
src/util-beans-basic-lists.adb
|
src/util-beans-basic-lists.adb
|
-----------------------------------------------------------------------
-- Util.Beans.Basic.Lists -- List bean given access to a vector
-- Copyright (C) 2011 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Unchecked_Deallocation;
package body Util.Beans.Basic.Lists is
-- ------------------------------
-- Initialize the list bean.
-- ------------------------------
overriding
procedure Initialize (Object : in out List_Bean) is
Bean : constant Readonly_Bean_Access := Object.Current'Unchecked_Access;
begin
Object.Row := Util.Beans.Objects.To_Object (Bean, Util.Beans.Objects.STATIC);
end Initialize;
-- ------------------------------
-- Get the number of elements in the list.
-- ------------------------------
function Get_Count (From : in List_Bean) return Natural is
begin
return Natural (Vectors.Length (From.List));
end Get_Count;
-- ------------------------------
-- Set the current row index. Valid row indexes start at 1.
-- ------------------------------
procedure Set_Row_Index (From : in out List_Bean;
Index : in Natural) is
begin
From.Current := Vectors.Element (From.List, Index - 1);
end Set_Row_Index;
-- ------------------------------
-- Get the element at the current row index.
-- ------------------------------
function Get_Row (From : in List_Bean) return Util.Beans.Objects.Object is
begin
return From.Row;
end Get_Row;
-- ------------------------------
-- Get the value identified by the name.
-- If the name cannot be found, the method should return the Null object.
-- ------------------------------
function Get_Value (From : in List_Bean;
Name : in String) return Util.Beans.Objects.Object is
begin
if Name = "count" then
return Util.Beans.Objects.To_Object (Integer (From.List.Length));
else
return Util.Beans.Objects.Null_Object;
end if;
end Get_Value;
-- ------------------------------
-- Deletes the list bean
-- ------------------------------
procedure Free (List : in out Util.Beans.Basic.Readonly_Bean_Access) is
procedure Free is
new Ada.Unchecked_Deallocation (List_Bean'Class,
List_Bean_Access);
begin
if List.all in List_Bean'Class then
declare
L : List_Bean_Access := List_Bean (List.all)'Unchecked_Access;
begin
Free (L);
List := null;
end;
end if;
end Free;
end Util.Beans.Basic.Lists;
|
-----------------------------------------------------------------------
-- Util.Beans.Basic.Lists -- List bean given access to a vector
-- Copyright (C) 2011, 2013 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.Unchecked_Deallocation;
package body Util.Beans.Basic.Lists is
-- ------------------------------
-- Initialize the list bean.
-- ------------------------------
overriding
procedure Initialize (Object : in out List_Bean) is
Bean : constant Readonly_Bean_Access := Object.Current'Unchecked_Access;
begin
Object.Row := Util.Beans.Objects.To_Object (Bean, Util.Beans.Objects.STATIC);
end Initialize;
-- ------------------------------
-- Get the number of elements in the list.
-- ------------------------------
function Get_Count (From : in List_Bean) return Natural is
begin
return Natural (Vectors.Length (From.List));
end Get_Count;
-- ------------------------------
-- Set the current row index. Valid row indexes start at 1.
-- ------------------------------
procedure Set_Row_Index (From : in out List_Bean;
Index : in Natural) is
begin
From.Current_Index := Index;
From.Current := Vectors.Element (From.List, Index - 1);
end Set_Row_Index;
-- ------------------------------
-- Returns the current row index.
-- ------------------------------
function Get_Row_Index (From : in List_Bean) return Natural is
begin
return From.Current_Index;
end Get_Row_Index;
-- ------------------------------
-- Get the element at the current row index.
-- ------------------------------
function Get_Row (From : in List_Bean) return Util.Beans.Objects.Object is
begin
return From.Row;
end Get_Row;
-- ------------------------------
-- Get the value identified by the name.
-- If the name cannot be found, the method should return the Null object.
-- ------------------------------
function Get_Value (From : in List_Bean;
Name : in String) return Util.Beans.Objects.Object is
begin
if Name = "count" then
return Util.Beans.Objects.To_Object (Integer (From.List.Length));
elsif Name = "rowIndex" then
return Util.Beans.Objects.To_Object (From.Current_Index);
else
return Util.Beans.Objects.Null_Object;
end if;
end Get_Value;
-- ------------------------------
-- Deletes the list bean
-- ------------------------------
procedure Free (List : in out Util.Beans.Basic.Readonly_Bean_Access) is
procedure Free is
new Ada.Unchecked_Deallocation (List_Bean'Class,
List_Bean_Access);
begin
if List.all in List_Bean'Class then
declare
L : List_Bean_Access := List_Bean (List.all)'Unchecked_Access;
begin
Free (L);
List := null;
end;
end if;
end Free;
end Util.Beans.Basic.Lists;
|
Implement the Get_Row_Index Recognize 'rowIndex' as a name for the list bean to return the current row index
|
Implement the Get_Row_Index
Recognize 'rowIndex' as a name for the list bean to return the current row index
|
Ada
|
apache-2.0
|
Letractively/ada-util,flottokarotto/ada-util,flottokarotto/ada-util,Letractively/ada-util
|
e9503ebb713bae3271a25fe0efbaf0f769b52d0b
|
src/asis/a4g-contt-tt.ads
|
src/asis/a4g-contt-tt.ads
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . C O N T T . T T --
-- --
-- S p e c --
-- --
-- Copyright (C) 1995-2011, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore. --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
-- This package defines for each ASIS Context the corresponding Tree Table,
-- which contains the information about the tree output files needed for
-- handling and swapping the ASTs represented by the tree output files
-- accessed by ASIS.
with Asis;
package A4G.Contt.TT is -- Context_Table.Tree_Tables
----------------
-- Tree Table --
----------------
-- The tree table has an entry for each AST ( = tree output file)
-- created and read at least once for this run of ASIS application.
-- The entries in the table are accessing using a Tree_Id which
-- ranges from Nil_Tree (a special value using for initializing
-- ASIS Nil_Element and ASIS Nil_Compilation_Unit) to Last_Tree.
-- Each entry has the following fields:
---------------------
-- Tree Name Table --
---------------------
procedure Get_Name_String (C : Context_Id; Id : Tree_Id);
-- Get_Name_String is used to retrieve the string associated with
-- an entry in the name table. The resulting string is stored in
-- Name_Buffer and Name_Len is set.
function Get_Tree_Name (C : Context_Id; Id : Tree_Id) return String;
-- Returns the full name of the tree file.
function Allocate_Tree_Entry return Tree_Id; -- #####
-- Allocates the new entry in the Tree Table for the tree output file
-- name stored in the A_Name_Buffer (A_Name_Len should be set
-- in a proper way).
------------------------------
-- Internal Tree Attributes --
------------------------------
-- Each Tree entry contains the following fields, representing the Tree
-- attributes needed to organize tree processing inside ASIS
-- implementation:
-- Enclosing_Lib : Context_Id; --##
-- Context Id of the ASIS Context for which the tree has been
-- created.
-- Main_Unit_Id : Unit_Id;
-- The ASIS Compilation Unit, corresponding to the main unit in
-- the tree
-- Main_Top : Node_Id;
-- The top node (having N_Compilation_Unit Node Kind) of Main_Unit
-- Units : Elist_Id;
-- The list of all the Units (or all the Units except Main_Unit?)
-- which may be processed on the base of this tree, [each Unit
-- is accompanied by its top node, which it has in the given tree
-- ??? Not implemented for now!]
---------------------------------------------------------------
-- Internal Tree Unit Attributes Access and Update Routines --
---------------------------------------------------------------
function Main_Unit_Id (T : Tree_Id) return Unit_Id;
function Main_Unit_Id return Unit_Id;
-- Returns the Id of the main unit in Current_Tree
procedure Set_Main_Unit_Id (T : Tree_Id; U : Unit_Id);
procedure Set_Main_Top (T : Tree_Id; N : Node_Id);
-- Do we really need Set procedures having a Tree (and its "enclosing"
-- Context) as a parameter? Now it seems, that all settings will be
-- done for the currently accessing Tree only.
procedure Set_Main_Unit_Id (U : Unit_Id);
procedure Set_Main_Top (N : Node_Id);
-----------------------------------
-- Subprograms for Tree Swapping --
-----------------------------------
function Unit_In_Current_Tree (C : Context_Id; U : Unit_Id) return Boolean;
-- Checks if the subtree for a given Unit defined by C and U, is
-- contained in the currently accessed tree.
procedure Reset_Tree (Context : Context_Id; Tree : Tree_Id);
-- Resets the currently accessed tree to the tree identified by
-- the Context and Tree parameters
procedure Reset_Tree_For_Unit (C : Context_Id; U : Unit_Id);
procedure Reset_Tree_For_Unit (Unit : Asis.Compilation_Unit);
-- Resets the currently accessed tree to some tree containing
-- the subtree for a given unit. For now, there is no special
-- strategy for choosing the tree among all the trees containing
-- the given unit
procedure Reset_Tree_For_Element (E : Asis.Element);
-- Resets the currently accessed tree to the tree containing the node(s)
-- of the argument Element.
procedure Reset_Instance_Tree
(Lib_Level_Instance : Asis.Compilation_Unit;
Decl_Node : in out Node_Id);
-- Given Lib_Level_Instance as ASIS Compilation Unit being a library-level
-- instantiation, or a package or generic package containing
-- an instantiation of some library-level generic unit, and Decl_Node as
-- the node representing some declaration in the corresponding spec (which
-- can be either expanded generics spec if Lib_Level_Instance is a library-
-- level instantiation or a normal spec in case of a (generic) package);
-- it is an error to call this procedure with other arguments), this
-- procedure resets the currently accessed tree to the main tree for
-- Lib_Level_Instance (it may be the tree created for the body of
-- Lib_Level_Instance in case if Lib_Level_Instance is a package
-- declaration) and resets Decl_Node to point to the same construct in
-- this tree.
--
-- If the corresponding ASIS Context does not contain the main tree for
-- this library-level instantiation, the procedure does nothing.
-- Also does nothing if Lib_Level_Instance is a package body
function Restore_Node_From_Trace
(In_Body : Boolean := False;
CU : Asis.Compilation_Unit := Asis.Nil_Compilation_Unit)
return Node_Id;
-- Taking the node trace stored in Node_Trace table, tries to find the
-- construct corresponding to the beginning of the trace in the currently
-- accessed tree. By default we consider that we are in the package spec,
-- unless In_Body is set ON.
procedure Append_Full_View_Tree_To_Unit (C : Context_Id; U : Unit_Id);
procedure Append_Limited_View_Tree_To_Unit (C : Context_Id; U : Unit_Id);
-- Appends the currently accessed tree to the list of the (consistent)
-- trees containing a given Unit (this tree list belongs to the unit U).
procedure Reorder_Trees (C : Context_Id);
-- This procedure is called in the very end of opening the context C, when
-- all the information is already set in the Context Unit table. It
-- reorders the tree lists associated with units according to the
-- following rules (note, that currently the first tree in the tree list
-- is used by Element gateway queries to get into the unit structure:
--
-- (1) for a subunit, the tree for its ancestor body is moved into the
-- first position in the tree list;
--
-- (2) for a package declaration or generic package declaration, if this
-- package requires a body, the tree for the body is moved into the
-- first position in the tree list;
--
-- (3) for package or generic package declaration which does not require a
-- body, the tree created for the given (generic) package is moved
-- into the first position in the tree list;
--
-- (4) for a library-level instantiation, the tree created for the
-- instantiation is moved into the first position in the tree list;
--
-- (5) for a (generic) subprogram declaration, the tree for the
-- corresponding body is moved into the first position in the tree
-- list;
--
-- (6) for the bodies, we may also need to set the main tree first, because
-- according to Lib (h), the body may be compiled as being needed for
-- some spec (or other body unit)
--
-- For -CA Context, if the tree to be moved into the first position in
-- the tree list does not exist, the corresponding warning is generated,
-- except if the corresponding unit is of A_Predefined_Unit or
-- An_Implementation_Unit origin
---------------------------------
-- General-Purpose Subprograms --
---------------------------------
function Present (Tree : Tree_Id) return Boolean;
-- Tests given Tree Id for non-equality with No_Tree_Name.
-- This allows notations like "if Present (Tree)" as opposed to
-- "if Tree /= No_Tree_Name"
function No (Tree : Tree_Id) return Boolean;
-- Tests given Tree Id for equality with No_Tree_Name. This allows
-- notations like "if No (Tree)" as opposed to
-- "if Tree = No_Tree_Name"
function Last_Tree (C : Context_Id) return Tree_Id;
-- Returns the Tree_Id of the last tree which has been allocated
-- in the Tree Table.
procedure Output_Tree (C : Context_Id; Tree : Tree_Id);
-- Produces the debug output of the Tree Table entry corresponding
-- to Tree
procedure Print_Trees (C : Context_Id);
-- Produces the debug output from the Tree table for the Context C.
function Tree_Consistent_With_Sources
(E : Asis.Element)
return Boolean;
function Tree_Consistent_With_Sources
(CU : Asis.Compilation_Unit)
return Boolean;
-- These functions are supposed to be used for Incremental Context mode.
-- They check that the tree from which their argument Element or Unit has
-- been obtained is still consistent with all the sources from which
-- the tree was generated (and that all these sources are available)
-- This function supposes that its argument is not null and that the tree
-- to check is available.
function Current_Tree_Consistent_With_Sources return Boolean;
-- Checks that for the current tree all the sources from which it has been
-- obtained are still available and that the tree is consistent with
-- these sources. The caller is responsible for setting as the current
-- tree the tree he would like to check
end A4G.Contt.TT;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen
|
|
74bb7921ab69acd59f815a374c3c05f15aabc132
|
src/asis/a4g-decl_sem.adb
|
src/asis/a4g-decl_sem.adb
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . D E C L _ S E M --
-- --
-- B o d y --
-- --
-- Copyright (C) 1995-2012, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
-- This package contains routines needed for semantic queries from
-- the Asis.Declarations package
with Asis.Declarations; use Asis.Declarations;
with Asis.Definitions; use Asis.Definitions;
with Asis.Iterator; use Asis.Iterator;
with Asis.Elements; use Asis.Elements;
with Asis.Errors; use Asis.Errors;
with Asis.Exceptions; use Asis.Exceptions;
with Asis.Extensions; use Asis.Extensions;
with Asis.Set_Get; use Asis.Set_Get;
with A4G.A_Sem; use A4G.A_Sem;
with A4G.Int_Knds; use A4G.Int_Knds;
with A4G.Vcheck; use A4G.Vcheck;
with A4G.Mapping; use A4G.Mapping;
with Atree; use Atree;
with Einfo; use Einfo;
with Namet; use Namet;
with Nlists; use Nlists;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
package body A4G.Decl_Sem is
-----------------------------
-- Corresponding_Body_Node --
-----------------------------
function Corresponding_Body_Node (Decl_Node : Node_Id) return Node_Id is
Result_Node : Node_Id;
begin
Result_Node := Corresponding_Body (Decl_Node);
if No (Result_Node) then
-- package without a body
return Result_Node;
end if;
Result_Node := Parent (Result_Node);
if Nkind (Result_Node) = N_Defining_Program_Unit_Name then
Result_Node := Parent (Result_Node);
end if;
if Nkind (Result_Node) = N_Function_Specification or else
Nkind (Result_Node) = N_Procedure_Specification
then
Result_Node := Parent (Result_Node);
end if;
if Nkind (Parent (Result_Node)) = N_Subunit then
-- we come back to the stub!
Result_Node := Corresponding_Stub (Parent (Result_Node));
end if;
if not Comes_From_Source (Result_Node)
and then
not (Is_Rewrite_Substitution (Result_Node)
-- SCz
-- and then
-- Nkind (Original_Node (Result_Node)) = N_Expression_Function)
)
then
-- implicit body created by the compiler for renaming-as-body.
-- the renaming itself is the previous list member, so
Result_Node := Get_Renaming_As_Body (Decl_Node);
end if;
return Result_Node;
end Corresponding_Body_Node;
-----------------------------
-- Corresponding_Decl_Node --
-----------------------------
function Corresponding_Decl_Node (Body_Node : Node_Id) return Node_Id is
Result_Node : Node_Id := Empty;
Protected_Def_Node : Node_Id;
Tmp_Node : Node_Id := Empty;
begin
case Nkind (Body_Node) is
when N_Body_Stub =>
Result_Node := Corr_Decl_For_Stub (Body_Node);
when N_Entry_Body =>
Protected_Def_Node := Corresponding_Spec (Parent (Body_Node));
if Ekind (Protected_Def_Node) = E_Limited_Private_Type then
Protected_Def_Node := Full_View (Protected_Def_Node);
end if;
Protected_Def_Node := Parent (Protected_Def_Node);
Protected_Def_Node := Protected_Definition (Protected_Def_Node);
Tmp_Node :=
First_Non_Pragma (Visible_Declarations (Protected_Def_Node));
while Present (Tmp_Node) loop
if Nkind (Tmp_Node) = N_Entry_Declaration and then
Parent (Corresponding_Body (Tmp_Node)) = Body_Node
then
Result_Node := Tmp_Node;
exit;
end if;
Tmp_Node := Next_Non_Pragma (Tmp_Node);
end loop;
if No (Result_Node) and then
Present (Private_Declarations (Protected_Def_Node))
then
Tmp_Node :=
First_Non_Pragma (Private_Declarations (Protected_Def_Node));
while Present (Tmp_Node) loop
if Nkind (Tmp_Node) = N_Entry_Declaration and then
Parent (Corresponding_Body (Tmp_Node)) = Body_Node
then
Result_Node := Tmp_Node;
exit;
end if;
Tmp_Node := Next_Non_Pragma (Tmp_Node);
end loop;
end if;
when others =>
Result_Node := Corresponding_Spec (Body_Node);
Result_Node := Parent (Result_Node);
if Nkind (Result_Node) = N_Defining_Program_Unit_Name then
Result_Node := Parent (Result_Node);
end if;
end case;
pragma Assert (Present (Result_Node));
-- now - from a defining entity to the declaration itself; note,
-- that here we cannot get a defining expanded name, because the
-- corresponding declaration for library units are obtained in
-- another control flow
case Nkind (Result_Node) is
when N_Function_Specification |
N_Procedure_Specification |
N_Package_Specification =>
Result_Node := Parent (Result_Node);
when N_Private_Type_Declaration =>
-- this is the case when a task type is the completion
-- of a private type
Result_Node := Full_View (Defining_Identifier (Result_Node));
Result_Node := Parent (Result_Node);
when others =>
null;
end case;
return Result_Node;
end Corresponding_Decl_Node;
---------------------------------------
-- Get_Corresponding_Generic_Element --
---------------------------------------
function Get_Corresponding_Generic_Element
(Gen_Unit : Asis.Declaration;
Def_Name : Asis.Element)
return Asis.Element
is
Kind_To_Check : constant Internal_Element_Kinds := Int_Kind (Def_Name);
Sloc_To_Check : constant Source_Ptr := Sloc (Node (Def_Name));
Line_To_Check : constant Physical_Line_Number :=
Get_Physical_Line_Number (Sloc_To_Check);
Column_To_Check : constant Column_Number :=
Get_Column_Number (Sloc_To_Check);
Result_Element : Asis.Element := Nil_Element;
Tmp_El : Asis.Element;
Check_Inherited_Element : constant Boolean :=
Is_Part_Of_Inherited (Def_Name);
Sloc_To_Check_1 : constant Source_Ptr := Sloc (Node_Field_1 (Def_Name));
Line_To_Check_1 : constant Physical_Line_Number :=
Get_Physical_Line_Number (Sloc_To_Check_1);
Column_To_Check_1 : constant Column_Number :=
Get_Column_Number (Sloc_To_Check_1);
-- Used in case if we are looking for an implicit Element
function Is_Found (E : Asis.Element) return Boolean;
-- Checks if the Element being traversed is a corresponding generic
-- element for Def_Name
function Is_Found (E : Asis.Element) return Boolean is
Elem_Sloc : constant Source_Ptr := Sloc (Node (E));
Elem_Sloc_1 : Source_Ptr;
Result : Boolean := False;
begin
if not (Check_Inherited_Element xor Is_Part_Of_Inherited (E)) then
Result :=
Line_To_Check = Get_Physical_Line_Number (Elem_Sloc)
and then
Column_To_Check = Get_Column_Number (Elem_Sloc);
if Result
and then
Check_Inherited_Element
then
Elem_Sloc_1 := Sloc (Node_Field_1 (E));
Result :=
Line_To_Check_1 = Get_Physical_Line_Number (Elem_Sloc_1)
and then
Column_To_Check_1 = Get_Column_Number (Elem_Sloc_1);
end if;
end if;
return Result;
end Is_Found;
-- and now, variables and actuals for Traverse_Element
My_Control : Traverse_Control := Continue;
My_State : No_State := Not_Used;
procedure Pre_Op
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out No_State);
procedure Look_For_Corr_Gen_El is new Traverse_Element
(State_Information => No_State,
Pre_Operation => Pre_Op,
Post_Operation => No_Op);
procedure Pre_Op
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out No_State)
is
pragma Unreferenced (State);
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Element);
begin
case Arg_Kind is
when An_Internal_Body_Stub =>
if Kind_To_Check = A_Defining_Identifier or else
Kind_To_Check in Internal_Defining_Operator_Kinds
then
-- We have to traverse the code of the subunit -
-- see 9217-015. But before doing this, let's check the
-- name of the subunit:
Tmp_El := Asis.Declarations.Names (Element) (1);
if Int_Kind (Tmp_El) = Kind_To_Check and then
Is_Found (Tmp_El)
then
Result_Element := Tmp_El;
Control := Terminate_Immediately;
return;
end if;
end if;
-- If we are here, we have to traverse the proper body:
Tmp_El := Corresponding_Subunit (Element);
if not Is_Nil (Tmp_El) then
Look_For_Corr_Gen_El (Element => Tmp_El,
Control => My_Control,
State => My_State);
end if;
when Internal_Defining_Name_Kinds =>
if Int_Kind (Element) = Kind_To_Check and then
Is_Found (Element)
then
Result_Element := Element;
Control := Terminate_Immediately;
end if;
when A_Derived_Type_Definition |
A_Derived_Record_Extension_Definition |
A_Formal_Derived_Type_Definition =>
if Check_Inherited_Element then
declare
Inherited_Decls : constant Asis.Element_List :=
Implicit_Inherited_Declarations (Element);
Inherited_Subprgs : constant Asis.Element_List :=
Implicit_Inherited_Subprograms (Element);
begin
for J in Inherited_Decls'Range loop
exit when My_Control = Terminate_Immediately;
Look_For_Corr_Gen_El
(Element => Inherited_Decls (J),
Control => My_Control,
State => My_State);
end loop;
for J in Inherited_Subprgs'Range loop
exit when My_Control = Terminate_Immediately;
Look_For_Corr_Gen_El
(Element => Inherited_Subprgs (J),
Control => My_Control,
State => My_State);
end loop;
end;
end if;
when others =>
null;
end case;
end Pre_Op;
begin -- Get_Corresponding_Generic_Element
Look_For_Corr_Gen_El (Element => Gen_Unit,
Control => My_Control,
State => My_State);
return Result_Element;
exception
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Argument => Nil_Element,
Outer_Call => "A4G.Decl_Sem.Get_Corresponding_Generic_Element");
end if;
raise;
end Get_Corresponding_Generic_Element;
-----------------------
-- Get_Expanded_Spec --
-----------------------
function Get_Expanded_Spec (Instance_Node : Node_Id) return Node_Id is
Result_Node : Node_Id;
begin
-- GNAT constructs the structure corresponding to an expanded generic
-- specification just before the instantiation itself, except the case
-- of the formal package with box:
if Nkind (Instance_Node) = N_Package_Declaration and then
Nkind (Original_Node (Instance_Node)) = N_Formal_Package_Declaration
then
Result_Node := Instance_Node;
else
Result_Node := Prev_Non_Pragma (Instance_Node);
end if;
if Nkind (Result_Node) = N_Package_Body then
-- Here we have the expanded generic body, therefore - one
-- more step up the list
Result_Node := Prev_Non_Pragma (Result_Node);
end if;
-- in case of a package instantiation, we have to take the whole
-- expanded package, but in case of a subprogram instantiation we
-- need only the subprogram declaration, which is the last element
-- of the visible declarations list of the "artificial" package
-- spec created by the compiler
if not (Nkind (Instance_Node) = N_Package_Instantiation or else
Nkind (Original_Node (Instance_Node)) =
N_Formal_Package_Declaration)
then
Result_Node := Last_Non_Pragma (Visible_Declarations
(Specification (Result_Node)));
if Nkind (Result_Node) = N_Subprogram_Body then
Result_Node := Parent (Parent (Corresponding_Spec (Result_Node)));
end if;
pragma Assert (Nkind (Result_Node) = N_Subprogram_Declaration);
end if;
return Result_Node;
end Get_Expanded_Spec;
--------------------------
-- Get_Renaming_As_Body --
--------------------------
function Get_Renaming_As_Body
(Node : Node_Id;
Spec_Only : Boolean := False)
return Node_Id
is
Entity_Node : Node_Id;
Scope_Node : Node_Id;
Result_Node : Node_Id := Empty;
List_To_Search : List_Id;
Search_Node : Node_Id := Node;
-- in the first List_To_Search we start not from the very beginning;
-- but from the node representing the argument subprogram declaration
Completion_Found : Boolean := False;
procedure Search_In_List;
-- looks for a possible renaming-as-bode node being a completion for
-- Node, using global settings for List_To_Search and Search_Node
procedure Search_In_List is
begin
while Present (Search_Node) loop
if Nkind (Search_Node) = N_Subprogram_Renaming_Declaration and then
Corresponding_Spec (Search_Node) = Entity_Node
then
Result_Node := Search_Node;
Completion_Found := True;
return;
end if;
Search_Node := Next_Non_Pragma (Search_Node);
end loop;
end Search_In_List;
begin -- Get_Renaming_As_Body
Entity_Node := Defining_Unit_Name (Specification (Node));
List_To_Search := List_Containing (Node);
Search_In_List;
if Completion_Found then
goto end_of_search;
end if;
-- here we have to see, where we are. If we are not in a package,
-- we have nothing to do, but if we are in the package, we may
-- have to search again in another lists (the private part and
-- the body)
Scope_Node := Scope (Entity_Node);
-- Node here can be of N_Subprogram_Declaration only!
if Nkind (Parent (Scope_Node)) = N_Implicit_Label_Declaration then
-- this is the implicit name created for a block statement,
-- so we do not have any other list to search in
goto end_of_search;
else
Scope_Node := Parent (Scope_Node);
end if;
if Nkind (Scope_Node) = N_Defining_Program_Unit_Name then
Scope_Node := Parent (Scope_Node);
end if;
-- now if we are not in N_Package_Specification, we have no
-- other list to search in
if Nkind (Scope_Node) /= N_Package_Specification then
goto end_of_search;
end if;
-- and here we are in N_Package_Specification
if List_To_Search = Visible_Declarations (Scope_Node) then
-- continuing in the private part:
List_To_Search := Private_Declarations (Scope_Node);
if not (No (List_To_Search)
or else Is_Empty_List (List_To_Search))
then
Search_Node := First_Non_Pragma (List_To_Search);
Search_In_List;
end if;
if Completion_Found or else Spec_Only then
goto end_of_search;
end if;
end if;
-- and here we have to go into the package body, if any:
Scope_Node := Corresponding_Body (Parent (Scope_Node));
if Present (Scope_Node) then
while Nkind (Scope_Node) /= N_Package_Body loop
Scope_Node := Parent (Scope_Node);
end loop;
-- and to continue to search in the package body:
List_To_Search := Sinfo.Declarations (Scope_Node);
if not (No (List_To_Search)
or else Is_Empty_List (List_To_Search))
then
Search_Node := First_Non_Pragma (List_To_Search);
Search_In_List;
end if;
end if;
<< end_of_search >>
return Result_Node;
end Get_Renaming_As_Body;
-----------------------
-- Serach_First_View --
-----------------------
function Serach_First_View (Type_Entity : Entity_Id) return Entity_Id is
Type_Chars : constant Name_Id := Chars (Type_Entity);
Type_Decl : constant Node_Id := Parent (Type_Entity);
Result_Node : Node_Id := Empty;
Scope_Node : Node_Id;
Scope_Kind : Node_Kind;
Search_List : List_Id;
Private_Decls_Passed : Boolean := False;
procedure Sesrch_In_List (L : List_Id);
-- we have a separate procedure for searching in a list of
-- declarations, because we have to do this search from one to
-- three times in case of a package. This procedure uses Type_Chars,
-- Type_Decl and Result_Node as global values, and it sets
-- Result_Node equal to the node defining the type with the same name
-- as the name of the type represented by Type_Entity, if the
-- search is successful, otherwise it remains is equal to Empty.
-- this procedure supposes, that L is not No_List
procedure Sesrch_In_List (L : List_Id) is
Next_Decl : Node_Id;
Next_Decl_Original : Node_Id;
Next_Kind : Node_Kind;
begin
Next_Decl := First_Non_Pragma (L);
Next_Decl_Original := Original_Node (Next_Decl);
Next_Kind := Nkind (Next_Decl_Original);
while Present (Next_Decl) loop
if (Comes_From_Source (Next_Decl_Original)
and then
(Next_Kind = N_Full_Type_Declaration or else
Next_Kind = N_Task_Type_Declaration or else
Next_Kind = N_Protected_Type_Declaration or else
Next_Kind = N_Private_Type_Declaration or else
Next_Kind = N_Private_Extension_Declaration or else
Next_Kind = N_Formal_Type_Declaration or else
-- impossible in ASIS, but possible in the tree
-- because of the tree rewritings
Next_Kind = N_Incomplete_Type_Declaration))
-- these cases correspond to non-rewritten type
-- declarations
or else
(not (Comes_From_Source (Next_Decl_Original))
and then
Next_Kind = N_Subtype_Declaration)
-- the declaration of a derived type rewritten into a
-- subtype declaration
then
if Is_Not_Duplicated_Decl (Next_Decl) then
-- ??? <tree problem 2> - we need this "if" only because of this problem
if Next_Decl_Original = Type_Decl then
-- no private or incomplete view
Result_Node := Type_Entity;
return;
end if;
if Type_Chars = Chars (Defining_Identifier (Next_Decl)) then
-- we've found something...
Result_Node := Defining_Identifier (Next_Decl);
return;
end if;
end if;
end if;
Next_Decl := Next_Non_Pragma (Next_Decl);
Next_Decl_Original := Original_Node (Next_Decl);
Next_Kind := Nkind (Next_Decl_Original);
end loop;
end Sesrch_In_List;
begin -- Serach_First_View
-- first, defining the scope of the Type_Entity. In case of a package
-- body it will be a package spec anyway.
Scope_Node := Scope (Type_Entity);
if Nkind (Parent (Scope_Node)) = N_Implicit_Label_Declaration then
-- this is the implicit name created for a block statement
Scope_Node := Parent (Block_Node (Scope_Node));
else
Scope_Node := Parent (Scope_Node);
end if;
if Nkind (Scope_Node) = N_Defining_Program_Unit_Name then
Scope_Node := Parent (Scope_Node);
end if;
-- now we are in N_Function_Specification, N_Procedure_Specification
-- or in N_Package_Specification
Scope_Kind := Nkind (Scope_Node);
if Scope_Kind = N_Function_Specification or else
Scope_Kind = N_Procedure_Specification
then
-- we do not do this additional step for packages, because
-- N_Package_Specification_Node already contains references to
-- declaration lists, and for a package we gave to start from the
-- declarations in the package spec, but for a subprogram
-- we have to go to a subprogram body, because nothing interesting
-- for this function can be declared in a separate subprogram
-- specification (if any) or in a generic formal part (if any)
Scope_Node := Parent (Scope_Node);
Scope_Kind := Nkind (Scope_Node);
end if;
if Scope_Kind = N_Subprogram_Declaration
or else
Scope_Kind = N_Generic_Subprogram_Declaration
or else
Scope_Kind = N_Task_Type_Declaration
or else
Scope_Kind = N_Entry_Declaration
or else
Scope_Kind = N_Subprogram_Body_Stub
then
Scope_Node := Corresponding_Body (Scope_Node);
Scope_Node := Parent (Scope_Node);
if Nkind (Scope_Node) = N_Defining_Program_Unit_Name then
Scope_Node := Parent (Scope_Node);
end if;
if Nkind (Scope_Node) = N_Function_Specification or else
Nkind (Scope_Node) = N_Procedure_Specification
then
Scope_Node := Parent (Scope_Node);
end if;
Scope_Kind := Nkind (Scope_Node);
end if;
-- now, defining the list to search. In case of generics, we do not
-- have to start from parsing the list of generic parameters, because
-- a generic formal type cannot have a completion as its full view,
-- and it cannot be a completion of some other type.
if Scope_Kind = N_Subprogram_Body or else
Scope_Kind = N_Task_Body or else
Scope_Kind = N_Block_Statement or else
Scope_Kind = N_Entry_Body
then
Search_List := Sinfo.Declarations (Scope_Node);
elsif Scope_Kind = N_Package_Specification then
Search_List := Visible_Declarations (Scope_Node);
if Is_Empty_List (Search_List) then
-- note, that Visible_Declarations cannot be No_List
Private_Decls_Passed := True;
Search_List := Private_Declarations (Scope_Node);
if No (Search_List) or else Is_Empty_List (Search_List) then
-- here we should go to the declarative part of the package
-- body. Note, that if we are in a legal ada program, and if
-- we start from a type declaration, Search_List cannot
-- be No_List or an empty list
Scope_Node := Parent (Corresponding_Body (Parent (Scope_Node)));
-- note, that Search_Kind is unchanged here
Search_List := Sinfo.Declarations (Scope_Node);
end if;
end if;
end if;
Sesrch_In_List (Search_List);
if Result_Node /= Empty then
if Result_Node /= Type_Entity and then
Full_View (Result_Node) /= Type_Entity
then
-- The case when Type_Entity is a full type declaration that
-- completes a private type/extension declaration that in turn
-- completes an incomplete type.
Result_Node := Full_View (Result_Node);
end if;
return Result_Node;
end if;
-- it is possible only for a package - we have to continue in the
-- private part or/and in the body
pragma Assert (Scope_Kind = N_Package_Specification);
-- first, try a private part, if needed and if any
if not Private_Decls_Passed then
-- Scope_Node is still of N_Package_Specification kind here!
Private_Decls_Passed := True;
Search_List := Private_Declarations (Scope_Node);
if Present (Search_List) and then Is_Non_Empty_List (Search_List) then
Sesrch_In_List (Search_List);
if Result_Node /= Empty then
return Result_Node;
end if;
end if;
end if;
-- if we are here, Scope_Node is still of N_Package_Specification,
-- and the only thing we have to do now is to check the package
-- body
-- There is some redundancy in the code - in fact, we need only
-- one boolean flag (Private_Decls_Passed) to control the search in
-- case of a package
Scope_Node := Parent (Corresponding_Body (Parent (Scope_Node)));
if Nkind (Scope_Node) = N_Defining_Program_Unit_Name then
Scope_Node := Parent (Scope_Node);
end if;
Search_List := Sinfo.Declarations (Scope_Node);
Sesrch_In_List (Search_List);
if Result_Node /= Empty then
return Result_Node;
else
pragma Assert (False);
return Empty;
end if;
end Serach_First_View;
end A4G.Decl_Sem;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
stcarrez/dynamo,stcarrez/dynamo,stcarrez/dynamo
|
|
26ed1ef0aa7c7edba7a4c2eec2f6b65121d07252
|
awa/plugins/awa-mail/src/aws/awa-mail-clients-aws_smtp-initialize_ssl.adb
|
awa/plugins/awa-mail/src/aws/awa-mail-clients-aws_smtp-initialize_ssl.adb
|
-----------------------------------------------------------------------
-- awa-mail-clients-aws_smtp-initialize -- Initialize SMTP client with SSL support
-- Copyright (C) 2016 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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.
-----------------------------------------------------------------------
separate (AWA.Mail.Clients.AWS_SMTP)
procedure Initialize (Client : in out AWS_Mail_Manager'Class;
Props : in Util.Properties.Manager'Class) is
Server : constant String := Props.Get (Name => "smtp.host", Default => "localhost");
User : constant String := Props.Get (Name => "smtp.user", Default => "");
Passwd : constant String := Props.Get (Name => "smtp.password", Default => "");
Secure : constant String := Props.Get (Name => "smtp.ssl", Default => "0");
begin
Client.Secure := Secure = "1" or Secure = "yes" or Secure = "true";
if User'Length > 0 then
Client.Creds := AWS.SMTP.Authentication.Plain.Initialize (User, Passwd);
Client.Server := AWS.SMTP.Client.Initialize (Server_Name => Server,
Port => Client.Port,
Secure => Client.Secure,
Credential => Client.Creds'Access);
else
Client.Server := AWS.SMTP.Client.Initialize (Server_Name => Server,
Port => Client.Port,
Secure => Client.Secure);
end if;
end Initialize;
|
Implement the Initialize procedure with SSL support (AWS version starting from gnat-2015)
|
Implement the Initialize procedure with SSL support (AWS version starting from gnat-2015)
|
Ada
|
apache-2.0
|
stcarrez/ada-awa,stcarrez/ada-awa,stcarrez/ada-awa,stcarrez/ada-awa
|
|
4333b1bcaa297968d1e17d9ac7be13ee055e76ce
|
regtests/check_build/gen-tests-packages.ads
|
regtests/check_build/gen-tests-packages.ads
|
-----------------------------------------------------------------------
-- Test -- Test the code generation
-- Copyright (C) 2012 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 Gen.Tests.Packages is
end Gen.Tests.Packages;
|
Add the package to build the generated Ada packages (UML packages test)
|
Add the package to build the generated Ada packages (UML packages test)
|
Ada
|
apache-2.0
|
Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen
|
|
c7d6150e56b133ee6a44ff5f5beea417bd238e77
|
src/wiki-streams-html-stream.adb
|
src/wiki-streams-html-stream.adb
|
-----------------------------------------------------------------------
-- wiki-streams-html-stream -- Generic Wiki HTML output stream
-- Copyright (C) 2016, 2020 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 Wiki.Streams.Html.Stream is
-- Close the current XML entity if an entity was started
procedure Close_Current (Stream : in out Html_Output_Stream'Class);
-- ------------------------------
-- Close the current XML entity if an entity was started
-- ------------------------------
procedure Close_Current (Stream : in out Html_Output_Stream'Class) is
begin
if Stream.Close_Start then
Stream.Write ('>');
Stream.Close_Start := False;
end if;
end Close_Current;
-- ------------------------------
-- Write the string to the stream.
-- ------------------------------
procedure Write_String (Stream : in out Html_Output_Stream'Class;
Content : in String) is
begin
for I in Content'Range loop
Stream.Write (Wiki.Strings.To_WChar (Content (I)));
end loop;
end Write_String;
-- ------------------------------
-- Write an XML attribute within an XML element.
-- The attribute value is escaped according to the XML escape rules.
-- ------------------------------
overriding
procedure Write_Wide_Attribute (Stream : in out Html_Output_Stream;
Name : in String;
Content : in Wiki.Strings.UString) is
begin
if Stream.Close_Start then
Html.Write_Escape_Attribute (Stream, Name, Wiki.Strings.To_WString (Content));
end if;
end Write_Wide_Attribute;
-- ------------------------------
-- Write an XML attribute within an XML element.
-- The attribute value is escaped according to the XML escape rules.
-- ------------------------------
overriding
procedure Write_Wide_Attribute (Stream : in out Html_Output_Stream;
Name : in String;
Content : in Wide_Wide_String) is
begin
if Stream.Close_Start then
Stream.Write_Escape_Attribute (Name, Content);
end if;
end Write_Wide_Attribute;
-- ------------------------------
-- Start an XML element with the given name.
-- ------------------------------
overriding
procedure Start_Element (Stream : in out Html_Output_Stream;
Name : in String) is
begin
Close_Current (Stream);
Stream.Write ('<');
Stream.Write_String (Name);
Stream.Close_Start := True;
end Start_Element;
-- ------------------------------
-- Closes an XML element of the given name.
-- ------------------------------
overriding
procedure End_Element (Stream : in out Html_Output_Stream;
Name : in String) is
begin
if Stream.Close_Start then
Stream.Write (" />");
Stream.Close_Start := False;
else
Close_Current (Stream);
Stream.Write ("</");
Stream.Write_String (Name);
Stream.Write ('>');
end if;
end End_Element;
-- ------------------------------
-- Write a text escaping any character as necessary.
-- ------------------------------
overriding
procedure Write_Wide_Text (Stream : in out Html_Output_Stream;
Content : in Wiki.Strings.WString) is
begin
Close_Current (Stream);
Stream.Write_Escape (Content);
end Write_Wide_Text;
end Wiki.Streams.Html.Stream;
|
Refactor the HTML Text_IO into a generic package
|
Refactor the HTML Text_IO into a generic package
|
Ada
|
apache-2.0
|
stcarrez/ada-wiki,stcarrez/ada-wiki
|
|
efc53985b50750e6e4650d892321cd6a9ca2ba84
|
awa/plugins/awa-comments/src/awa-comments-beans.adb
|
awa/plugins/awa-comments/src/awa-comments-beans.adb
|
-----------------------------------------------------------------------
-- awa-comments-beans -- Beans for the comments module
-- Copyright (C) 2014 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 ADO.Sessions.Entities;
with ADO.Queries;
with ADO.Statements;
package body AWA.Comments.Beans is
-- ------------------------------
-- Set the value identified by the name.
-- If the name cannot be found, the method should raise the No_Value
-- exception.
-- ------------------------------
overriding
procedure Set_Value (From : in out Comment_List_Bean;
Name : in String;
Value : in Util.Beans.Objects.Object) is
begin
if Name = "entity_type" then
From.Entity_Type := Util.Beans.Objects.To_Unbounded_String (Value);
elsif Name = "permission" then
From.Permission := Util.Beans.Objects.To_Unbounded_String (Value);
end if;
end Set_Value;
-- ------------------------------
-- Set the entity type (database table) with which the comments are associated.
-- ------------------------------
procedure Set_Entity_Type (Into : in out Comment_List_Bean;
Table : in ADO.Schemas.Class_Mapping_Access) is
begin
Into.Entity_Type := Ada.Strings.Unbounded.To_Unbounded_String (Table.Table.all);
end Set_Entity_Type;
-- ------------------------------
-- Set the permission to check before removing or adding a comment on the entity.
-- ------------------------------
procedure Set_Permission (Into : in out Comment_List_Bean;
Permission : in String) is
begin
Into.Permission := Ada.Strings.Unbounded.To_Unbounded_String (Permission);
end Set_Permission;
-- ------------------------------
-- Load the comments associated with the given database identifier.
-- ------------------------------
procedure Load_Comments (Into : in out Comment_List_Bean;
Session : in ADO.Sessions.Session;
For_Entity_Id : in ADO.Identifier) is
use ADO.Sessions.Entities;
Entity_Type : constant String := Ada.Strings.Unbounded.To_String (Into.Entity_Type);
Kind : constant ADO.Entity_Type := Find_Entity_Type (Session, Entity_Type);
Query : ADO.Queries.Context;
begin
Query.Set_Query (AWA.Comments.Models.Query_Comment_List);
Query.Bind_Param ("entity_type", Kind);
Query.Bind_Param ("entity_id", For_Entity_Id);
declare
Stmt : ADO.Statements.Query_Statement := Session.Create_Statement (Query);
begin
Stmt.Execute;
while Stmt.Has_Elements loop
Into.List.Append (Util.Beans.Objects.To_Object (Stmt.Get_String (0)));
Stmt.Next;
end loop;
end;
end Load_Comments;
-- ------------------------------
-- Create the comment list bean instance.
-- ------------------------------
function Create_Comment_List_Bean (Module : in AWA.Comments.Modules.Comment_Module_Access)
return Util.Beans.Basic.Readonly_Bean_Access is
Result : constant Comment_List_Bean_Access := new Comment_List_Bean;
begin
Result.Module := Module;
return Result.all'Access;
end Create_Comment_List_Bean;
end AWA.Comments.Beans;
|
Implement the Comment_List_Bean type operations
|
Implement the Comment_List_Bean type operations
|
Ada
|
apache-2.0
|
stcarrez/ada-awa,stcarrez/ada-awa,stcarrez/ada-awa,stcarrez/ada-awa
|
|
1d3e25c4612e641b9159cae7c9a0204f093447b6
|
src/asis/asis-extensions-iterator.adb
|
src/asis/asis-extensions-iterator.adb
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A S I S . E X T E N S I O N S . I T E R A T O R --
-- --
-- B o d y --
-- --
-- Copyright (c) 2003-2006, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
with Asis.Compilation_Units; use Asis.Compilation_Units;
with Asis.Elements; use Asis.Elements;
with Asis.Errors; use Asis.Errors;
with Asis.Exceptions; use Asis.Exceptions;
with Asis.Iterator; use Asis.Iterator;
with A4G.Vcheck; use A4G.Vcheck;
package body Asis.Extensions.Iterator is
Package_Name : constant String := "Asis.Extensions.Iterator.";
-------------------
-- Traverse_Unit --
-------------------
procedure Traverse_Unit
(Unit : Asis.Compilation_Unit;
Control : in out Traverse_Control;
State : in out State_Information)
is
Arg_Kind : constant Unit_Kinds := Unit_Kind (Unit);
procedure Process_Element is new Asis.Iterator.Traverse_Element
(State_Information => State_Information,
Pre_Operation => Pre_Operation,
Post_Operation => Post_Operation);
begin
Check_Validity (Unit, Package_Name & "Control");
if not (Arg_Kind in A_Procedure .. A_Protected_Body_Subunit) then
Raise_ASIS_Inappropriate_Compilation_Unit
(Package_Name & "Traverse_Unit");
end if;
declare
Cont_Clause_Elements : constant Element_List :=
Asis.Elements.Context_Clause_Elements
(Compilation_Unit => Unit,
Include_Pragmas => True);
Unit_Element : constant Asis.Element :=
Asis.Elements.Unit_Declaration (Unit);
begin
for I in Cont_Clause_Elements'Range loop
Process_Element (Cont_Clause_Elements (I), Control, State);
end loop;
Process_Element (Unit_Element, Control, State);
end;
exception
when ASIS_Inappropriate_Compilation_Unit =>
raise;
when ASIS_Inappropriate_Context |
ASIS_Inappropriate_Container |
ASIS_Inappropriate_Element |
ASIS_Inappropriate_Line |
ASIS_Inappropriate_Line_Number =>
Add_Call_Information (Outer_Call => Package_Name & "Traverse_Unit");
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Traverse_Unit");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Traverse_Unit",
Ex => Ex,
Arg_CU => Unit);
end Traverse_Unit;
end Asis.Extensions.Iterator;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen,Letractively/ada-gen
|
|
0f3689fec59c8fb0e7a21d9183dc1799ba297e19
|
build/gnat/rts/common/adainclude/s-parame.ads
|
build/gnat/rts/common/adainclude/s-parame.ads
|
-- -*- Mode: Ada -*-
-- Filename : s-parame.ads
-- Description : Custom package.
-- Author : Luke A. Guest
-- Created On : Thur Nov 17 17:52:04 2016
-- Licence : See LICENCE in the root directory.
package System.Parameters is
pragma Pure;
----------------------------------------------
-- Characteristics of types in Interfaces.C --
----------------------------------------------
long_bits : constant := Long_Integer'Size;
-- Number of bits in type long and unsigned_long. The normal convention
-- is that this is the same as type Long_Integer, but this is not true
-- of all targets. For example, in OpenVMS long /= Long_Integer.
ptr_bits : constant := Standard'Address_Size;
subtype C_Address is System.Address;
-- Number of bits in Interfaces.C pointers, normally a standard address,
-- except on 64-bit VMS where they are 32-bit addresses, for compatibility
-- with legacy code.
end System.Parameters;
|
Add custom System.Parameters package.
|
Add custom System.Parameters package.
|
Ada
|
cc0-1.0
|
Lucretia/bare_bones
|
|
68b6898995e461a39bcb7edfa212a2b394bba929
|
src/security-auth-oauth-facebook.ads
|
src/security-auth-oauth-facebook.ads
|
-----------------------------------------------------------------------
-- security-auth-oauth-facebook -- Facebook OAuth based authentication
-- Copyright (C) 2013 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 Security.OAuth.Clients;
package Security.Auth.OAuth.Facebook is
-- ------------------------------
-- OAuth Manager
-- ------------------------------
-- The <b>Manager</b> provides the core operations for the OAuth authorization process.
type Manager is new Security.Auth.OAuth.Manager with private;
-- Verify the OAuth access token and retrieve information about the user.
overriding
procedure Verify_Access_Token (Realm : in Manager;
Assoc : in Association;
Request : in Parameters'Class;
Token : in Security.OAuth.Clients.Access_Token_Access;
Result : in out Authentication);
private
type Manager is new Security.Auth.OAuth.Manager with null record;
end Security.Auth.OAuth.Facebook;
|
Define the Facebook authentication by using OAuth and Facebook Graph API
|
Define the Facebook authentication by using OAuth and Facebook Graph API
|
Ada
|
apache-2.0
|
stcarrez/ada-security
|
|
0fb91254d56bbf2d5930942952ec4bbd3d20d0cc
|
regtests/gen-artifacts-yaml-tests.adb
|
regtests/gen-artifacts-yaml-tests.adb
|
-----------------------------------------------------------------------
-- gen-artifacts-yaml-tests -- Tests for YAML model files
-- Copyright (C) 2018 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 Util.Test_Caller;
with Gen.Configs;
with Gen.Generator;
package body Gen.Artifacts.Yaml.Tests is
use Ada.Strings.Unbounded;
package Caller is new Util.Test_Caller (Test, "Gen.Yaml");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test Gen.Yaml.Read_Model",
Test_Read_Yaml'Access);
end Add_Tests;
-- ------------------------------
-- Test reading the YAML files defines in regression tests.
-- ------------------------------
procedure Test_Read_Yaml (T : in out Test) is
A : Artifact;
G : Gen.Generator.Handler;
C : constant String := Util.Tests.Get_Parameter ("config_dir", "config");
Path : constant String := Util.Tests.Get_Path ("regtests/files/users.yaml");
Model : Gen.Model.Packages.Model_Definition;
Iter : Gen.Model.Packages.Package_Cursor;
Cnt : Natural := 0;
begin
Gen.Generator.Initialize (G, Ada.Strings.Unbounded.To_Unbounded_String (C), False);
A.Read_Model (Path, Model, G);
Iter := Model.First;
while Gen.Model.Packages.Has_Element (Iter) loop
Cnt := Cnt + 1;
Gen.Model.Packages.Next (Iter);
end loop;
Util.Tests.Assert_Equals (T, 1, Cnt, "Missing some packages");
end Test_Read_Yaml;
end Gen.Artifacts.Yaml.Tests;
|
Add test for YAML model support
|
Add test for YAML model support
|
Ada
|
apache-2.0
|
stcarrez/dynamo,stcarrez/dynamo,stcarrez/dynamo
|
|
38d9be567574e1621cc0fe2aded54f347cac313c
|
src/babel-streams-files.adb
|
src/babel-streams-files.adb
|
-----------------------------------------------------------------------
-- babel-streams-files -- Local file stream management
-- Copyright (C) 2014, 2015 Stephane.Carrez
-- Written by Stephane.Carrez ([email protected])
--
-- 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 Interfaces.C.Strings;
with Ada.Streams;
with Util.Systems.Os;
with Util.Systems.Constants;
package body Babel.Streams.Files is
use type Interfaces.C.int;
-- ------------------------------
-- Open the local file for reading and use the given buffer for the Read operation.
-- ------------------------------
procedure Open (Stream : in out Stream_Type;
Path : in String;
Buffer : in Babel.Files.Buffers.Buffer_Access) is
Name : Interfaces.C.Strings.chars_ptr := Interfaces.C.Strings.New_String (Path);
Fd : Util.Systems.Os.File_Type;
begin
Fd := Util.Systems.Os.Sys_Open (Path => Name,
Flags => Util.Systems.Constants.O_RDONLY,
Mode => 0);
Interfaces.C.Strings.Free (Name);
Stream.Buffer := Buffer;
Stream.File.Initialize (File => Fd);
end Open;
-- ------------------------------
-- Create a file and prepare for the Write operation.
-- ------------------------------
procedure Create (Stream : in out Stream_Type;
Path : in String;
Mode : in Util.Systems.Types.mode_t) is
Name : Interfaces.C.Strings.chars_ptr := Interfaces.C.Strings.New_String (Path);
Fd : Util.Systems.Os.File_Type;
begin
Fd := Util.Systems.Os.Sys_Open (Path => Name,
Flags => Util.Systems.Constants.O_WRONLY
+ Util.Systems.Constants.O_CREAT
+ Util.Systems.Constants.O_TRUNC,
Mode => Interfaces.C.int (Mode));
Interfaces.C.Strings.Free (Name);
Stream.Buffer := null;
Stream.File.Initialize (File => Fd);
end Create;
-- ------------------------------
-- Read the data stream as much as possible and return the result in a buffer.
-- The buffer is owned by the stream and need not be released. The same buffer may
-- or may not be returned by the next <tt>Read</tt> operation.
-- A null buffer is returned when the end of the data stream is reached.
-- ------------------------------
overriding
procedure Read (Stream : in out Stream_Type;
Buffer : out Babel.Files.Buffers.Buffer_Access) is
use type Ada.Streams.Stream_Element_Offset;
begin
if Stream.Eof then
Buffer := null;
else
Stream.File.Read (Stream.Buffer.Data, Stream.Buffer.Last);
if Stream.Buffer.Last < Stream.Buffer.Data'First then
Buffer := null;
else
Buffer := Stream.Buffer;
end if;
Stream.Eof := Stream.Buffer.Last < Stream.Buffer.Data'Last;
end if;
end Read;
-- ------------------------------
-- Write the buffer in the data stream.
-- ------------------------------
overriding
procedure Write (Stream : in out Stream_Type;
Buffer : in Babel.Files.Buffers.Buffer_Access) is
begin
Stream.File.Write (Buffer.Data (Buffer.Data'First .. Buffer.Last));
end Write;
-- ------------------------------
-- Close the data stream.
-- ------------------------------
overriding
procedure Close (Stream : in out Stream_Type) is
begin
Stream.File.Close;
end Close;
-- ------------------------------
-- Prepare to read again the data stream from the beginning.
-- ------------------------------
overriding
procedure Rewind (Stream : in out Stream_Type) is
begin
null;
end Rewind;
end Babel.Streams.Files;
|
Implement the stream reading/writing on raw files
|
Implement the stream reading/writing on raw files
|
Ada
|
apache-2.0
|
stcarrez/babel
|
|
8ababa1ca39b8d8a902e7b931064abcd3bdd67fc
|
samples/escape.adb
|
samples/escape.adb
|
-----------------------------------------------------------------------
-- escape -- Text Transformations
-- Copyright (C) 2001, 2002, 2003, 2006, 2008, 2009, 2010 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Strings.Transforms;
with Ada.Strings.Unbounded;
with Ada.Text_IO;
with Ada.Command_Line;
procedure Escape is
use Ada.Strings.Unbounded;
Count : constant Natural := Ada.Command_Line.Argument_Count;
begin
if Count = 0 then
Ada.Text_IO.Put_Line ("Usage: escape string...");
return;
end if;
for I in 1 .. Count loop
declare
S : constant String := Ada.Command_Line.Argument (I);
begin
Ada.Text_IO.Put_Line ("Escape javascript : "
& Util.Strings.Transforms.Escape_Javascript (S));
Ada.Text_IO.Put_Line ("Escape XML : "
& Util.Strings.Transforms.Escape_Xml (S));
end;
end loop;
end Escape;
|
Add simple example for text transformations
|
Add simple example for text transformations
|
Ada
|
apache-2.0
|
stcarrez/ada-util,stcarrez/ada-util
|
|
4a7c7b2ebb469fc3e1e8b42dec81d1f946dd71d7
|
src/asis/a4g-a_elists.ads
|
src/asis/a4g-a_elists.ads
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . A _ E L I S T S --
-- --
-- S p e c --
-- --
-- Copyright (C) 1995-2007, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adaccore.com). --
-- --
------------------------------------------------------------------------------
-- This package is a modification of the GNAT Elists package, which
-- provides facilities for manipulating lists of AST nodes (see the GNAT
-- package Atree for format and implementation of tree nodes).
--
-- The following modifications of the GNAT Elists package (revision 1.13-spec
-- and 1.19 body) are made here:
--
-- 1. List type: for multiple Context processing, ASIS needs a list type to
-- represent unit lists specific for each Context. To make it possible to
-- simulate the element list type by the Saved_Table type provided by the
-- GNAT Table package, the instantiations of the GNAT Table which
-- implements element lists in the ASIS lists package are moved from
-- the body into the spec.
--
-- 2. List element type: ASIS needs lists of ASIS Compilation Units to be
-- processed as a part of the ASIS Context implementation. Therefore the
-- GNAT Node_Id type is systematically replaced by the ASIS Unit_Id type,
-- and the Node function is renamed into the Unit function
--
-- 3. Removing non-needed subprograms - the following subprograms defined in
-- the GNAT Elists package are of no need for ASIS lists. They are removed
-- from the ASIS list package:
-- procedure Lock
-- procedure Tree_Read
-- procedure Tree_Write
-- function Elists_Address
-- function Elmts_Address
--
-- 4. Adding subprograms for ASIS needs - they are grouped in the end of the
-- package spec after the corresponding comment separator
--
-- 5. Removing Inline pragmas: in the current version of the ASIS lists
-- package all the Inline pragnas are removed
--
-- 6. Adjusting documentation: some minor and natural adjustments in the
-- documentation has been done
with Table;
with Alloc;
with Types; use Types;
with A4G.A_Types; use A4G.A_Types;
package A4G.A_Elists is
-- An element list is represented by a header that is allocated in the
-- Elist header table. This header contains pointers to the first and
-- last elements in the list, or to No_Elmt if the list is empty.
-----------------------------------------------------
-- Subprograms coming from the GNAT Elists package --
-----------------------------------------------------
procedure Initialize;
-- Initialize allocation of element list tables. Called at the start of
-- compiling each new main source file. Note that Initialize must not be
-- called if Tree_Read is used.
function Last_Elist_Id return Elist_Id;
-- Returns Id of last allocated element list header
function Num_Elists return Nat;
-- Number of currently allocated element lists
function Last_Elmt_Id return Elmt_Id;
-- Returns Id of last allocated list element
function Unit (Elmt : Elmt_Id) return Unit_Id;
-- Returns the value of a given list element. Returns Empty if Elmt
-- is set to No_Elmt.
function New_Elmt_List return Elist_Id;
-- Creates a new empty element list. Typically this is used to initialize
-- a field in some other node which points to an element list where the
-- list is then subsequently filled in using Append calls.
function First_Elmt (List : Elist_Id) return Elmt_Id;
-- Obtains the first element of the given element list or, if the
-- list has no items, then No_Elmt is returned.
function Last_Elmt (List : Elist_Id) return Elmt_Id;
-- Obtains the last element of the given element list or, if the
-- list has no items, then No_Elmt is returned.
function Next_Elmt (Elmt : Elmt_Id) return Elmt_Id;
-- This function returns the next element on an element list. The argument
-- must be a list element other than No_Elmt. Returns No_Elmt if the given
-- element is the last element of the list.
function Is_Empty_Elmt_List (List : Elist_Id) return Boolean;
-- This function determines if a given tree id references an element list
-- that contains no items.
procedure Append_Elmt (Unit : Unit_Id; To : Elist_Id);
-- Appends Unit at the end of To, allocating a new element.
procedure Prepend_Elmt (Unit : Unit_Id; To : Elist_Id);
-- Appends Unit at the beginning of To, allocating a new element.
procedure Insert_Elmt_After (Unit : Unit_Id; Elmt : Elmt_Id);
-- Add a new element (Unit) right after the pre-existing element Elmt
-- It is invalid to call this subprogram with Elmt = No_Elmt.
procedure Replace_Elmt (Elmt : Elmt_Id; New_Unit : Unit_Id);
-- Causes the given element of the list to refer to New_Unit, the node
-- which was previously referred to by Elmt is effectively removed from
-- the list and replaced by New_Unit.
procedure Remove_Elmt (List : Elist_Id; Elmt : Elmt_Id);
-- Removes Elmt from the given list. The node itself is not affected,
-- but the space used by the list element may be (but is not required
-- to be) freed for reuse in a subsequent Append_Elmt call.
procedure Remove_Last_Elmt (List : Elist_Id);
-- Removes the last element of the given list. The node itself is not
-- affected, but the space used by the list element may be (but is not
-- required to be) freed for reuse in a subsequent Append_Elmt call.
function No (List : Elist_Id) return Boolean;
-- Tests given Id for equality with No_Elist. This allows notations like
-- "if No (Statements)" as opposed to "if Statements = No_Elist".
function Present (List : Elist_Id) return Boolean;
-- Tests given Id for inequality with No_Elist. This allows notations like
-- "if Present (Statements)" as opposed to "if Statements /= No_Elist".
function No (Elmt : Elmt_Id) return Boolean;
-- Tests given Id for equality with No_Elmt. This allows notations like
-- "if No (Operation)" as opposed to "if Operation = No_Elmt".
function Present (Elmt : Elmt_Id) return Boolean;
-- Tests given Id for inequality with No_Elmt. This allows notations like
-- "if Present (Operation)" as opposed to "if Operation /= No_Elmt".
--------------------------------------
-- Subprograms added for ASIS needs --
--------------------------------------
procedure Add_To_Elmt_List (Unit : Unit_Id; List : in out Elist_Id);
-- If List is equial to No_Lists, creates the new (empty) list, assigns
-- it to List and appens Unit to this list. Otherwise, checks, if Unit
-- already is in List, and if the check fails, appends Unit to List.
--
-- This procedure is intended to be used during creating the dependency
-- lists for a Unit.
function In_Elmt_List (U : Unit_Id; List : Elist_Id) return Boolean;
-- Checks if Unit is included in the given List. Returns False for
-- No_List and for empty list.
procedure Print_List (List : Elist_Id);
-- Currently this procedure only produces the debug output for List
function List_Length (List : Elist_Id) return Natural;
-- Returns the number of items in the given list. It is an error to call
-- this function with No_Elist.
function Intersect (List1 : Elist_Id; List2 : Elist_Id) return Boolean;
-- Checks if List1 and List2 have a common data element (that is, if
-- one of them is No_List or empty element list, False is returned).
function Belongs (List1 : Elist_Id; List2 : Elist_Id) return Boolean;
-- Checks if all the elements of List1 belongs to List2. If List1 is
-- equial to No_List, returns True
procedure Move_List
(List_From : Elist_Id;
List_To : in out Elist_Id);
-- Moves (prepends) the content of List_From to List_To. If List_To is
-- equial to No_Elist, it is created. For now, this procedure does not
-- check if the elements from List_From are already in List_To, therefore
-- as a result of a call to this procedure, List_To can contain
-- duplicated elements
--
-- If before the call List_From was equal to No_List, it will be No_List
-- after the call. In any other case List_From will be an empty list after
-- the call
-------------------------------------
-- Implementation of Element Lists --
-------------------------------------
-- Element lists are composed of three types of entities. The element
-- list header, which references the first and last elements of the
-- list, the elements themselves which are singly linked and also
-- reference the nodes on the list, and finally the nodes themselves.
-- The following diagram shows how an element list is represented:
-- +----------------------------------------------------+
-- | +------------------------------------------+ |
-- | | | |
-- V | V |
-- +-----|--+ +-------+ +-------+ +-------+ |
-- | Elmt | | 1st | | 2nd | | Last | |
-- | List |--->| Elmt |--->| Elmt ---...-->| Elmt ---+
-- | Header | | | | | | | | | |
-- +--------+ +---|---+ +---|---+ +---|---+
-- | | |
-- V V V
-- +-------+ +-------+ +-------+
-- | | | | | |
-- | Unit1 | | Unit2 | | Unit3 |
-- | | | | | |
-- +-------+ +-------+ +-------+
-- The list header is an entry in the Elists table. The values used for
-- the type Elist_Id are subscripts into this table. The First_Elmt field
-- (Lfield1) points to the first element on the list, or to No_Elmt in the
-- case of an empty list. Similarly the Last_Elmt field (Lfield2) points to
-- the last element on the list or to No_Elmt in the case of an empty list.
-- The elements themselves are entries in the Elmts table. The Next field
-- of each entry points to the next element, or to the Elist header if this
-- is the last item in the list. The Unit field points to the node which
-- is referenced by the corresponding list entry.
--------------------------
-- Element List Tables --
--------------------------
type Elist_Header is record
First : Elmt_Id;
Last : Elmt_Id;
end record;
package Elists is new Table.Table (
Table_Component_Type => Elist_Header,
Table_Index_Type => Elist_Id,
Table_Low_Bound => First_Elist_Id,
Table_Initial => Alloc.Elists_Initial,
Table_Increment => Alloc.Elists_Increment,
Table_Name => "Elists");
type Elmt_Item is record
Unit : Unit_Id;
Next : Union_Id;
end record;
package Elmts is new Table.Table (
Table_Component_Type => Elmt_Item,
Table_Index_Type => Elmt_Id,
Table_Low_Bound => First_Elmt_Id,
Table_Initial => Alloc.Elmts_Initial,
Table_Increment => Alloc.Elmts_Increment,
Table_Name => "Elmts");
type Saved_Lists is record
Saved_Elmts : Elmts.Saved_Table;
Saved_Elists : Elists.Saved_Table;
end record;
end A4G.A_Elists;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
stcarrez/dynamo,stcarrez/dynamo,stcarrez/dynamo
|
|
5c024f1dee98004b825686a6331fba5ccd0f8b21
|
regtests/util-streams-buffered-encoders-tests.adb
|
regtests/util-streams-buffered-encoders-tests.adb
|
-----------------------------------------------------------------------
-- util-streams-buffered-encoders-tests -- Unit tests for encoding buffered streams
-- Copyright (C) 2017 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Test_Caller;
with Util.Streams.Files;
with Util.Streams.Texts;
with Util.Files;
with Ada.Streams.Stream_IO;
package body Util.Streams.Buffered.Encoders.Tests is
use Util.Tests;
use Util.Streams.Files;
use Ada.Streams.Stream_IO;
package Caller is new Util.Test_Caller (Test, "Streams.Buffered.Encoders");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test Util.Streams.Buffered.Encoders.Write, Read",
Test_Base64_Stream'Access);
end Add_Tests;
procedure Test_Base64_Stream (T : in out Test) is
Stream : aliased File_Stream;
Buffer : aliased Util.Streams.Buffered.Encoders.Encoding_Stream;
Print : Util.Streams.Texts.Print_Stream;
Path : constant String := Util.Tests.Get_Test_Path ("regtests/result/test-stream.b64");
Expect : constant String := Util.Tests.Get_Path ("regtests/expect/test-stream.b64");
begin
Print.Initialize (Output => Buffer'Unchecked_Access, Size => 5);
Buffer.Initialize (Output => Stream'Unchecked_Access,
Size => 1024,
Format => Util.Encoders.BASE_64);
Stream.Create (Mode => Out_File, Name => Path);
for I in 1 .. 32 loop
Print.Write ("abcd");
Print.Write (" fghij");
Print.Write (ASCII.LF);
end loop;
Print.Flush;
Stream.Close;
Util.Tests.Assert_Equal_Files (T => T,
Expect => Expect,
Test => Path,
Message => "Base64 stream");
end Test_Base64_Stream;
end Util.Streams.Buffered.Encoders.Tests;
|
Implement a new test to verify the Base64 encoding stream
|
Implement a new test to verify the Base64 encoding stream
|
Ada
|
apache-2.0
|
stcarrez/ada-util,stcarrez/ada-util
|
|
8e5f06e642e2a80ff46068352a6154dfe92f64b0
|
src/asis/a4g-asis_tables.ads
|
src/asis/a4g-asis_tables.ads
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . A S I S _ T A B L E S --
-- --
-- S p e c --
-- --
-- Copyright (C) 1995-2012, 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, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, 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 AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
-- This package contains definitions of tables and related auxilary resources
-- needed in more than one ASIS implementation package
with Asis;
with Sinfo; use Sinfo;
with Table;
with Types; use Types;
package A4G.Asis_Tables is
package Internal_Asis_Element_Table is new Table.Table (
Table_Component_Type => Asis.Element,
Table_Index_Type => Asis.ASIS_Natural,
Table_Low_Bound => 1,
Table_Initial => 10,
Table_Increment => 100,
Table_Name => "Internal Element_List");
-- This table contains ASIS Elements. It is supposed to be used only for
-- creating the result Element lists in ASIS structural queries. Note that
-- many ASIS queries use instantiations of Traverse_Elements to create
-- result lists, so we have to make sure that ASIS structural queries
-- used in the implementation of Traverse_Element use another table to
-- create result lists
package Asis_Element_Table is new Table.Table (
Table_Component_Type => Asis.Element,
Table_Index_Type => Asis.ASIS_Natural,
Table_Low_Bound => 1,
Table_Initial => 10,
Table_Increment => 100,
Table_Name => "Element_List");
-- This table contains ASIS Elements. It is supposed to be used for any
-- purpose except creating the result Element lists in ASIS structural
-- queries.
procedure Add_New_Element (Element : Asis.Element);
-- Differs from Asis_Element_Table.Append that checks if the argument
-- Element already is in the table, and appends the new element only if the
-- check fails. Note that the implementation is based on a simple array
-- search, so it can result in performance penalties if there are too
-- many elements in the table.
type Node_Trace_Rec is record
Kind : Node_Kind;
Node_Line : Physical_Line_Number;
Node_Col : Column_Number;
end record;
-- This record represents a Node in the node trace used to find the same
-- construct in another tree
package Node_Trace is new Table.Table (
Table_Component_Type => Node_Trace_Rec,
Table_Index_Type => Int,
Table_Low_Bound => 0,
Table_Initial => 10,
Table_Increment => 100,
Table_Name => "Node_Trace");
-- This table is used to create the node trace needed to compare elements
-- from nested instances
function Is_Equal
(N : Node_Id;
Trace_Rec : Node_Trace_Rec)
return Boolean;
-- Checks if N (in the currently accessed tree corresponds to the node
-- for which Trace_Rec was created
procedure Create_Node_Trace (N : Node_Id);
-- Creates the Node trace which is supposed to be used to find the node
-- representing the same construct in another tree. The trace is also used
-- to check is two nodes from different trees, each belonging to expanded
-- generics both denote the same thing. This trace contains the record
-- about N itself and all the enclosing constructs such as package bodies
-- and package specs. For the package which is an expanded generic, the
-- next element in the trace is the corresponding instantiation node.
function Enclosing_Scope (N : Node_Id) return Node_Id;
-- Given a node somewhere from expanded generic, returnes its enclosing
-- "scope" which can be N_Package_Declaration, N_Package_Body or
-- N_Generic_Declaration node. The idea is to use this function to create
-- the node trace either for storing it in the Note Trace table or for
-- creating the trace on the fly to compare it with the stored trace.
end A4G.Asis_Tables;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
stcarrez/dynamo,stcarrez/dynamo,stcarrez/dynamo
|
|
6c92da4b4a18fd130e2bdee09bb2fc4a148978d3
|
src/util-encoders-sha256.adb
|
src/util-encoders-sha256.adb
|
-----------------------------------------------------------------------
-- util-encoders-sha256 -- Compute SHA-1 hash
-- Copyright (C) 2017 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Encoders.Base64;
package body Util.Encoders.SHA256 is
-- ------------------------------
-- Computes the SHA256 hash and returns the raw binary hash in <b>Hash</b>.
-- ------------------------------
procedure Finish (E : in out Context;
Hash : out Hash_Array) is
begin
Hash := GNAT.SHA256.Digest (E);
E := GNAT.SHA256.Initial_Context;
end Finish;
-- ------------------------------
-- Computes the SHA256 hash and returns the hexadecimal hash in <b>Hash</b>.
-- ------------------------------
procedure Finish (E : in out Context;
Hash : out Digest) is
begin
Hash := GNAT.SHA256.Digest (E);
E := GNAT.SHA256.Initial_Context;
end Finish;
-- ------------------------------
-- Computes the SHA256 hash and returns the base64 hash in <b>Hash</b>.
-- ------------------------------
procedure Finish_Base64 (E : in out Context;
Hash : out Base64_Digest) is
Buf : Ada.Streams.Stream_Element_Array (1 .. Hash'Length);
for Buf'Address use Hash'Address;
pragma Import (Ada, Buf);
H : Hash_Array;
B : Util.Encoders.Base64.Encoder;
Last : Ada.Streams.Stream_Element_Offset;
Encoded : Ada.Streams.Stream_Element_Offset;
begin
Finish (E, H);
E := GNAT.SHA256.Initial_Context;
B.Transform (Data => H, Into => Buf, Last => Last, Encoded => Encoded);
end Finish_Base64;
end Util.Encoders.SHA256;
|
Implement the operations for the SHA256 package
|
Implement the operations for the SHA256 package
|
Ada
|
apache-2.0
|
stcarrez/ada-util,stcarrez/ada-util
|
|
cebe528c822e282afc34d00e9684b6d2f3a68d55
|
awa/src/awa-oauth-filters.adb
|
awa/src/awa-oauth-filters.adb
|
-----------------------------------------------------------------------
-- awa-oauth-filters -- OAuth filter
-- Copyright (C) 2017 Stephane Carrez
-- Written by Stephane Carrez ([email protected])
--
-- 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 Security;
with Security.OAuth.Servers;
with Util.Beans.Objects;
with AWA.Applications;
with AWA.Services.Contexts;
package body AWA.OAuth.Filters is
-- Initialize the filter.
overriding
procedure Initialize (Filter : in out Auth_Filter;
Config : in ASF.Servlets.Filter_Config) is
begin
null;
end Initialize;
function Get_Access_Token (Req : in ASF.Requests.Request'Class) return String is
begin
return "";
end Get_Access_Token;
-- The Do_Filter method of the Filter is called by the container each time
-- a request/response pair is passed through the chain due to a client request
-- for a resource at the end of the chain. The Filter_Chain passed in to this
-- method allows the Filter to pass on the request and response to the next
-- entity in the chain.
--
-- Before passing the control to the next filter, initialize the service
-- context to give access to the current application, current user and
-- manage possible transaction rollbacks.
overriding
procedure Do_Filter (F : in Auth_Filter;
Request : in out ASF.Requests.Request'Class;
Response : in out ASF.Responses.Response'Class;
Chain : in out ASF.Servlets.Filter_Chain) is
use type AWA.OAuth.Services.Auth_Manager_Access;
use type ASF.Principals.Principal_Access;
type Context_Type is new AWA.Services.Contexts.Service_Context with null record;
-- Get the attribute registered under the given name in the HTTP session.
overriding
function Get_Session_Attribute (Ctx : in Context_Type;
Name : in String) return Util.Beans.Objects.Object;
-- Set the attribute registered under the given name in the HTTP session.
overriding
procedure Set_Session_Attribute (Ctx : in out Context_Type;
Name : in String;
Value : in Util.Beans.Objects.Object);
overriding
function Get_Session_Attribute (Ctx : in Context_Type;
Name : in String) return Util.Beans.Objects.Object is
pragma Unreferenced (Ctx);
begin
return Request.Get_Session.Get_Attribute (Name);
end Get_Session_Attribute;
-- Set the attribute registered under the given name in the HTTP session.
overriding
procedure Set_Session_Attribute (Ctx : in out Context_Type;
Name : in String;
Value : in Util.Beans.Objects.Object) is
pragma Unreferenced (Ctx);
S : ASF.Sessions.Session := Request.Get_Session;
begin
S.Set_Attribute (Name, Value);
end Set_Session_Attribute;
App : constant ASF.Servlets.Servlet_Registry_Access
:= ASF.Servlets.Get_Servlet_Context (Chain);
Bearer : constant String := Get_Access_Token (Request);
Auth : Security.Principal_Access;
Grant : Security.OAuth.Servers.Grant_Type;
begin
if F.Realm = null then
return;
end if;
F.Realm.Authenticate (Bearer, Grant);
declare
Context : aliased Context_Type;
Application : AWA.Applications.Application_Access;
begin
-- Get the application
if App.all in AWA.Applications.Application'Class then
Application := AWA.Applications.Application'Class (App.all)'Access;
else
Application := null;
end if;
-- Context.Set_Context (Application, Grant.Auth);
-- Give the control to the next chain up to the servlet.
ASF.Servlets.Do_Filter (Chain => Chain,
Request => Request,
Response => Response);
-- By leaving this scope, the active database transactions are rollbacked
-- (finalization of Service_Context)
end;
end Do_Filter;
end AWA.OAuth.Filters;
|
Implement the OAuth security filter for AWA applications
|
Implement the OAuth security filter for AWA applications
|
Ada
|
apache-2.0
|
stcarrez/ada-awa,stcarrez/ada-awa,stcarrez/ada-awa,stcarrez/ada-awa
|
|
e1c39d7b2a246bd43c98a0d00703bb8a1b028177
|
src/oto-alc.ads
|
src/oto-alc.ads
|
pragma License (Modified_GPL);
------------------------------------------------------------------------------
-- EMAIL: <[email protected]> --
-- License: Modified GNU GPLv3 or any later as published by Free Software --
-- Foundation (GMGPL, see COPYING file). --
-- --
-- Copyright © 2014 darkestkhan --
------------------------------------------------------------------------------
-- This Program is Free Software: You can redistribute it and/or modify --
-- it under the terms of The GNU General Public License as published by --
-- the Free Software Foundation: either version 3 of the license, or --
-- (at your option) any later version. --
-- --
-- This Program is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --
-- GNU General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public License --
-- along with this program. If not, see <http://www.gnu.org/licenses/>. --
-- --
-- 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. --
------------------------------------------------------------------------------
with System;
with Oto.Binary;
use Oto;
package Oto.ALC is
---------------------------------------------------------------------------
---------------
-- T Y P E S --
---------------
---------------------------------------------------------------------------
-- Due to the fact that only pointers to device and context are passed
-- we ar going to use System.Address for them.
subtype Context is System.Address;
subtype Device is System.Address;
subtype Bool is Binary.Byte;
subtype Char is Binary.S_Byte;
subtype Double is Long_Float;
subtype Enum is Binary.S_Word;
subtype Int is Integer;
subtype Short is Binary.S_Short;
subtype SizeI is Integer;
subtype UByte is Binary.Byte;
subtype UInt is Binary.Word;
subtype UShort is Binary.Short;
---------------------------------------------------------------------------
end OTO.ALC;
|
Add type definitions.
|
ALC: Add type definitions.
Signed-off-by: darkestkhan <[email protected]>
|
Ada
|
isc
|
darkestkhan/oto
|
|
7a3790a903d91013b2fbc9119e23c8da361bf9af
|
orka_simd/src/x86/gnat/orka-simd-avx-longs-convert.ads
|
orka_simd/src/x86/gnat/orka-simd-avx-longs-convert.ads
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2021 onox <[email protected]>
--
-- 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 Orka.SIMD.AVX.Doubles;
package Orka.SIMD.AVX.Longs.Convert is
pragma Pure;
use SIMD.AVX.Doubles;
function Convert (Elements : m256d) return m256l
with Import, Convention => Intrinsic, External_Name => "__builtin_ia32_cvtpd2dq256";
function Convert (Elements : m256l) return m256d
with Import, Convention => Intrinsic, External_Name => "__builtin_ia32_cvtdq2pd256";
end Orka.SIMD.AVX.Longs.Convert;
|
Add missing ads file for package Orka.SIMD.AVX.Longs.Convert
|
simd: Add missing ads file for package Orka.SIMD.AVX.Longs.Convert
Signed-off-by: onox <[email protected]>
|
Ada
|
apache-2.0
|
onox/orka
|
|
a969cfc64e2859baacdd996dcd2d2be1f98c54fd
|
src/asis/a4g-contt.ads
|
src/asis/a4g-contt.ads
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . C O N T T --
-- --
-- S p e c --
-- --
-- Copyright (C) 1995-2006, 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). --
-- --
------------------------------------------------------------------------------
-- This package defines the Context (Context) Table - the top-level ASIS data
-- structure for ASIS Context/Compilation_Unit processing.
with A4G.A_Alloc; use A4G.A_Alloc;
with A4G.A_Types; use A4G.A_Types;
with A4G.Unit_Rec;
with A4G.Tree_Rec;
with A4G.A_Elists; use A4G.A_Elists;
with A4G.A_Opt; use A4G.A_Opt;
with Table;
with Alloc;
with Types; use Types;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with Hostparm;
package A4G.Contt is
------------------------------------------------
-- Subprograms for General Context Processing --
------------------------------------------------
procedure Verify_Context_Name (Name : String; Cont : Context_Id);
-- Verifies the string passed as the Name parameter for
-- Asis.Ada_Environments.Associate. If the string can be used as a
-- Context name, it is stored in a Context Table for a further use,
-- and if the verification is failed, ASIS_Failed is raised and a Status
-- is set as Parameter_Error.
procedure Process_Context_Parameters
(Parameters : String;
Cont : Context_Id := Non_Associated);
-- Processes a Parameters string passed parameter to the
-- Asis.Ada_Environments.Associate query. If there are any errors contained
-- in the Context association parameters, ASIS_Failed is raised and
-- a Status is set as Parameter_Error only in case of a fatal error,
-- that is, when a given set of parameters does not allow to define a legal
-- ASIS Context in case of ASIS-for-GNAT. For a non-fatal error detected
-- for some parameter, ASIS warning is generated.
--
-- If the Parameters string contains tree file names, these names are
-- stored in the Context Tree Table for Cont.
function I_Options (C : Context_Id) return Argument_List;
-- Returns the list of "-I" GNAT options according to the definition of
-- the Context C.
procedure Initialize;
-- Should be called by Asis.Implementation.Initialize. Initializes the
-- Context Table. Sets Current_Context and Current_Tree to nil values.
procedure Finalize;
-- Should be called by Asis.Implementation.Finalize.
-- Finalizes all the Contexts being processed by ASIS and then finalizes
-- the general Context Table. Produces the debug output, if the
-- corresponding debug flags are set ON.
-- ??? Requires revising
procedure Pre_Initialize (C : Context_Id);
-- Should be called by Asis.Ada_Environments.Associate. It initializes
-- the unit and tree tables for C, but it does not put any information
-- in these tables. Before doing this, it backups the current context,
-- and after initializing Context tables it sets Current_Context to C and
-- Current_Tree to Nil_Tree.
procedure Initialize (C : Context_Id);
-- Should be called by Asis.Ada_Environments.Open.
-- Initializes the internal structures and Tables for the Context C.
procedure Finalize (C : Context_Id);
-- Should be called by Asis.Ada_Environments.Close.
-- Finalizes the internal structures and Tables for the Context C.
-- Produces the debug output, if the corresponding debug flags are
-- set ON.
function Allocate_New_Context return Context_Id;
-- Allocates a new entry to an ASIS Context Table and returns the
-- corresponding Id as a result
function Context_Info (C : Context_Id) return String;
-- returns the string, which content uniquely identifies the ASIS Context
-- printed by C in user-understandable form. Initially is supposed to
-- be called in the implementation of Asis_Compilation_Units.Unique_Name.
-- May be used for producing some debug output.
procedure Erase_Old (C : Context_Id);
-- Erases all the settings for the given context, which have been
-- made by previous calls to Asis.Ada_Environments.Associate
-- procedure. (All the dynamically allocated memory is reclaimed)
procedure Set_Context_Name (C : Context_Id; Name : String);
-- Stores Name as the context name for context C
procedure Set_Context_Parameters (C : Context_Id; Parameters : String);
-- Stores Parameters as the context parameters for context C
function Get_Context_Name (C : Context_Id) return String;
-- returns a name string associated with a context
function Get_Context_Parameters (C : Context_Id) return String;
-- returns a parameters string associated with a context
procedure Print_Context_Info;
-- produces the general debug output for ASIS contexts;
-- is intended to be used during ASIS implementation finalization
procedure Print_Context_Info (C : Context_Id);
-- produces the detailed debug output for the ASIS context C
-- is intended to be used during ASIS implementation finalization
procedure Print_Context_Parameters (C : Context_Id);
-- prints strings which were used when the Context C was associated
-- for the last time, as well as the corresponding settings made
-- as the result of this association
procedure Scan_Trees_New (C : Context_Id);
-- This procedure does the main job when opening the Context C in case if
-- tree processing mode for this context is set to Pre_Created or Mixed.
-- It scans the set of tree files making up the Context and collects some
-- block-box information about Compilation Units belonging to this Context.
-- In case if any error is detected (including error when reading a tree
-- file in -C1 or -CN Context mode or any inconsistency), ASIS_Failed is
-- raised as a result of opening the Context
function Get_Current_Tree return Tree_Id;
-- Returns the Id of the tree currently accessed by ASIS.
procedure Set_Current_Tree (Tree : Tree_Id);
-- Sets the currently accessed tree
function Get_Current_Cont return Context_Id;
-- Returns the Id of the ASIS Context to which the currently accessed
-- tree belongs
procedure Set_Current_Cont (L : Context_Id);
-- Sets the Id of the Context to which the currently accessed tree
-- belongs
---------------------------------------------------
-- Context Attributes Access and Update Routines --
---------------------------------------------------
function Is_Associated (C : Context_Id) return Boolean;
function Is_Opened (C : Context_Id) return Boolean;
function Opened_At (C : Context_Id) return ASIS_OS_Time;
function Context_Processing_Mode (C : Context_Id) return Context_Mode;
function Tree_Processing_Mode (C : Context_Id) return Tree_Mode;
function Source_Processing_Mode (C : Context_Id) return Source_Mode;
function Use_Default_Trees (C : Context_Id) return Boolean;
function Gcc_To_Call (C : Context_Id) return String_Access;
--------
procedure Set_Is_Associated (C : Context_Id; Ass : Boolean);
procedure Set_Is_Opened (C : Context_Id; Op : Boolean);
procedure Set_Context_Processing_Mode (C : Context_Id; M : Context_Mode);
procedure Set_Tree_Processing_Mode (C : Context_Id; M : Tree_Mode);
procedure Set_Source_Processing_Mode (C : Context_Id; M : Source_Mode);
procedure Set_Use_Default_Trees (C : Context_Id; B : Boolean);
procedure Set_Default_Context_Processing_Mode (C : Context_Id);
procedure Set_Default_Tree_Processing_Mode (C : Context_Id);
procedure Set_Default_Source_Processing_Mode (C : Context_Id);
-------------------------------------------------
-----------------
-- Name Buffer --
-----------------
-- All the Name Tables from the ASIS Context implementation
-- shares the same Name Buffer.
A_Name_Buffer : String (1 .. Hostparm.Max_Name_Length);
-- This buffer is used to set the name to be stored in the table for the
-- Name_Find call, and to retrieve the name for the Get_Name_String call.
A_Name_Len : Natural;
-- Length of name stored in Name_Buffer. Used as an input parameter for
-- Name_Find, and as an output value by Get_Name_String.
procedure Set_Name_String (S : String);
-- Sets A_Name_Len as S'Length and after that sets
-- A_Name_Buffer (1 .. A_Name_Len) as S. We do not need any encoding,
-- and we usually operate with strings which should be stored as they
-- came from the clients, so we simply can set the string to be
-- stored or looked for in the name buffer as it is.
procedure NB_Save;
-- Saves the current state (the value of A_Name_Len and the characters
-- in A_Name_Buffer (1 .. A_Name_Len) of the A_Name Buffer. This state may
-- be restored by NB_Restore
procedure NB_Restore;
-- Restores the state of the A_Name Buffer, which has been saved by the
-- NB_Save procedure
------------------
-- Search Paths --
------------------
procedure Set_Search_Paths (C : Context_Id);
-- Stores the previously verified and stored in temporary data structures
-- directory names as search paths for a given contexts. Also sets the
-- list of the "-I" options for calling the compiler from inside ASIS.
-- The temporary structures are cleaned, and the dynamically allocated
-- storage used by them are reclaimed.
function Locate_In_Search_Path
(C : Context_Id;
File_Name : String;
Dir_Kind : Search_Dir_Kinds)
return String_Access;
-- This function tries to locate the given file (having File_Name as its
-- name) in the search path associated with context C. If the file
-- cannot be located, the null access value is returned
-----------------
-- NEW STUFF --
-----------------
procedure Save_Context (C : Context_Id);
-- Saves the tables for C. Does nothing, if the currently accessed Context
-- is Non_Associated
procedure Restore_Context (C : Context_Id);
-- restored tables for C taking them from the internal C structure
procedure Reset_Context (C : Context_Id);
-- If C is not Nil_Context_Id, resets the currently accessed Context to be
-- C, including restoring all the tables. If C is Nil_Context_Id, does
-- nothing (we need this check for Nil_Context_Id, because C may come from
-- Nil_Compilation_Unit
procedure Backup_Current_Context;
-- Saves tables for the currently accessed Context. Does nothing, if the
-- currently accessed Context is Non_Associated.
private
------------------------
-- ASIS Context Table --
------------------------
-- The entries in the table are accessed using a Context_Id that ranges
-- from Context_Low_Bound to Context_High_Bound. Context_Low_Bound is
-- reserved for a Context which has never been associated.
--
-- The following diagram shows the general idea of the multiple
-- Context processing in ASIS:
-- Asis.Compilation_Unit value:
-- +-----------------------+
-- | Id : Unit_Id; ------+---------
-- | | |
-- | Cont_Id : Context_Id;-+- |
-- +-----------------------+ | |
-- | |
-- | |
-- +------------------------- |
-- | |
-- | Context Table: |
-- | ============= |
-- | +--------------+ |
-- | | | |
-- | | | |
-- | | | |
-- | | | |
-- | +--------------+ | Unit_Reciord value
-- +-->| | | /
-- | ... | | /
-- | | V / Unit Table for
-- | | +-----+-----+----------... / a given
-- | Units -----+----->| | | / Context
-- | | +-----+-----+----------...
-- | | ^ ^
-- | | | |------------------+
-- | | | |
-- | | | |
-- | | V |
-- | | +-----------------... |
-- | Name_Chars --+----> | |
-- | | +-----------------... |
-- | | |
-- | | +-----------------------
-- | | |
-- | | V
-- | | +----------------...
-- | Hash_Table -+----> |
-- | | +----------------...
-- | |
-- | |
-- | ... |
-- | |
-- +--------------+
-- | |
-- | |
-- | ... |
-- +--------------+
-- | |
-- . .
-- . .
-- . .
---------------------------
-- Types for hash tables --
---------------------------
Hash_Num : constant Int := 2**12;
-- Number of headers in the hash table. Current hash algorithm is closely
-- tailored to this choice, so it can only be changed if a corresponding
-- change is made to the hash algorithm.
Hash_Max : constant Int := Hash_Num - 1;
-- Indexes in the hash header table run from 0 to Hash_Num - 1
subtype Hash_Index_Type is Int range 0 .. Hash_Max;
-- Range of hash index values
type Hash_Array is array (Hash_Index_Type) of Unit_Id;
-- Each kind of tables in the implementation of an ASIS Context uses
-- its own type of hash table
--
-- The hash table is used to locate existing entries in the names table.
-- The entries point to the first names table entry whose hash value
-- matches the hash code. Then subsequent names table entries with the
-- same hash code value are linked through the Hash_Link fields.
function Hash return Hash_Index_Type;
pragma Inline (Hash);
-- Compute hash code for name stored in Name_Buffer (length in Name_Len)
-- In Unit Name Table it can really be applied only to the "normalized"
-- unit names.
---------------
-- NEW STUFF --
---------------
package A_Name_Chars is new Table.Table (
Table_Component_Type => Character,
Table_Index_Type => Int,
Table_Low_Bound => 0,
Table_Initial => Alloc.Name_Chars_Initial,
Table_Increment => Alloc.Name_Chars_Increment,
Table_Name => "A_Name_Chars");
package Unit_Table is new Table.Table (
Table_Component_Type => A4G.Unit_Rec.Unit_Record,
Table_Index_Type => A4G.A_Types.Unit_Id,
Table_Low_Bound => A4G.A_Types.First_Unit_Id,
Table_Initial => A4G.A_Alloc.Alloc_ASIS_Units_Initial,
Table_Increment => A4G.A_Alloc.Alloc_ASIS_Units_Increment,
Table_Name => "ASIS_Compilation_Units");
package Tree_Table is new Table.Table (
Table_Component_Type => A4G.Tree_Rec.Tree_Record,
Table_Index_Type => A4G.A_Types.Tree_Id,
Table_Low_Bound => A4G.A_Types.First_Tree_Id,
Table_Initial => A4G.A_Alloc.Alloc_ASIS_Trees_Initial,
Table_Increment => A4G.A_Alloc.Alloc_ASIS_Trees_Increment,
Table_Name => "ASIS_Trees");
subtype Directory_List_Ptr is Argument_List_Access;
subtype Tree_File_List_Ptr is Argument_List_Access;
type Saved_Context is record
Context_Name_Chars : A_Name_Chars.Saved_Table;
Context_Unit_Lists : A4G.A_Elists.Saved_Lists;
Units : Unit_Table.Saved_Table;
Trees : Tree_Table.Saved_Table;
end record;
--------------------
-- Context Record --
--------------------
type Context_Record is record -- the field should be commented also here!!!
---------------------------------------------------
-- General Context/Context Attributes and Fields --
---------------------------------------------------
Name : String_Access;
Parameters : String_Access;
-- to keep the parameters set by the ASIS Associate routine
GCC : String_Access;
-- If non-null, contains the full path to the compiler to be used when
-- creating trees on the fly. (If null, the standard gcc/GNAT
-- installation is used)
Is_Associated : Boolean := False;
Is_Opened : Boolean := False;
Opened_At : ASIS_OS_Time := Last_ASIS_OS_Time;
-- when an application opens a Context, we store the time of opening;
-- we need it to check whether an Element or a Compilation_Unit in
-- use has been obtained after the last opening of this Context
Specs : Natural;
Bodies : Natural;
-- counters for library_units_declarations and library_unit_bodies/
-- subunits (respectively) contained in a Context. We need them to
-- optimize processing of the queries Compilation_Units,
-- Libary_Unit_Declarations and Compilation_Unit_Bodies from
-- Asis.Compilation_Units and to make the difference between "regular"
-- and nonexistent units. Last for Context's Unit table gives us the
-- whole number of all the units, including nonexistent ones.
-------------------------------------
-- Fields for Context's Unit Table --
-------------------------------------
Hash_Table : Hash_Array; -- hash table for Unit Table
Current_Main_Unit : Unit_Id;
-- The variable to store the Id of the Unit corresponding to the
-- main unit of the currently accessed tree
-- ----------------------------------------------...
-- | Nil | |...|XXX| | | | |
-- | Unit | |...|XXX| | | | | <- Unit Table
-- ----------------------------------------------...
-- ^ ^ ^ ^ ^
-- | | | | |
-- | ----------------|
-- Current_Main_Unit |
-- |
-- for all of these Units
-- Is_New (C, Unit) = True
------------------
-- Search Paths --
------------------
-- we do not know the number of the directories in a path, so we have
-- to use pointers to the arrays of the pointers to strings
Source_Path : Directory_List_Ptr;
-- The search path for the source files
Object_Path : Directory_List_Ptr;
-- The search path for library (that is, object + ALI) files
Tree_Path : Directory_List_Ptr;
-- The search path for the tree output files
Context_I_Options : Directory_List_Ptr;
-- Source search path for GNAT or another tree builder, when it is
-- called from inside ASIS to create a tree output file "on the fly"
-- ("I" comes after "-I" gcc/GNAT option). The corresponding search
-- path is obtained form the value of the Source_Path field by
-- prepending "-I" to each directory name kept in Source_Path and
-- by appending "-I-" element to this path
Context_Tree_Files : Tree_File_List_Ptr;
Back_Up : Saved_Context;
Mode : Context_Mode := All_Trees;
Tree_Processing : Tree_Mode := Pre_Created;
Source_Processing : Source_Mode := All_Sources;
Use_Default_Trees : Boolean := False;
-- If set On, the value of the GNAT environment variable
-- ADA_OBJECTS_PATH is appended to Object_Path
end record;
-------------------
-- Context Table --
-------------------
package Contexts is new Table.Table (
Table_Component_Type => Context_Record,
Table_Index_Type => Context_Id,
Table_Low_Bound => First_Context_Id,
Table_Initial => Alloc_Contexts_Initial,
Table_Increment => Alloc_Contexts_Increment,
Table_Name => "ASIS_Contexts");
------------------------------------------------------
-- "Back-Up" Name Buffer for NB_Save and NB_Restore --
------------------------------------------------------
Backup_Name_Buffer : String (1 .. Hostparm.Max_Name_Length);
Backup_Name_Len : Natural := 0;
-- ??? is it the right place for these declarations???
Current_Tree : Tree_Id := Nil_Tree;
-- This is the tree, which is being currently accessed by ASIS.
-- The Initialize procedure sets Current_Tree equal to Nil_Tree.
Current_Context : Context_Id := Non_Associated;
-- This is the Context to which the currently accessed tree belongs.
-- The Initialize procedure sets Current_Context equal to Non_Associated.
First_New_Unit : Unit_Id;
-- In the Incremental Context mode stores the first unit registered
-- from the newly created tree. Then used by Set_All_Dependencies routine
-- to collect full dependencies only for the units added to the Context
end A4G.Contt;
|
Add the ASIS file $i
|
Add the ASIS file $i
|
Ada
|
apache-2.0
|
stcarrez/dynamo,stcarrez/dynamo,stcarrez/dynamo
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.