source: trunk/ada-2012/src/asis/asis-iterator.adb@ 343

Last change on this file since 343 was 343, checked in by Maxim Reznik, 6 years ago

Skip some children while iterating over tree.

Add asis2xml as test for first ACATS test

  • Property svn:keywords set to Date Revision
File size: 3.0 KB
Line 
1with Gela.Elements;
2with Asis.Extensions.Flat_Kinds;
3
4package 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 others => 0);
13
14 ----------------------
15 -- Traverse_Element --
16 ----------------------
17
18 procedure Traverse_Element
19 (Element : in Asis.Element;
20 Control : in out Traverse_Control;
21 State : in out State_Information) is
22 begin
23 Check_Nil_Element (Element, "Traverse_Element");
24
25 if Control /= Continue then
26 return;
27 end if;
28
29 declare
30 use type Gela.Elements.Element_Sequence_Access;
31
32 Kind : Asis.Extensions.Flat_Kinds.Element_Flat_Kind;
33 Children : constant Gela.Elements.Nested_Array :=
34 Element.Data.Nested_Items;
35 begin
36 if not Auxilary (Element) then
37 Pre_Operation (Element, Control, State);
38 end if;
39
40 if Control = Continue then
41 Kind := Asis.Extensions.Flat_Kinds.Flat_Kind (Element);
42
43 for J in Children'Range loop
44 case Children (J).Kind is
45 when Gela.Elements.Nested_Token =>
46 null;
47
48 when Gela.Elements.Nested_Element =>
49 declare
50 Next : constant Asis.Element :=
51 (Data => Children (J).Nested_Element);
52 begin
53 if Assigned (Next) and Skip (Kind) /= J then
54 Traverse_Element (Next, Control, State);
55 end if;
56 end;
57
58 when Gela.Elements.Nested_Sequence =>
59 if Children (J).Nested_Sequence /= null then
60 declare
61 Next : Gela.Elements.Element_Sequence_Cursor :=
62 Children (J).Nested_Sequence.First;
63 begin
64 while Next.Has_Element loop
65 Traverse_Element
66 ((Data => Next.Element), Control, State);
67
68 exit when Control /= Continue;
69 Next.Next;
70 end loop;
71 end;
72 end if;
73
74 end case;
75
76 exit when Control /= Continue;
77 end loop;
78
79 if Control = Abandon_Siblings then
80 Control := Continue;
81 end if;
82 end if;
83
84 if Control = Continue and then not Auxilary (Element) then
85 Post_Operation (Element, Control, State);
86 end if;
87
88 if Control = Abandon_Children then
89 Control := Continue;
90 end if;
91 end;
92 end Traverse_Element;
93
94end Asis.Iterator;
Note: See TracBrowser for help on using the repository browser.