c2rust-refactor 0.10.1

C2Rust refactoring tool implementation
Documentation
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
    <title>Reference</title>
    <link rel="stylesheet" href="ldoc.css" type="text/css" />
</head>
<body>

<div id="container">

<div id="product">
	<div id="product_logo"></div>
	<div id="product_name"><big><b></b></big></div>
	<div id="product_description"></div>
</div> <!-- id="product" -->


<div id="main">


<!-- Menu -->

<div id="navigation">
<br/>
<h1>c2rust-refactor</h1>


<h2>Contents</h2>
<ul>
<li><a href="#Tables">Tables</a></li>
<li><a href="#Fields">Fields</a></li>
<li><a href="#Class_RefactorState">Class RefactorState </a></li>
<li><a href="#Class_MatchCtxt">Class MatchCtxt </a></li>
<li><a href="#Class_TransformCtxt">Class TransformCtxt </a></li>
</ul>


<h2>Modules</h2>
<ul class="nowrap">
  <li><strong>Refactor</strong></li>
</ul>

</div>

<div id="content">

<h1>Module <code>Refactor</code></h1>
<p>Refactoring module</p>
<p>

</p>


<h2><a href="#Tables">Tables</a></h2>
<table class="function_list">
	<tr>
	<td class="name" nowrap><a href="#Stmt">Stmt</a></td>
	<td class="summary">AST Stmt</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#Expr">Expr</a></td>
	<td class="summary">AST Expr</td>
	</tr>
</table>
<h2><a href="#Fields">Fields</a></h2>
<table class="function_list">
	<tr>
	<td class="name" nowrap><a href="#refactor">refactor</a></td>
	<td class="summary">Global refactoring state</td>
	</tr>
</table>
<h2><a href="#Class_RefactorState">Class RefactorState </a></h2>
<table class="function_list">
	<tr>
	<td class="name" nowrap><a href="#RefactorState:run_command">RefactorState:run_command (name, args)</a></td>
	<td class="summary">Run a builtin refactoring command</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#RefactorState:transform">RefactorState:transform (callback)</a></td>
	<td class="summary">Run a custom refactoring transformation</td>
	</tr>
</table>
<h2><a href="#Class_MatchCtxt">Class MatchCtxt </a></h2>
<table class="function_list">
	<tr>
	<td class="name" nowrap><a href="#MatchCtxt:parse_stmts">MatchCtxt:parse_stmts (pat)</a></td>
	<td class="summary">Parse statements and add them to this MatchCtxt</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#MatchCtxt:parse_expr">MatchCtxt:parse_expr (pat)</a></td>
	<td class="summary">Parse an expressiong and add it to this MatchCtxt</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#MatchCtxt:fold_with">MatchCtxt:fold_with (needle, crate, callback)</a></td>
	<td class="summary">Find matches of <code>pattern</code> within <code>crate</code> and rewrite using <code>callback</code></td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#MatchCtxt:get_expr">MatchCtxt:get_expr (Expression)</a></td>
	<td class="summary">Get matched binding for an expression variable</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#MatchCtxt:get_stmt">MatchCtxt:get_stmt (Statement)</a></td>
	<td class="summary">Get matched binding for a statement variable</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#MatchCtxt:try_match">MatchCtxt:try_match (pat, target)</a></td>
	<td class="summary">Attempt to match <code>target</code> against <code>pat</code>, updating bindings if matched.</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#MatchCtxt:subst">MatchCtxt:subst (replacement)</a></td>
	<td class="summary">Substitute the currently matched AST node with a new AST node</td>
	</tr>
</table>
<h2><a href="#Class_TransformCtxt">Class TransformCtxt </a></h2>
<table class="function_list">
	<tr>
	<td class="name" nowrap><a href="#TransformCtxt:replace_stmts_with">TransformCtxt:replace_stmts_with (needle, callback)</a></td>
	<td class="summary">Replace matching statements using given callback</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#TransformCtxt:replace_expr_with">TransformCtxt:replace_expr_with (needle, callback)</a></td>
	<td class="summary">Replace matching expressions using given callback</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#TransformCtxt:match">TransformCtxt:match ()</a></td>
	<td class="summary">Create a new, empty <a href="scripting_api.html#MatchCtxt">MatchCtxt</a></td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#TransformCtxt:get_ast">TransformCtxt:get_ast (node)</a></td>
	<td class="summary">Retrieve a Lua version of an AST node</td>
	</tr>
</table>

<br/>
<br/>


    <h2 class="section-header "><a name="Tables"></a>Tables</h2>

    <dl class="function">
    <dt>
    <a name = "Stmt"></a>
    <strong>Stmt</strong>
    </dt>
    <dd>
    AST Stmt


    <h3>Fields:</h3>
    <ul>
        <li><span class="parameter">type</span>
         "Stmt"
        </li>
        <li><span class="parameter">kind</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
         <code>StmtKind</code> of this statement</p>

<p> <code>StmtKind::Local</code> only:
        </li>
        <li><span class="parameter">ty</span>
            <span class="types"><a class="type" href="scripting_api.html#AstNode">AstNode</a></span>
         Type of local
         (<em>optional</em>)
        </li>
        <li><span class="parameter">init</span>
            <span class="types"><a class="type" href="scripting_api.html#AstNode">AstNode</a></span>
         Initializer of local
         (<em>optional</em>)
        </li>
        <li><span class="parameter">pat</span>
            <span class="types"><a class="type" href="scripting_api.html#AstNode">AstNode</a></span>
         Name of local</p>

<p> <code>StmtKind::Item</code> only:
        </li>
        <li><span class="parameter">item</span>
            <span class="types"><a class="type" href="scripting_api.html#AstNode">AstNode</a></span>
         Item node</p>

<p> <code>StmtKind::Semi</code> and <code>StmtKind::Expr</code> only:
        </li>
        <li><span class="parameter">expr</span>
            <span class="types"><a class="type" href="scripting_api.html#AstNode">AstNode</a></span>
         Expression in this statement
        </li>
    </ul>





</dd>
    <dt>
    <a name = "Expr"></a>
    <strong>Expr</strong>
    </dt>
    <dd>
    AST Expr


    <h3>Fields:</h3>
    <ul>
        <li><span class="parameter">type</span>
         "Expr"
        </li>
        <li><span class="parameter">kind</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
         <code>ExprKind</code> of this expression</p>

<p> <code>ExprKind::Lit</code> only:
        </li>
        <li><span class="parameter">value</span>
         Literal value of this expression
        </li>
    </ul>





</dd>
</dl>
    <h2 class="section-header "><a name="Fields"></a>Fields</h2>

    <dl class="function">
    <dt>
    <a name = "refactor"></a>
    <strong>refactor</strong>
    </dt>
    <dd>
    Global refactoring state


    <ul>
        <li><span class="parameter">refactor</span>
         RefactorState object
        </li>
    </ul>





</dd>
</dl>
    <h2 class="section-header has-description"><a name="Class_RefactorState"></a>Class RefactorState </h2>

          <div class="section-description">
          Refactoring context
          </div>
    <dl class="function">
    <dt>
    <a name = "RefactorState:run_command"></a>
    <strong>RefactorState:run_command (name, args)</strong>
    </dt>
    <dd>
    Run a builtin refactoring command


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">name</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
         Command to run
        </li>
        <li><span class="parameter">args</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">{string,...}</a></span>
         List of arguments for the command
        </li>
    </ul>





</dd>
    <dt>
    <a name = "RefactorState:transform"></a>
    <strong>RefactorState:transform (callback)</strong>
    </dt>
    <dd>
    Run a custom refactoring transformation


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">callback</span>
            <span class="types"><span class="type">function(TransformCtxt,AstNode)</span></span>
         Transformation function called with a fresh <a href="scripting_api.html#TransformCtxt">TransformCtxt</a> and the crate to be transformed.
        </li>
    </ul>





</dd>
</dl>
    <h2 class="section-header has-description"><a name="Class_MatchCtxt"></a>Class MatchCtxt </h2>

          <div class="section-description">
          A match context
          </div>
    <dl class="function">
    <dt>
    <a name = "MatchCtxt:parse_stmts"></a>
    <strong>MatchCtxt:parse_stmts (pat)</strong>
    </dt>
    <dd>
    Parse statements and add them to this MatchCtxt


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">pat</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
         Pattern to parse
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><a class="type" href="scripting_api.html#AstNode">AstNode</a></span>
        The parsed statements
    </ol>




</dd>
    <dt>
    <a name = "MatchCtxt:parse_expr"></a>
    <strong>MatchCtxt:parse_expr (pat)</strong>
    </dt>
    <dd>
    Parse an expressiong and add it to this MatchCtxt


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">pat</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
         Pattern to parse
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><a class="type" href="scripting_api.html#AstNode">AstNode</a></span>
        The parsed expression
    </ol>




</dd>
    <dt>
    <a name = "MatchCtxt:fold_with"></a>
    <strong>MatchCtxt:fold_with (needle, crate, callback)</strong>
    </dt>
    <dd>
    Find matches of <code>pattern</code> within <code>crate</code> and rewrite using <code>callback</code>


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">needle</span>
            <span class="types"><a class="type" href="scripting_api.html#AstNode">AstNode</a></span>
         Pattern to search for
        </li>
        <li><span class="parameter">crate</span>
            <span class="types"><a class="type" href="scripting_api.html#AstNode">AstNode</a></span>
         Crate to fold over
        </li>
        <li><span class="parameter">callback</span>
            <span class="types"><span class="type">function(AstNode,MatchCtxt)</span></span>
         Function called for each match. Takes the matching node and a new <a href="scripting_api.html#MatchCtxt">MatchCtxt</a> for that match.
        </li>
    </ul>





</dd>
    <dt>
    <a name = "MatchCtxt:get_expr"></a>
    <strong>MatchCtxt:get_expr (Expression)</strong>
    </dt>
    <dd>
    Get matched binding for an expression variable


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">Expression</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
         variable pattern
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><a class="type" href="scripting_api.html#AstNode">AstNode</a></span>
        Expression matched by this binding
    </ol>




</dd>
    <dt>
    <a name = "MatchCtxt:get_stmt"></a>
    <strong>MatchCtxt:get_stmt (Statement)</strong>
    </dt>
    <dd>
    Get matched binding for a statement variable


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">Statement</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
         variable pattern
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><a class="type" href="scripting_api.html#AstNode">AstNode</a></span>
        Statement matched by this binding
    </ol>




</dd>
    <dt>
    <a name = "MatchCtxt:try_match"></a>
    <strong>MatchCtxt:try_match (pat, target)</strong>
    </dt>
    <dd>
    Attempt to match <code>target</code> against <code>pat</code>, updating bindings if matched.


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">pat</span>
            <span class="types"><a class="type" href="scripting_api.html#AstNode">AstNode</a></span>
         AST (potentially with variable bindings) to match with
        </li>
        <li><span class="parameter">target</span>
            <span class="types"><a class="type" href="scripting_api.html#AstNode">AstNode</a></span>
         AST to match against
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><span class="type">bool</span></span>
        true if match was successful
    </ol>




</dd>
    <dt>
    <a name = "MatchCtxt:subst"></a>
    <strong>MatchCtxt:subst (replacement)</strong>
    </dt>
    <dd>
    Substitute the currently matched AST node with a new AST node


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">replacement</span>
            <span class="types"><a class="type" href="scripting_api.html#AstNode">AstNode</a></span>
         New AST node to replace the currently matched AST. May include variable bindings if these bindings were matched by the search pattern.
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

           <span class="types"><a class="type" href="scripting_api.html#AstNode">AstNode</a></span>
        New AST node with variable bindings replaced by their matched values
    </ol>




</dd>
</dl>
    <h2 class="section-header has-description"><a name="Class_TransformCtxt"></a>Class TransformCtxt </h2>

          <div class="section-description">
          Transformation context
          </div>
    <dl class="function">
    <dt>
    <a name = "TransformCtxt:replace_stmts_with"></a>
    <strong>TransformCtxt:replace_stmts_with (needle, callback)</strong>
    </dt>
    <dd>
    Replace matching statements using given callback


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">needle</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
         Statements pattern to search for, may include variable bindings
        </li>
        <li><span class="parameter">callback</span>
            <span class="types"><span class="type">function(AstNode,MatchCtxt)</span></span>
         Function called for each match. Takes the matching node and a new <a href="scripting_api.html#MatchCtxt">MatchCtxt</a> for that match. See <a href="scripting_api.html#MatchCtxt:fold_with">MatchCtxt:fold_with</a>
        </li>
    </ul>





</dd>
    <dt>
    <a name = "TransformCtxt:replace_expr_with"></a>
    <strong>TransformCtxt:replace_expr_with (needle, callback)</strong>
    </dt>
    <dd>
    Replace matching expressions using given callback


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">needle</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4">string</a></span>
         Expression pattern to search for, may include variable bindings
        </li>
        <li><span class="parameter">callback</span>
            <span class="types"><span class="type">function(AstNode,MatchCtxt)</span></span>
         Function called for each match. Takes the matching node and a new <a href="scripting_api.html#MatchCtxt">MatchCtxt</a> for that match. See <a href="scripting_api.html#MatchCtxt:fold_with">MatchCtxt:fold_with</a>
        </li>
    </ul>





</dd>
    <dt>
    <a name = "TransformCtxt:match"></a>
    <strong>TransformCtxt:match ()</strong>
    </dt>
    <dd>
    Create a new, empty <a href="scripting_api.html#MatchCtxt">MatchCtxt</a>



    <h3>Returns:</h3>
    <ol>

           <span class="types"><a class="type" href="scripting_api.html#MatchCtxt">MatchCtxt</a></span>
        New match context
    </ol>




</dd>
    <dt>
    <a name = "TransformCtxt:get_ast"></a>
    <strong>TransformCtxt:get_ast (node)</strong>
    </dt>
    <dd>
    Retrieve a Lua version of an AST node


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">node</span>
            <span class="types"><a class="type" href="scripting_api.html#AstNode">AstNode</a></span>
         AST node handle
        </li>
    </ul>

    <h3>Returns:</h3>
    <ol>

        Struct representation of this AST node. Valid return types are <a href="scripting_api.html#Stmt">Stmt</a>, and <a href="scripting_api.html#Expr">Expr</a>.
    </ol>




</dd>
</dl>


</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2019-02-21 10:38:12 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>