Commit 991ebcff authored by Maxime Perrotin's avatar Maxime Perrotin

Add option type

parent d3b05461
......@@ -396,10 +396,17 @@ package body Buildsupport_Utils is
function Parse_Function (Name : String;
Inst : Node_Id) return Taste_Terminal_Function
is
Result : Taste_Terminal_Function;
pragma Unreferenced (Inst);
Result : Taste_Terminal_Function;
-- To get the optional zip filename where user code is stored:
Source_Text : constant Name_Array := Get_Source_Text (Inst);
Zip_Id : Name_Id := No_Name;
begin
Result.Name := US (Name);
Result.Name := US (Name);
Result.Language := Get_Source_Language (Inst);
if Source_Text'Length /= 0 then
Zip_Id := Source_Text (1);
Result.Zip_File := Just (US (Get_Name_String (Zip_Id)));
end if;
return Result;
end Parse_Function;
......@@ -419,7 +426,7 @@ package body Buildsupport_Utils is
Inner := AIN.First_Node (AIN.Subcomponents (CI));
while Present (Inner) loop
Res := Res & Rec_Function (Prefix => Name, Func => Inner);
Inner := AIN.Next_Node (Inner);
Inner := AIN.Next_Node (Inner);
end loop;
end if;
......
......@@ -12,7 +12,8 @@ with Ocarina,
Ada.Containers.Indefinite_Vectors,
Ocarina.ME_AADL.AADL_Tree.Nodes,
Ocarina.ME_AADL.AADL_Instances.Nodes,
Ada.Strings.Unbounded;
Ada.Strings.Unbounded,
Option_Type;
use Ocarina,
Types,
......@@ -142,12 +143,14 @@ package Buildsupport_Utils is
end record;
package Ctxt_Params is new Indefinite_Vectors (Natural, Context_Parameter);
package Option_Zip is new Option_Type (Unbounded_String);
use Option_Zip;
type Taste_Terminal_Function is
record
Name : Unbounded_String;
Language : Supported_Source_Language;
Zip_File : Unbounded_String;
Zip_File : Option_Zip.Option (False) := Nothing;
Context_Params : Ctxt_Params.Vector;
User_Properties : Property_Maps.Map;
Timers : String_Vectors.Vector;
......
-- *************************** buildsupport **************************** --
-- (c) 2008-2017 European Space Agency - maxime.perrotin@esa.int
-- LGPL license, see LICENSE file
-- Define a generic Option type
generic
type T is private;
package Option_Type is
pragma Assertion_Policy (check);
type Option (Present : Boolean) is tagged private;
function Just (I : T) return Option;
function Nothing return Option;
function Just (O : Option) return T
with Pre => O.Present;
function Value (O : Option) return T renames Just;
function Value_Or (O : Option; Default : T) return T;
function Has_Value (O : Option) return Boolean is (O.Present);
private
type Option (Present : Boolean) is tagged
record
case Present is
when True =>
Value : T;
when False =>
null;
end case;
end record;
function Just (I : T) return Option is
(Present => True, Value => I);
function Nothing return Option is
(Present => False);
function Just (O : Option) return T is (O.Value);
function Value_Or (O : Option; Default : T) return T is
(if O.Present then O.Value else Default);
end Option_Type;
......@@ -14,6 +14,7 @@ project BuildSupport is
"buildsupport.adb",
"buildsupport_utils.ads",
"buildsupport_utils.adb",
"option_type.ads",
"buildsupport_version.ads");
package Builder is
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment