@@ -32,7 +32,7 @@ namespace patchestry::ast {
3232 // / As rules fire, nodes get absorbed into StructuredNode wrappers and
3333 // / removed from the active set.
3434 struct CNode {
35- static constexpr size_t NONE = std::numeric_limits<size_t >::max();
35+ static constexpr size_t kNone = std::numeric_limits<size_t >::max();
3636
3737 size_t id; // original CfgBlock index
3838 std::vector<size_t > succs; // outgoing edges (by CNode id)
@@ -55,47 +55,47 @@ namespace patchestry::ast {
5555
5656 // Set when absorbed into a parent structured node
5757 bool collapsed = false ;
58- size_t collapsed_into = NONE ; // representative node after collapse
58+ size_t collapsed_into = kNone ; // representative node after collapse
5959
6060 // Flags for the collapse algorithm
6161 bool mark = false ;
6262 int visit_count = 0 ;
6363
6464 enum EdgeFlag : uint32_t {
65- F_GOTO = 1u << 0 ,
66- F_BACK = 1u << 1 ,
67- F_LOOP_EXIT = 1u << 2 ,
65+ kGoto = 1u << 0 ,
66+ kBack = 1u << 1 ,
67+ kLoopExit = 1u << 2 ,
6868 };
6969
70- bool isGotoOut (size_t i) const {
71- return i < edge_flags.size () && (edge_flags[i] & F_GOTO );
70+ bool IsGotoOut (size_t i) const {
71+ return i < edge_flags.size () && (edge_flags[i] & kGoto );
7272 }
73- bool isBackEdge (size_t i) const {
74- return i < edge_flags.size () && (edge_flags[i] & F_BACK );
73+ bool IsBackEdge (size_t i) const {
74+ return i < edge_flags.size () && (edge_flags[i] & kBack );
7575 }
76- bool isLoopExit (size_t i) const {
77- return i < edge_flags.size () && (edge_flags[i] & F_LOOP_EXIT );
76+ bool IsLoopExit (size_t i) const {
77+ return i < edge_flags.size () && (edge_flags[i] & kLoopExit );
7878 }
79- bool isDecisionOut (size_t i) const {
80- return !isGotoOut (i) && !isBackEdge (i);
79+ bool IsDecisionOut (size_t i) const {
80+ return !IsGotoOut (i) && !IsBackEdge (i);
8181 }
8282 // / Edges to trace in TraceDAG: not back-edges, not loop-exit edges.
83- bool isLoopDAGOut (size_t i) const {
84- return !isBackEdge (i) && !isLoopExit (i);
83+ bool IsLoopDagOut (size_t i) const {
84+ return !IsBackEdge (i) && !IsLoopExit (i);
8585 }
86- bool isSwitchOut () const { return succs.size () > 2 ; }
86+ bool IsSwitchOut () const { return succs.size () > 2 ; }
8787
88- size_t sizeIn () const { return preds.size (); }
89- size_t sizeOut () const { return succs.size (); }
88+ size_t SizeIn () const { return preds.size (); }
89+ size_t SizeOut () const { return succs.size (); }
9090
91- void setGoto (size_t i) {
92- if (i < edge_flags.size ()) edge_flags[i] |= F_GOTO ;
91+ void SetGoto (size_t i) {
92+ if (i < edge_flags.size ()) edge_flags[i] |= kGoto ;
9393 }
94- void setLoopExit (size_t i) {
95- if (i < edge_flags.size ()) edge_flags[i] |= F_LOOP_EXIT ;
94+ void SetLoopExit (size_t i) {
95+ if (i < edge_flags.size ()) edge_flags[i] |= kLoopExit ;
9696 }
97- void clearLoopExit (size_t i) {
98- if (i < edge_flags.size ()) edge_flags[i] &= ~static_cast <uint32_t >(F_LOOP_EXIT );
97+ void ClearLoopExit (size_t i) {
98+ if (i < edge_flags.size ()) edge_flags[i] &= ~static_cast <uint32_t >(kLoopExit );
9999 }
100100 };
101101
@@ -106,27 +106,27 @@ namespace patchestry::ast {
106106 size_t entry = 0 ;
107107
108108 // / Active (uncollapsed) node ids
109- std::vector<size_t > activeIds () const {
109+ std::vector<size_t > ActiveIds () const {
110110 std::vector<size_t > result;
111111 for (auto &n : nodes) {
112112 if (!n.collapsed ) result.push_back (n.id );
113113 }
114114 return result;
115115 }
116116
117- size_t activeCount () const {
117+ size_t ActiveCount () const {
118118 size_t c = 0 ;
119119 for (auto &n : nodes) {
120120 if (!n.collapsed ) ++c;
121121 }
122122 return c;
123123 }
124124
125- CNode &node (size_t id) { return nodes[id]; }
126- const CNode &node (size_t id) const { return nodes[id]; }
125+ CNode &Node (size_t id) { return nodes[id]; }
126+ const CNode &Node (size_t id) const { return nodes[id]; }
127127
128128 // / Remove an edge from the active graph
129- void removeEdge (size_t from, size_t to) {
129+ void RemoveEdge (size_t from, size_t to) {
130130 auto &s = nodes[from].succs ;
131131 auto &f = nodes[from].edge_flags ;
132132 for (size_t i = 0 ; i < s.size (); ++i) {
@@ -142,58 +142,57 @@ namespace patchestry::ast {
142142
143143 // / Replace a set of nodes with a single new structured node.
144144 // / Returns the representative node id.
145- size_t collapseNodes (const std::vector<size_t > &ids, SNode *snode);
145+ size_t CollapseNodes (const std::vector<size_t > &ids, SNode *snode);
146146 };
147147
148148 // / Build the collapse graph from a Cfg.
149- CGraph buildCGraph (const Cfg &cfg);
149+ CGraph BuildCGraph (const Cfg &cfg);
150150
151151 // / Detect back-edges using DFS and mark them in the graph.
152- void markBackEdges (CGraph &g);
152+ void MarkBackEdges (CGraph &g);
153153
154154 // / A detected natural loop: header, back-edge tails, nesting info.
155155 struct LoopBody {
156156 size_t head; // loop header CNode id
157157 std::vector<size_t > tails; // CNode ids with back-edges to head
158158 int depth = 0 ; // nesting depth (deeper = higher number)
159159 int unique_count = 0 ; // count of head+tail nodes before reachability
160- size_t exit_block = NONE ; // official exit CNode id, or NONE
160+ size_t exit_block = kNone ; // official exit CNode id, or kNone
161161 LoopBody *immed_container = nullptr ; // immediately containing loop
162162
163- static constexpr size_t NONE = std::numeric_limits<size_t >::max();
163+ static constexpr size_t kNone = std::numeric_limits<size_t >::max();
164164
165165 explicit LoopBody (size_t h) : head(h) {}
166166
167- void addTail (size_t t) { tails.push_back (t); }
167+ void AddTail (size_t t) { tails.push_back (t); }
168168
169169 // / Core body computation: backward reachability from tails to head.
170170 // / Populates `body` with all CNode ids in the loop. Sets CNode::mark.
171- // / Caller MUST call clearMarks () after using the body.
172- void findBase (CGraph &g, std::vector<size_t > &body) const ;
171+ // / Caller MUST call ClearMarks () after using the body.
172+ void FindBase (CGraph &g, std::vector<size_t > &body) const ;
173173
174174 // / Set immed_container based on containment within other loops.
175- void labelContainments (const CGraph &g, const std::vector<size_t > &body,
175+ void LabelContainments (const CGraph &g, const std::vector<size_t > &body,
176176 const std::vector<LoopBody *> &looporder);
177177
178178 // / Exit detection, tail ordering, body extension, exit edge labeling.
179- // / (Declared here, implemented in Plan 02)
180- void findExit (const CGraph &g, const std::vector<size_t > &body);
181- void orderTails (const CGraph &g);
182- void extend (CGraph &g, std::vector<size_t > &body) const ;
183- void labelExitEdges (CGraph &g, const std::vector<size_t > &body) const ;
179+ void FindExit (const CGraph &g, const std::vector<size_t > &body);
180+ void OrderTails (const CGraph &g);
181+ void Extend (CGraph &g, std::vector<size_t > &body) const ;
182+ void LabelExitEdges (CGraph &g, const std::vector<size_t > &body) const ;
184183
185184 // / Merge LoopBody records that share the same head.
186- static void mergeIdenticalHeads (std::vector<LoopBody *> &looporder,
185+ static void MergeIdenticalHeads (std::vector<LoopBody *> &looporder,
187186 std::list<LoopBody> &storage);
188187
189- // / Mark edges leaving the loop body as F_LOOP_EXIT .
190- void setExitMarks (CGraph &g, const std::vector<size_t > &body) const ;
188+ // / Mark edges leaving the loop body as kLoopExit .
189+ void SetExitMarks (CGraph &g, const std::vector<size_t > &body) const ;
191190
192- // / Clear F_LOOP_EXIT marks set by setExitMarks .
193- void clearExitMarks (CGraph &g, const std::vector<size_t > &body) const ;
191+ // / Clear kLoopExit marks set by SetExitMarks .
192+ void ClearExitMarks (CGraph &g, const std::vector<size_t > &body) const ;
194193
195194 // / Check if this loop's head is still active (not collapsed).
196- bool update (const CGraph &g) const ;
195+ bool Update (const CGraph &g) const ;
197196
198197 // / Sort innermost-first (higher depth = processed first).
199198 bool operator <(const LoopBody &other) const {
@@ -209,8 +208,8 @@ namespace patchestry::ast {
209208 FloatingEdge (size_t t, size_t b) : top_id(t), bottom_id(b) {}
210209
211210 // / Resolve to current edge in graph. Returns {source_id, edge_index},
212- // / or {CNode::NONE , 0} if the edge no longer exists.
213- std::pair<size_t , size_t > getCurrentEdge (const CGraph &g) const ;
211+ // / or {CNode::kNone , 0} if the edge no longer exists.
212+ std::pair<size_t , size_t > GetCurrentEdge (const CGraph &g) const ;
214213 };
215214
216215 // / TraceDAG: traces DAG paths through the CGraph to identify
@@ -226,23 +225,23 @@ namespace patchestry::ast {
226225 int depth = 0 ;
227226 bool ismark = false ;
228227
229- void markPath ();
230- int distance (BranchPoint *op2);
228+ void MarkPath ();
229+ int Distance (BranchPoint *op2);
231230 };
232231
233232 struct BlockTrace {
234- enum : uint32_t { f_active = 1 , f_terminal = 2 };
233+ enum : uint32_t { kActive = 1 , kTerminal = 2 };
235234 uint32_t flags = 0 ;
236235 BranchPoint *top;
237236 int pathout;
238- size_t bottom_id; // CNode id (or NONE for root traces)
237+ size_t bottom_id; // CNode id (or kNone for root traces)
239238 size_t dest_id; // destination CNode id
240239 int edgelump = 1 ;
241240 std::list<BlockTrace *>::iterator activeiter;
242241 BranchPoint *derivedbp = nullptr ;
243242
244- bool isActive () const { return flags & f_active ; }
245- bool isTerminal () const { return flags & f_terminal ; }
243+ bool IsActive () const { return flags & kActive ; }
244+ bool IsTerminal () const { return flags & kTerminal ; }
246245 };
247246
248247 struct BadEdgeScore {
@@ -252,52 +251,52 @@ namespace patchestry::ast {
252251 int terminal = 0 ;
253252 int siblingedge = 0 ;
254253
255- bool compareFinal (const BadEdgeScore &op2) const ;
254+ bool CompareFinal (const BadEdgeScore &op2) const ;
256255 bool operator <(const BadEdgeScore &op2) const ;
257256 };
258257
259- std::list<FloatingEdge> &likelygoto ;
260- std::vector<size_t > rootlist ;
261- std::vector<BranchPoint *> branchlist ;
262- int activecount = 0 ;
263- std::list<BlockTrace *> activetrace ;
264- std::list<BlockTrace *>::iterator current_activeiter ;
265- size_t finishblock_id = CNode::NONE ;
258+ std::list<FloatingEdge> &likelygoto_ ;
259+ std::vector<size_t > rootlist_ ;
260+ std::vector<BranchPoint *> branchlist_ ;
261+ int activecount_ = 0 ;
262+ std::list<BlockTrace *> activetrace_ ;
263+ std::list<BlockTrace *>::iterator current_activeiter_ ;
264+ size_t finishblock_id_ = CNode::kNone ;
266265
267- void removeTrace (BlockTrace *trace);
268- void processExitConflict (std::list<BadEdgeScore>::iterator start,
266+ void RemoveTrace (BlockTrace *trace);
267+ void ProcessExitConflict (std::list<BadEdgeScore>::iterator start,
269268 std::list<BadEdgeScore>::iterator end);
270- BlockTrace *selectBadEdge ();
271- void insertActive (BlockTrace *trace);
272- void removeActive (BlockTrace *trace);
273- bool checkOpen (const CGraph &g, BlockTrace *trace);
274- std::list<BlockTrace *>::iterator openBranch (CGraph &g,
269+ BlockTrace *SelectBadEdge ();
270+ void InsertActive (BlockTrace *trace);
271+ void RemoveActive (BlockTrace *trace);
272+ bool CheckOpen (const CGraph &g, BlockTrace *trace);
273+ std::list<BlockTrace *>::iterator OpenBranch (CGraph &g,
275274 BlockTrace *parent);
276- bool checkRetirement (BlockTrace *trace, size_t &exitblock_id);
277- std::list<BlockTrace *>::iterator retireBranch (BranchPoint *bp,
275+ bool CheckRetirement (BlockTrace *trace, size_t &exitblock_id);
276+ std::list<BlockTrace *>::iterator RetireBranch (BranchPoint *bp,
278277 size_t exitblock_id);
279- void clearVisitCount (CGraph &g);
278+ void ClearVisitCount (CGraph &g);
280279
281280 public:
282- TraceDAG (std::list<FloatingEdge> &lg) : likelygoto (lg) {}
281+ TraceDAG (std::list<FloatingEdge> &lg) : likelygoto_ (lg) {}
283282 ~TraceDAG ();
284283
285- void addRoot (size_t root_id) { rootlist .push_back (root_id); }
286- void setFinishBlock (size_t id) { finishblock_id = id; }
287- void initialize ();
288- void pushBranches (CGraph &g);
284+ void AddRoot (size_t root_id) { rootlist_ .push_back (root_id); }
285+ void SetFinishBlock (size_t id) { finishblock_id_ = id; }
286+ void Initialize ();
287+ void PushBranches (CGraph &g);
289288 };
290289
291290 // / Clear CNode::mark for all nodes in body vector.
292- void clearMarks (CGraph &g, const std::vector<size_t > &body);
291+ void ClearMarks (CGraph &g, const std::vector<size_t > &body);
293292
294293 // / Scan back-edges and create LoopBody records.
295- void labelLoops (CGraph &g, std::list<LoopBody> &loopbody,
294+ void LabelLoops (CGraph &g, std::list<LoopBody> &loopbody,
296295 std::vector<LoopBody *> &looporder);
297296
298297 // / Discover all loops, compute bodies/nesting/exits, and order innermost-first.
299- // / Called once from CfgFoldStructure() after markBackEdges ().
300- void orderLoopBodies (CGraph &g, std::list<LoopBody> &loopbody);
298+ // / Called once from CfgFoldStructure() after MarkBackEdges ().
299+ void OrderLoopBodies (CGraph &g, std::list<LoopBody> &loopbody);
301300
302301 } // namespace detail
303302
0 commit comments