1  with Gela.Elements;


2  with Asis.Extensions.Flat_Kinds;


3 


4  package body Asis.Iterator is


5 


6   We need to skip some children of element while iterating, because


7   ASIS doesn't need all of them. For instance we keep "end_name" of


8   procedure body, but ASIS never iterate it.


9  Skip : constant array (Asis.Extensions.Flat_Kinds.Element_Flat_Kind) of


10  Natural :=


11  (Asis.Extensions.Flat_Kinds.A_Procedure_Body_Declaration => 16,


12  Asis.Extensions.Flat_Kinds.A_Package_Declaration => 9,


13  Asis.Extensions.Flat_Kinds.A_Package_Body_Declaration => 12,


14  others => 0);


15 


16  


17   Traverse_Element 


18  


19 


20  procedure Traverse_Element


21  (Element : in Asis.Element;


22  Control : in out Traverse_Control;


23  State : in out State_Information) is


24  begin


25  Check_Nil_Element (Element, "Traverse_Element");


26 


27  if Control /= Continue then


28  return;


29  end if;


30 


31  declare


32  use type Gela.Elements.Element_Sequence_Access;


33 


34  Kind : Asis.Extensions.Flat_Kinds.Element_Flat_Kind;


35  Children : constant Gela.Elements.Nested_Array :=


36  Element.Data.Nested_Items;


37  begin


38  if not Auxilary (Element) then


39  Pre_Operation (Element, Control, State);


40  end if;


41 


42  if Control = Continue then


43  Kind := Asis.Extensions.Flat_Kinds.Flat_Kind (Element);


44 


45  for J in Children'Range loop


46  case Children (J).Kind is


47  when Gela.Elements.Nested_Token =>


48  null;


49 


50  when Gela.Elements.Nested_Element =>


51  declare


52  Next : constant Asis.Element :=


53  (Data => Children (J).Nested_Element);


54  begin


55  if Assigned (Next) and Skip (Kind) /= J then


56  Traverse_Element (Next, Control, State);


57  end if;


58  end;


59 


60  when Gela.Elements.Nested_Sequence =>


61  if Children (J).Nested_Sequence /= null then


62  declare


63  Next : Gela.Elements.Element_Sequence_Cursor :=


64  Children (J).Nested_Sequence.First;


65  begin


66  while Next.Has_Element loop


67  Traverse_Element


68  ((Data => Next.Element), Control, State);


69 


70  exit when Control /= Continue;


71  Next.Next;


72  end loop;


73  end;


74  end if;


75 


76  end case;


77 


78  exit when Control /= Continue;


79  end loop;


80 


81  if Control = Abandon_Siblings then


82  Control := Continue;


83  end if;


84  end if;


85 


86  if Control = Continue and then not Auxilary (Element) then


87  Post_Operation (Element, Control, State);


88  end if;


89 


90  if Control = Abandon_Children then


91  Control := Continue;


92  end if;


93  end;


94  end Traverse_Element;


95 


96  end Asis.Iterator;

