From 9620102b7a00ad38af1a0fc1dcfc039cf3e538ac Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Wed, 9 May 2018 17:12:23 +0200 Subject: [PATCH] s/Conditional_Value/Tree/ --- src/alire-conditional.ads | 4 +- src/alire-conditional_trees.adb | 50 +++++++-------- src/alire-conditional_trees.ads | 104 ++++++++++++++++---------------- 3 files changed, 79 insertions(+), 79 deletions(-) diff --git a/src/alire-conditional.ads b/src/alire-conditional.ads index 79c20fcf..c96a2ad8 100644 --- a/src/alire-conditional.ads +++ b/src/alire-conditional.ads @@ -9,7 +9,7 @@ package Alire.Conditional with Preelaborate is package For_Dependencies is new Conditional_Trees (Dependencies.Dependency, Dependencies.Image); - subtype Dependencies is For_Dependencies.Conditional_Value; + subtype Dependencies is For_Dependencies.Tree; function New_Dependency (Name : Alire.Project; Versions : Semantic_Versioning.Version_Set) @@ -18,7 +18,7 @@ package Alire.Conditional with Preelaborate is package For_Properties is new Conditional_Trees (Properties.Property'Class, Properties.Image_Classwide); - subtype Properties is For_Properties.Conditional_Value; + subtype Properties is For_Properties.Tree; function New_Property (Property : Alire.Properties.Property'Class) return Properties; diff --git a/src/alire-conditional_trees.adb b/src/alire-conditional_trees.adb index 1176bdc5..2d1722ec 100644 --- a/src/alire-conditional_trees.adb +++ b/src/alire-conditional_trees.adb @@ -2,7 +2,7 @@ with GNAT.IO; package body Alire.Conditional_Trees is - function All_But_First_Children (This : Conditional_Value) return Conditional_Value is + function All_But_First_Children (This : Tree) return Tree is Children : Vectors.Vector := This.As_Vector; begin Children.Delete_First; @@ -36,7 +36,7 @@ package body Alire.Conditional_Trees is -- "and" -- ----------- - function "and" (L, R : Conditional_Value) return Conditional_Value is + function "and" (L, R : Tree) return Tree is Inner : Vector_Inner := (Conjunction => Anded, Values => <>); begin @@ -59,7 +59,7 @@ package body Alire.Conditional_Trees is -- "or" -- ---------- - function "or" (L, R : Conditional_Value) return Conditional_Value is + function "or" (L, R : Tree) return Tree is Inner : Vector_Inner := (Conjunction => Ored, Values => <>); begin @@ -82,7 +82,7 @@ package body Alire.Conditional_Trees is -- Leaf_Count -- ---------------- - function Leaf_Count (This : Conditional_Value) return Natural is + function Leaf_Count (This : Tree) return Natural is Count : Natural := 0; begin if This.Is_Empty then @@ -106,9 +106,9 @@ package body Alire.Conditional_Trees is -- Materialize -- ----------------- - function Materialize (This : Conditional_Value; Against : Properties.Vector) return Collection is + function Materialize (This : Tree; Against : Properties.Vector) return Collection is Col : Collection with Warnings => Off; - Pre : constant Conditional_Value := This.Evaluate (Against); + Pre : constant Tree := This.Evaluate (Against); procedure Visit (Inner : Inner_Node'Class) is begin @@ -139,7 +139,7 @@ package body Alire.Conditional_Trees is -- Enumerate -- --------------- - function Enumerate (This : Conditional_Value) return Collection is + function Enumerate (This : Tree) return Collection is Col : Collection with Warnings => Off; procedure Visit (Inner : Inner_Node'Class) is @@ -172,9 +172,9 @@ package body Alire.Conditional_Trees is -- Evaluate -- -------------- - function Evaluate (This : Conditional_Value; Against : Properties.Vector) return Conditional_Value is + function Evaluate (This : Tree; Against : Properties.Vector) return Tree is - function Evaluate (This : Inner_Node'Class) return Conditional_Value is + function Evaluate (This : Inner_Node'Class) return Tree is begin case This.Kind is when Condition => @@ -196,9 +196,9 @@ package body Alire.Conditional_Trees is end if; end; when Value => - return Conditional_Value'(To_Holder (This)); + return Tree'(To_Holder (This)); when Vector => - return Result : Conditional_Value := Empty do + return Result : Tree := Empty do for Cond of Vector_Inner (This).Values loop if Vector_Inner (This).Conjunction = Anded then Result := Result and Evaluate (Cond); @@ -222,9 +222,9 @@ package body Alire.Conditional_Trees is -- Contains_ORs -- ------------------ - function Contains_ORs (This : Conditional_Value) return Boolean is + function Contains_ORs (This : Tree) return Boolean is - function Verify (This : Conditional_Value) return Boolean is + function Verify (This : Tree) return Boolean is Contains : Boolean := False; begin case This.Kind is @@ -258,9 +258,9 @@ package body Alire.Conditional_Trees is -- Is_Unconditional -- ---------------------- - function Is_Unconditional (This : Conditional_Value) return Boolean is + function Is_Unconditional (This : Tree) return Boolean is - function Verify (This : Conditional_Value) return Boolean is + function Verify (This : Tree) return Boolean is Pass : Boolean := True; begin case This.Kind is @@ -284,8 +284,8 @@ package body Alire.Conditional_Trees is -- Iterate_Children -- ---------------------- - procedure Iterate_Children (This : Conditional_Value; - Visitor : access procedure (CV : Conditional_Value)) + procedure Iterate_Children (This : Tree; + Visitor : access procedure (CV : Tree)) is procedure Iterate (This : Inner_Node'Class) is @@ -295,7 +295,7 @@ package body Alire.Conditional_Trees is raise Constraint_Error with "Conditional value is not a vector"; when Vector => for Inner of Vector_Inner (This).Values loop - Visitor (Conditional_Value'(To_Holder (Inner))); + Visitor (Tree'(To_Holder (Inner))); end loop; end case; end Iterate; @@ -312,8 +312,8 @@ package body Alire.Conditional_Trees is package body Case_Statements is - function Case_Is (Arr : Arrays) return Conditional_Value is - Case_Is : Conditional_Value := Arr (Arr'Last); + function Case_Is (Arr : Arrays) return Tree is + Case_Is : Tree := Arr (Arr'Last); -- Since we get the whole array, -- by exhaustion at worst the last must be true begin @@ -332,7 +332,7 @@ package body Alire.Conditional_Trees is -- Print -- ----------- - procedure Print (This : Conditional_Value; + procedure Print (This : Tree; Prefix : String := ""; And_Or : Boolean := True) is use GNAT.IO; @@ -415,7 +415,7 @@ package body Alire.Conditional_Trees is -- Iterate -- ------------- - function Iterate (Container : Conditional_Value) + function Iterate (Container : Tree) return Iterators.Forward_Iterator'Class is begin if Container.Kind /= Vector then @@ -432,9 +432,9 @@ package body Alire.Conditional_Trees is -- Indexed_Element -- --------------------- - function Indexed_Element (Container : Conditional_Value; + function Indexed_Element (Container : Tree; Pos : Cursor) - return Conditional_Value is - (Conditional_Value'(To_Holder (Element (Pos)))); + return Tree is + (Tree'(To_Holder (Element (Pos)))); end Alire.Conditional_Trees; diff --git a/src/alire-conditional_trees.ads b/src/alire-conditional_trees.ads index d718664a..837c08af 100644 --- a/src/alire-conditional_trees.ads +++ b/src/alire-conditional_trees.ads @@ -15,18 +15,18 @@ package Alire.Conditional_Trees with Preelaborate is type Kinds is (Condition, Value, Vector); - type Conditional_Value is tagged private with + type Tree is tagged private with Default_Iterator => Iterate, - Iterator_Element => Conditional_Value, + Iterator_Element => Tree, Constant_Indexing => Indexed_Element; -- Recursive type that stores conditions (requisites) and values/further conditions if they are met or not - function Leaf_Count (This : Conditional_Value) return Natural; + function Leaf_Count (This : Tree) return Natural; generic type Collection is private; with procedure Append (C : in out Collection; V : Values; Count : Count_Type := 1); - function Materialize (This : Conditional_Value; Against : Properties.Vector) return Collection; + function Materialize (This : Tree; Against : Properties.Vector) return Collection; -- Materialize against the given properties, and return as list -- NOTE: this presumes there are no OR conditions along the tree -- In Alire context, this is always true for properties and @@ -35,75 +35,75 @@ package Alire.Conditional_Trees with Preelaborate is generic type Collection is private; with procedure Append (C : in out Collection; V : Values; Count : Count_Type := 1); - function Enumerate (This : Conditional_Value) return Collection; + function Enumerate (This : Tree) return Collection; -- Return all value nodes, regardless of dependencies/conjunctions -- This is used for textual search and has no semantic trascendence - function Evaluate (This : Conditional_Value; Against : Properties.Vector) return Conditional_Value; + function Evaluate (This : Tree; Against : Properties.Vector) return Tree; -- Materialize against the given properties, returning values as an unconditional tree -- NOTE: the result is unconditional but can still contain a mix of AND/OR subtrees - function Kind (This : Conditional_Value) return Kinds; + function Kind (This : Tree) return Kinds; - function Is_Empty (This : Conditional_Value) return Boolean; + function Is_Empty (This : Tree) return Boolean; - function Empty return Conditional_Value; + function Empty return Tree; - function Image_One_Line (This : Conditional_Value) return String; + function Image_One_Line (This : Tree) return String; - function Is_Unconditional (This : Conditional_Value) return Boolean; + function Is_Unconditional (This : Tree) return Boolean; -- Recursively! - function Contains_ORs (This : Conditional_Value) return Boolean; + function Contains_ORs (This : Tree) return Boolean; --------------- -- SINGLES -- --------------- - function New_Value (V : Values) return Conditional_Value; -- when we don't really need a condition + function New_Value (V : Values) return Tree; -- when we don't really need a condition - function Value (This : Conditional_Value) return Values + function Value (This : Tree) return Values with Pre => This.Kind = Value; --------------- -- VECTORS -- --------------- - function "and" (L, R : Conditional_Value) return Conditional_Value; + function "and" (L, R : Tree) return Tree; -- Concatenation - function "or" (L, R : Conditional_Value) return Conditional_Value; + function "or" (L, R : Tree) return Tree; type Conjunctions is (Anded, Ored); - function Conjunction (This : Conditional_Value) return Conjunctions + function Conjunction (This : Tree) return Conjunctions with Pre => This.Kind = Vector; - procedure Iterate_Children (This : Conditional_Value; - Visitor : access procedure (CV : Conditional_Value)); + procedure Iterate_Children (This : Tree; + Visitor : access procedure (CV : Tree)); -- There is "of" notation too, but that bugs out when using this package as generic formal - type Children_Array is array (Positive range <>) of Conditional_Value; + type Children_Array is array (Positive range <>) of Tree; - function First_Child (This : Conditional_Value) return Conditional_Value; + function First_Child (This : Tree) return Tree; - function All_But_First_Children (This : Conditional_Value) return Conditional_Value; + function All_But_First_Children (This : Tree) return Tree; -------------------- -- CONDITIONALS -- -------------------- function New_Conditional (If_X : Requisites.Tree; - Then_X : Conditional_Value; - Else_X : Conditional_Value) return Conditional_Value; + Then_X : Tree; + Else_X : Tree) return Tree; - function Condition (This : Conditional_Value) return Requisites.Tree + function Condition (This : Tree) return Requisites.Tree with Pre => This.Kind = Condition; - function True_Value (This : Conditional_Value) return Conditional_Value + function True_Value (This : Tree) return Tree with Pre => This.Kind = Condition; - function False_Value (This : Conditional_Value) return Conditional_Value + function False_Value (This : Tree) return Tree with Pre => This.Kind = Condition; generic @@ -112,9 +112,9 @@ package Alire.Conditional_Trees with Preelaborate is -- Function which creates an equality requisite on V package Case_Statements is - type Arrays is array (Enum) of Conditional_Value; + type Arrays is array (Enum) of Tree; - function Case_Is (Arr : Arrays) return Conditional_Value; + function Case_Is (Arr : Arrays) return Tree; end Case_Statements; @@ -122,7 +122,7 @@ package Alire.Conditional_Trees with Preelaborate is -- Print -- ----------- - procedure Print (This : Conditional_Value; + procedure Print (This : Tree; Prefix : String := ""; And_Or : Boolean := True); -- And_Or is false if only And can appear, thus no necessity to distinguish @@ -139,13 +139,13 @@ package Alire.Conditional_Trees with Preelaborate is package Iterators is new Ada.Iterator_Interfaces (Cursor, Has_Element); - function Iterate (Container : Conditional_Value) + function Iterate (Container : Tree) return Iterators.Forward_Iterator'Class; -- Returns our own iterator, which in general will be defined in the -- private part or the body. - function Indexed_Element (Container : Conditional_Value; Pos : Cursor) - return Conditional_Value; + function Indexed_Element (Container : Tree; Pos : Cursor) + return Tree; private @@ -162,7 +162,7 @@ private type Cursor is new Vectors.Cursor; - type Conditional_Value is new Holders.Holder with null record; + type Tree is new Holders.Holder with null record; -- Instead of dealing with pointers and finalization, we use this class-wide container package Definite_Values is new Ada.Containers.Indefinite_Holders (Values); @@ -205,8 +205,8 @@ private type Conditional_Inner is new Inner_Node with record Condition : Requisites.Tree; - Then_Value : Conditional_Value; - Else_Value : Conditional_Value; + Then_Value : Tree; + Else_Value : Tree; end record; overriding function Image (V : Conditional_Inner) return String is @@ -218,7 +218,7 @@ private -- As_Value -- -------------- - function As_Value (This : Conditional_Value) return Values + function As_Value (This : Tree) return Values is (Value_Inner (This.Element).Value.Element) with Pre => This.Kind = Value; @@ -227,7 +227,7 @@ private -- As_Conditional -- -------------------- - function As_Conditional (This : Conditional_Value) return Conditional_Inner'Class is + function As_Conditional (This : Tree) return Conditional_Inner'Class is (Conditional_Inner'Class (This.Element)) with Pre => This.Kind = Condition; @@ -235,7 +235,7 @@ private -- As_Vector -- --------------- - function As_Vector (This : Conditional_Value) return Vectors.Vector is + function As_Vector (This : Tree) return Vectors.Vector is (Vector_Inner'Class (This.Element).Values) with Pre => This.Kind = Vector; @@ -243,14 +243,14 @@ private -- Conjunction -- ----------------- - function Conjunction (This : Conditional_Value) return Conjunctions is + function Conjunction (This : Tree) return Conjunctions is (Vector_Inner'Class (This.Element).Conjunction); ----------------- -- First_Child -- ----------------- - function First_Child (This : Conditional_Value) return Conditional_Value is + function First_Child (This : Tree) return Tree is (To_Holder (This.As_Vector.First_Element)); --------------------- @@ -258,8 +258,8 @@ private --------------------- function New_Conditional (If_X : Requisites.Tree; - Then_X : Conditional_Value; - Else_X : Conditional_Value) return Conditional_Value is + Then_X : Tree; + Else_X : Tree) return Tree is (To_Holder (Conditional_Inner'(Condition => If_X, Then_Value => Then_X, Else_Value => Else_X))); @@ -268,48 +268,48 @@ private -- New_Value -- --------------- - function New_Value (V : Values) return Conditional_Value is + function New_Value (V : Values) return Tree is (To_Holder (Value_Inner'(Value => Definite_Values.To_Holder (V)))); --------------- -- Condition -- --------------- - function Condition (This : Conditional_Value) return Requisites.Tree is + function Condition (This : Tree) return Requisites.Tree is (This.As_Conditional.Condition); ----------- -- Value -- ----------- - function Value (This : Conditional_Value) return Values renames As_Value; + function Value (This : Tree) return Values renames As_Value; ---------------- -- True_Value -- ---------------- - function True_Value (This : Conditional_Value) return Conditional_Value is + function True_Value (This : Tree) return Tree is (This.As_Conditional.Then_Value); ----------------- -- False_Value -- ----------------- - function False_Value (This : Conditional_Value) return Conditional_Value is + function False_Value (This : Tree) return Tree is (This.As_Conditional.Else_Value); ----------- -- Empty -- ----------- - function Empty return Conditional_Value is + function Empty return Tree is (Holders.Empty_Holder with null record); -------------- -- Is_Empty -- -------------- - overriding function Is_Empty (This : Conditional_Value) return Boolean is + overriding function Is_Empty (This : Tree) return Boolean is (Holders.Holder (This).Is_Empty); ---------- @@ -323,14 +323,14 @@ private then Vector else Condition)); - function Kind (This : Conditional_Value) return Kinds is + function Kind (This : Tree) return Kinds is (This.Constant_Reference.Kind); -------------------- -- Image_One_Line -- -------------------- - function Image_One_Line (This : Conditional_Value) return String is + function Image_One_Line (This : Tree) return String is (if This.Is_Empty then "(empty condition)" else This.Constant_Reference.Image);