-
Notifications
You must be signed in to change notification settings - Fork 1
/
rejuvenation-finder.ads
161 lines (130 loc) · 5.91 KB
/
rejuvenation-finder.ads
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
with Rejuvenation.Match_Patterns; use Rejuvenation.Match_Patterns;
with Rejuvenation.Patterns; use Rejuvenation.Patterns;
package Rejuvenation.Finder is
-- Methods to find nodes of a certain Node_Kind or nodes that match certain
-- AST patterns.
-- Externally-visible data structures -------
package Match_Pattern_List is new Vectors (Positive, Match_Pattern);
type Pattern_Array is array (Positive range <>) of Pattern;
package Pattern_Vectors is new Vectors (Positive, Pattern);
-- Data type for list of Match_Pattern.
Pattern_Is_No_List_Exception : exception;
-- Exception that indicates that the pattern parameter was
-- not an Ada_List (as required).
-- Find Predicate --------
function Find
(Node : Ada_Node'Class;
Predicate : not null access function
(Node : Ada_Node'Class) return Boolean)
return Node_List.Vector;
-- Return all recursively nested nodes from the AST instance
-- that match the Predicate.
function Find_Non_Contained
(Node : Ada_Node'Class;
Predicate : not null access function
(Node : Ada_Node'Class) return Boolean)
return Node_List.Vector;
-- Return all nodes from the AST instance that match the Predicate,
-- but without nodes that are contained / recursively nested
-- in other returned nodes.
-- Find Node_Kind --------
function Find
(Node : Ada_Node'Class; Node_Kind : Ada_Node_Kind_Type)
return Node_List.Vector;
-- Return all recursively nested nodes from the AST instance
-- that match the Node_Kind.
function Find_Non_Contained
(Node : Ada_Node'Class; Node_Kind : Ada_Node_Kind_Type)
return Node_List.Vector;
-- Return all nodes from the AST instance that match the Node_Kind,
-- but without nodes that are contained / recursively nested
-- in other returned nodes.
function Find_First
(Node : Ada_Node'Class; Node_Kind : Ada_Node_Kind_Type) return Ada_Node;
-- Return the first recursively nested node from the AST instance
-- that match the Node_Kind.
function Find_Sub_List
(Node : Ada_Node'Class; Node_Kinds : Node_Kind_Type_Array)
return Node_List_List.Vector;
-- Return all recursively nested subsequences of nodes
-- from the AST instance that fully match the node kinds.
-- Find Match_Pattern --------
function Accept_Every_Match (M_P : Match_Pattern) return Boolean;
-- Predicate function that accepts every match
function Find_Full
(Node : Ada_Node'Class; Find_Pattern : Pattern;
Predicate : not null access function
(M_P : Match_Pattern) return Boolean :=
Accept_Every_Match'Access)
return Match_Pattern_List.Vector;
-- Return all recursively nested nodes from the AST instance
-- that fully match the AST pattern and the predicate.
function Find_Non_Contained_Full
(Node : Ada_Node'Class; Find_Pattern : Pattern;
Predicate : not null access function
(M_P : Match_Pattern) return Boolean :=
Accept_Every_Match'Access)
return Match_Pattern_List.Vector;
-- Return all nodes from the AST instance that fully match the AST pattern
-- and the predicate,
-- but without nodes that are contained / recursively nested
-- in other returned nodes.
function Find_First_Full
(Node : Ada_Node'Class; Find_Pattern : Pattern;
Predicate : not null access function
(M_P : Match_Pattern) return Boolean :=
Accept_Every_Match'Access;
Result : out Match_Pattern) return Boolean;
-- Return the first recursively nested node from the AST instance that
-- fully match the AST pattern and the predicate.
function Find_Sub_List
(Node : Ada_Node'Class; Find_Pattern : Pattern;
Predicate : not null access function
(M_P : Match_Pattern) return Boolean :=
Accept_Every_Match'Access)
return Match_Pattern_List.Vector;
-- Return all recursively nested subsequences of nodes
-- from the AST instance that fully match the AST pattern and the Predicate.
function Find_Non_Contained_Sub_List
(Node : Ada_Node'Class; Find_Pattern : Pattern;
Predicate : not null access function
(M_P : Match_Pattern) return Boolean :=
Accept_Every_Match'Access)
return Match_Pattern_List.Vector;
-- Return all nodes from the AST instance that fully match the AST pattern
-- and the predicate,
-- but without nodes that are contained / recursively nested
-- in other returned nodes.
function Find_Full
(Node : Ada_Node'Class; Find_Patterns : Pattern_Array)
return Match_Pattern_List.Vector;
-- Return all recursively nested nodes from the AST instance that
-- fully match any of the AST patterns.
-- Note: when a Node matches multiple patterns,
-- it will occur multiple times in the result.
private
function Find_Predicate
(Node : Ada_Node'Class;
Predicate : not null access function
(Node : Ada_Node'Class) return Boolean;
Next : Visit_Status) return Node_List.Vector;
function Find_NK_Sub_List
(Node : Ada_Node'Class; Node_Kinds : Node_Kind_Type_Array)
return Node_List_List.Vector;
function Find_MP
(Node : Ada_Node'Class; Pattern : Ada_Node; Next : Visit_Status;
Predicate : not null access function
(M_P : Match_Pattern) return Boolean)
return Match_Pattern_List.Vector;
type Containment is (Contained, Non_Contained);
function Find_Sub_List
(Node : Ada_Node'Class; Find_Pattern : Pattern; Next : Containment;
Predicate : not null access function
(M_P : Match_Pattern) return Boolean)
return Match_Pattern_List.Vector;
function Find_MP_Sub_List
(Node : Ada_Node'Class; Pattern : Ada_Node_Array; Next : Containment;
Predicate : not null access function
(M_P : Match_Pattern) return Boolean)
return Match_Pattern_List.Vector;
end Rejuvenation.Finder;