dump_perl.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. /* Copyright 2010, 2011, 2012, 2013, 2014, 2015
  2. Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include "parser.h"
  16. #include "input.h"
  17. #include "text.h"
  18. #include "labels.h"
  19. #include "indices.h"
  20. #include "api.h"
  21. #define element_type_name(e) element_type_names[(e)->type]
  22. #define TREE_ROOT_VAR "$TREE"
  23. static int indent = 0;
  24. /* A dump to fill in references from one part of the tree to another. */
  25. static TEXT fixup_dump;
  26. /* A dump for information about the indices. */
  27. static TEXT indices_dump;
  28. /* A dump to fill in references from the parse tree to the indices
  29. information. */
  30. static TEXT tree_to_indices_dump;
  31. void dump_contents (ELEMENT *, TEXT *);
  32. void dump_element (ELEMENT *, TEXT *);
  33. void dump_args (ELEMENT *, TEXT *);
  34. /* Output INDENT spaces. */
  35. static void
  36. dump_indent (TEXT *text)
  37. {
  38. int i;
  39. for (i = 0; i < indent; i++)
  40. text_append_n (text, " ", 1);
  41. }
  42. /* Ouput S escaping single quotes and backslashes, so that
  43. Perl can read it in when it is surrounded by single quotes. */
  44. void
  45. dump_string (char *s, TEXT *text)
  46. {
  47. while (*s)
  48. {
  49. if (*s == '\''
  50. || *s == '\\')
  51. text_append_n (text, "\\", 1);
  52. text_append_n (text, s++, 1);
  53. }
  54. }
  55. void
  56. dump_args (ELEMENT *e, TEXT *text)
  57. {
  58. int i;
  59. int not_in_tree = 0;
  60. /* Don't set routing information if not dumping from a route
  61. directly from the root, that is via an extra value. */
  62. if (e->parent_type == route_not_in_tree
  63. || (e->parent_type == route_uninitialized && e->parent))
  64. not_in_tree = 1;
  65. text_append_n (text, "[\n", 2);
  66. indent += 2;
  67. for (i = 0; i < e->args.number; i++)
  68. {
  69. if (!not_in_tree)
  70. {
  71. e->args.list[i]->parent_type = route_args;
  72. e->args.list[i]->index_in_parent = i;
  73. }
  74. dump_indent (text);
  75. dump_element (e->args.list[i], text);
  76. text_append_n (text, ",\n", 2);
  77. }
  78. indent -= 2;
  79. dump_indent (text);
  80. text_append_n (text, "],\n", 3);
  81. }
  82. void
  83. dump_contents (ELEMENT *e, TEXT *text)
  84. {
  85. int i;
  86. int not_in_tree = 0;
  87. /* Don't set routing information if not dumping from a route
  88. directly from the root, that is via an extra value. */
  89. if (e->parent_type == route_not_in_tree
  90. || (e->parent_type == route_uninitialized && e->parent))
  91. not_in_tree = 1;
  92. text_append_n (text, "[\n", 2);
  93. indent += 2;
  94. for (i = 0; i < e->contents.number; i++)
  95. {
  96. if (!not_in_tree)
  97. {
  98. e->contents.list[i]->parent_type = route_contents;
  99. e->contents.list[i]->index_in_parent = i;
  100. }
  101. dump_indent (text);
  102. dump_element (e->contents.list[i], text);
  103. text_append_n (text, ",\n", 2);
  104. }
  105. indent -= 2;
  106. dump_indent (text);
  107. text_append_n (text, "],\n", 3);
  108. }
  109. /* Recursively go up to the root of the tree. On the way back print the path
  110. to the element into DUMP. */
  111. void
  112. dump_route_to_element (ELEMENT *e, TEXT *dump)
  113. {
  114. if (e->parent)
  115. dump_route_to_element (e->parent, dump);
  116. switch (e->parent_type)
  117. {
  118. case route_args:
  119. text_append (dump, "{'args'}");
  120. text_printf (dump, "[%d]", e->index_in_parent);
  121. break;
  122. case route_contents:
  123. text_append (dump, "{'contents'}");
  124. text_printf (dump, "[%d]", e->index_in_parent);
  125. break;
  126. case route_uninitialized:
  127. if (e->parent)
  128. abort ();
  129. text_append (dump, TREE_ROOT_VAR "->");
  130. break;
  131. default:
  132. abort ();
  133. }
  134. }
  135. /* Append to FIXUP_DUMP a line assigning the I'th 'extra' key of E. */
  136. void
  137. dump_fixup_line (ELEMENT *e, int i)
  138. {
  139. dump_route_to_element (e, &fixup_dump);
  140. text_printf (&fixup_dump, "{'extra'}{'%s'}", e->extra[i].key);
  141. text_append (&fixup_dump, " = ");
  142. dump_route_to_element (e->extra[i].value, &fixup_dump);
  143. switch (e->extra[i].type)
  144. {
  145. case extra_element:
  146. break;
  147. case extra_element_contents:
  148. text_append (&fixup_dump, "->{'contents'}");
  149. break;
  150. case extra_element_text:
  151. text_append (&fixup_dump, "->{'text'}");
  152. break;
  153. default:
  154. abort ();
  155. }
  156. text_append (&fixup_dump, ";\n");
  157. }
  158. static void
  159. dump_node_spec (NODE_SPEC_EXTRA *value, TEXT *text)
  160. {
  161. text_append_n (text, "{\n", 2);
  162. indent += 2;
  163. if (value->manual_content)
  164. {
  165. dump_indent (text);
  166. text_append (text, "'manual_content' => ");
  167. dump_contents (value->manual_content, text);
  168. }
  169. if (value->node_content)
  170. {
  171. dump_indent (text);
  172. text_append (text, "'node_content' => ");
  173. dump_contents (value->node_content, text);
  174. }
  175. indent -= 2;
  176. dump_indent (text);
  177. text_append_n (text, "},\n", 3);
  178. }
  179. /* Dump a skeleton for the 'extra' key. For each key, if the referenced
  180. element has been dumped yet and we know its, append a line filling in the
  181. value of the key to FIXUP_DUMP. Otherwise, record the reference in the
  182. 'pending_references' field. Look through the pending references in E itself
  183. for references to this element from elsewhere. */
  184. void
  185. dump_extra (ELEMENT *e, TEXT *text)
  186. {
  187. int i;
  188. text_append_n (text, "{\n", 2);
  189. indent += 2;
  190. if (e->extra_number > 0)
  191. {
  192. for (i = 0; i < e->extra_number; i++)
  193. {
  194. if (e->extra[i].type == extra_deleted)
  195. continue;
  196. if (e->extra[i].type == extra_index_entry)
  197. {
  198. /* A "index_entry" extra key on a command defining an index
  199. entry. Unlike the other keys, the value is not in the
  200. main parse tree, but in the indices_information. It would
  201. be much nicer if we could get rid of the need for this key. */
  202. INDEX_ENTRY_REF *ire = (INDEX_ENTRY_REF *) e->extra[i].value;
  203. INDEX_ENTRY *value = &ire->index->index_entries[ire->entry];
  204. dump_route_to_element (e, &tree_to_indices_dump);
  205. text_printf (&tree_to_indices_dump, "{'extra'}{'%s'} = ",
  206. e->extra[i].key);
  207. text_printf (&tree_to_indices_dump,
  208. "$INDEX_NAMES->{'%s'}{'index_entries'}[%d];\n",
  209. value->index_name, value->number - 1);
  210. /* value->number is 1-based so we needed to subtract 1. */
  211. continue;
  212. }
  213. dump_indent (text);
  214. if (e->extra[i].type == extra_misc_args)
  215. {
  216. int j;
  217. /* A "misc_args" value is just an array of strings. */
  218. text_append_n (text, "'", 1);
  219. text_append (text, e->extra[i].key);
  220. text_append (text, "' => [");
  221. for (j = 0; j < e->extra[i].value->contents.number; j++)
  222. {
  223. if (e->extra[i].value->contents.list[j]->text.end > 0)
  224. {
  225. text_append_n (text, "'", 1);
  226. dump_string(e->extra[i].value->contents.list[j]
  227. ->text.text, text);
  228. text_append_n (text, "',", 2);
  229. }
  230. /* else an error? */
  231. }
  232. text_append_n (text, "],\n", 3);
  233. }
  234. else if (e->extra[i].type == extra_node_spec)
  235. {
  236. NODE_SPEC_EXTRA *value = (NODE_SPEC_EXTRA *) e->extra[i].value;
  237. text_printf (text, "'%s' => ", e->extra[i].key);
  238. dump_node_spec (value, text);
  239. }
  240. else if (e->extra[i].type == extra_node_spec_array)
  241. {
  242. NODE_SPEC_EXTRA **array = (NODE_SPEC_EXTRA **) e->extra[i].value;
  243. text_append_n (text, "'", 1);
  244. text_append (text, e->extra[i].key);
  245. text_append (text, "' => [\n");
  246. while (*array)
  247. {
  248. dump_indent (text);
  249. dump_node_spec (*array, text);
  250. array++;
  251. }
  252. dump_indent (text);
  253. text_append_n (text, "],\n", 3);
  254. }
  255. else if (e->extra[i].type == extra_string)
  256. {
  257. char *value = (char *) e->extra[i].value;
  258. text_append_n (text, "'", 1);
  259. text_append (text, e->extra[i].key);
  260. text_append (text, "' => '");
  261. dump_string (value, text);
  262. text_append_n (text, "',\n", 3);
  263. }
  264. else if (e->extra[i].type == extra_def_args)
  265. {
  266. DEF_ARGS_EXTRA *value = (DEF_ARGS_EXTRA *) e->extra[i].value;
  267. int j;
  268. char *label;
  269. text_append_n (text, "'", 1);
  270. text_append (text, e->extra[i].key);
  271. text_append (text, "' => [\n");
  272. for (j = 0; j < value->nelements; j++)
  273. {
  274. label = value->labels[j];
  275. dump_indent (text);
  276. text_append_n (text, "['", 2);
  277. text_append (text, label);
  278. text_append_n (text, "', ", 3);
  279. dump_element (value->elements[j], text);
  280. text_append_n (text, "],\n", 3);
  281. }
  282. dump_indent (text);
  283. text_append_n (text, "],\n", 3);
  284. /* TODO: Also output a "def_parsed_hash". */
  285. }
  286. else if (e->extra[i].value->parent_type == route_not_in_tree)
  287. {
  288. switch (e->extra[i].type)
  289. {
  290. int j;
  291. case extra_element:
  292. dump_element (e->extra[i].value, text);
  293. break;
  294. case extra_element_contents:
  295. text_append_n (text, "'", 1);
  296. text_append (text, e->extra[i].key);
  297. text_append (text, "' => ");
  298. dump_contents (e->extra[i].value, text);
  299. break;
  300. case extra_element_contents_array:
  301. /* Like extra_element_contents, but this time output an array
  302. of arrays (instead of an array). */
  303. text_append_n (text, "'", 1);
  304. text_append (text, e->extra[i].key);
  305. text_append (text, "' => [\n");
  306. indent += 2;
  307. for (j = 0; j < e->extra[i].value->contents.number; j++)
  308. {
  309. dump_indent (text);
  310. dump_contents (e->extra[i].value->contents.list[j],
  311. text);
  312. }
  313. indent -= 2;
  314. dump_indent (text);
  315. text_append (text, "],\n");
  316. break;
  317. default:
  318. abort ();
  319. }
  320. }
  321. else
  322. {
  323. if (e->extra[i].type != extra_element)
  324. abort ();
  325. text_append_n (text, "'", 1);
  326. text_append (text, e->extra[i].key);
  327. text_append (text, "' => {},\n");
  328. if (e->extra[i].value->parent_type != route_uninitialized)
  329. {
  330. dump_fixup_line (e, i);
  331. }
  332. else /* Add a pending reference to this element. */
  333. {
  334. ELEMENT *e2;
  335. e2 = e->extra[i].value;
  336. if (e2->pending_number == e2->pending_space)
  337. {
  338. e2->pending_references = realloc (e2->pending_references,
  339. (e2->pending_space += 2) * sizeof (PENDING_REFERENCE));
  340. if (!e2->pending_references)
  341. abort ();
  342. }
  343. e2->pending_references[e2->pending_number].element = e;
  344. e2->pending_references[e2->pending_number++].extra_index = i;
  345. }
  346. }
  347. }
  348. }
  349. if (e->pending_number > 0)
  350. {
  351. for (i = 0; i < e->pending_number; i++)
  352. {
  353. ELEMENT *referring;
  354. int index;
  355. referring = e->pending_references[i].element;
  356. index = e->pending_references[i].extra_index;
  357. dump_fixup_line (referring, index);
  358. }
  359. }
  360. indent -= 2;
  361. dump_indent (text);
  362. text_append_n (text, "},\n", 3);
  363. }
  364. void
  365. dump_line_nr (LINE_NR *line_nr, TEXT *text)
  366. {
  367. text_append_n (text, "{\n", 2);
  368. indent += 2;
  369. dump_indent (text);
  370. text_printf (text, "'file_name' => '%s',\n",
  371. line_nr->file_name ?
  372. line_nr->file_name : "");
  373. if (line_nr->line_nr)
  374. {
  375. dump_indent (text);
  376. text_append (text, "'line_nr' => ");
  377. text_printf (text, "%d", line_nr->line_nr);
  378. text_append (text, ",\n");
  379. }
  380. /* TODO: macro. */
  381. if (line_nr->macro)
  382. {
  383. dump_indent (text);
  384. text_append (text, "'macro' => ");
  385. text_printf (text, "'%s'", line_nr->macro);
  386. text_append (text, ",\n");
  387. }
  388. else
  389. {
  390. dump_indent (text);
  391. text_append (text, "'macro' => ''\n");
  392. }
  393. indent -= 2;
  394. dump_indent (text);
  395. text_append_n (text, "},\n", 3);
  396. }
  397. void
  398. dump_element (ELEMENT *e, TEXT *text)
  399. {
  400. text_append_n (text, "{\n", 2);
  401. indent += 2;
  402. if (e->type)
  403. {
  404. dump_indent (text);
  405. if (e->cmd != CM_verb)
  406. text_printf (text, "'type' => '%s',\n", element_type_name(e));
  407. else
  408. {
  409. char c = (char) e->type;
  410. text_printf (text, "'type' => '");
  411. if (c == '\'' || c == '\\') /* Escaping for Perl. */
  412. text_append_n (text, "\\", 1);
  413. text_append_n (text, &c, 1);
  414. text_printf (text, "',\n");
  415. }
  416. }
  417. if (e->cmd)
  418. {
  419. dump_indent (text);
  420. text_append (text, "'cmdname' => '");
  421. dump_string (command_data(e->cmd).cmdname, text);
  422. text_append_n (text, "',\n", 3);
  423. }
  424. if (e->line_nr.line_nr)
  425. {
  426. dump_indent (text);
  427. text_append (text, "'line_nr' => ");
  428. dump_line_nr (&e->line_nr, text);
  429. }
  430. if (e->text.text)
  431. {
  432. dump_indent (text);
  433. text_append (text, "'text' => '");
  434. dump_string (e->text.text, text);
  435. text_append_n (text, "',\n", 3);
  436. }
  437. if (e->args.number > 0)
  438. {
  439. dump_indent (text);
  440. text_append (text, "'args' => ");
  441. dump_args (e, text);
  442. }
  443. if (e->extra_number > 0)
  444. {
  445. dump_indent (text);
  446. text_append (text, "'extra' => ");
  447. dump_extra (e, text);
  448. }
  449. if (e->contents.number > 0)
  450. {
  451. dump_indent (text);
  452. text_append (text, "'contents' => ");
  453. dump_contents (e, text);
  454. }
  455. indent -= 2;
  456. dump_indent (text);
  457. text_append_n (text, "}", 1);
  458. }
  459. /* Append to FIXUP_DUMP information about the labels. */
  460. static void
  461. dump_labels_information (void)
  462. {
  463. int i;
  464. text_append (&fixup_dump, "\n$TARGETS = [\n");
  465. for (i = 0; i < labels_number; i++)
  466. {
  467. dump_route_to_element (labels_list[i].target, &fixup_dump);
  468. text_append (&fixup_dump, ",\n");
  469. }
  470. text_append (&fixup_dump, "];\n");
  471. }
  472. static void
  473. dump_entries_of_index (INDEX *idx)
  474. {
  475. int i;
  476. INDEX_ENTRY *e;
  477. if (idx->index_number == 0)
  478. return;
  479. text_printf (&indices_dump, "\n'index_entries' => [");
  480. for (i = 0; i < idx->index_number; i++)
  481. {
  482. e = &idx->index_entries[i];
  483. text_printf (&indices_dump, "\n{");
  484. text_printf (&indices_dump, "'index_name' => '%s',", e->index_name);
  485. text_printf (&indices_dump, "'index_prefix' => '%s',", e->index_prefix);
  486. text_printf (&indices_dump, "\n");
  487. text_printf (&indices_dump, "'index_at_command' => '%s',",
  488. command_data(e->index_at_command).cmdname);
  489. text_printf (&indices_dump, "'index_type_command' => '%s',\n",
  490. command_data(e->index_type_command).cmdname);
  491. text_printf (&indices_dump, "'command' => ");
  492. dump_route_to_element (e->command, &indices_dump);
  493. text_printf (&indices_dump, ",\n");
  494. text_printf (&indices_dump, "'number' => %d,", e->number);
  495. if (e->content)
  496. {
  497. text_printf (&indices_dump, "'content' => ");
  498. if (e->content->parent_type != route_not_in_tree)
  499. dump_route_to_element (e->content, &indices_dump);
  500. else
  501. dump_element (e->content, &indices_dump);
  502. text_printf (&indices_dump, "{'contents'}");
  503. text_printf (&indices_dump, ",\n");
  504. }
  505. if (e->node)
  506. {
  507. text_printf (&indices_dump, "'node' => ");
  508. dump_route_to_element (e->node, &indices_dump);
  509. text_printf (&indices_dump, ",\n");
  510. }
  511. text_printf (&indices_dump, "},");
  512. }
  513. text_printf (&indices_dump, "],\n");
  514. }
  515. /* Append to INDICES_DUMP information about the indices. */
  516. static void
  517. dump_indices_information (void)
  518. {
  519. INDEX **i, *idx;
  520. text_append (&indices_dump, "\n$INDEX_NAMES = {\n");
  521. for (i = index_names; (idx = *i); i++)
  522. {
  523. text_printf (&indices_dump, "'%s' => {", idx->name);
  524. text_printf (&indices_dump, "'name' => '%s',", idx->name);
  525. text_printf (&indices_dump, "'in_code' => 0,");
  526. /* TODO: This is a list of recognized prefixes for the index. */
  527. text_printf (&indices_dump, "'prefix' => ['%c', '%s'],",
  528. *idx->name, idx->name);
  529. /* TODO: Handle index merging. */
  530. text_printf (&indices_dump, "'contained_indices' => {'%s'=>1},",
  531. idx->name);
  532. dump_entries_of_index (idx);
  533. text_printf (&indices_dump, "},\n");
  534. }
  535. text_append (&indices_dump, "};\n");
  536. }
  537. void
  538. dump_tree_to_perl (ELEMENT *root)
  539. {
  540. TEXT output;
  541. text_init (&output);
  542. text_init (&fixup_dump);
  543. text_init (&tree_to_indices_dump);
  544. text_append (&output, TREE_ROOT_VAR " = ");
  545. dump_element (root, &output);
  546. text_append_n (&output, ";\n", 2);
  547. /* All the elements in the tree have routing information now. */
  548. if (output.end > 0)
  549. printf ("%s", output.text);
  550. //dump_labels_information ();
  551. //dump_indices_information ();
  552. if (fixup_dump.end > 0)
  553. printf ("%s", fixup_dump.text);
  554. if (indices_dump.end > 0)
  555. printf ("%s", indices_dump.text);
  556. /* This must be output at the end so that both the tree and the indices
  557. will exist by the time this is read. */
  558. if (tree_to_indices_dump.end > 0)
  559. printf ("%s", tree_to_indices_dump.text);
  560. free (output.text);
  561. }
  562. /************************************************************/
  563. /* Following are functions each returning Perl code to be
  564. eval'd. When done in the right order the data will be
  565. transferred into the Perl program. */
  566. char *
  567. dump_root_element_1 (void)
  568. {
  569. ELEMENT *e = Root;
  570. TEXT textb;
  571. TEXT *text;
  572. text = &textb;
  573. text_init (text);
  574. text_append (text, TREE_ROOT_VAR " = ");
  575. text_append_n (text, "{\n", 2);
  576. indent += 2;
  577. if (e->type)
  578. {
  579. dump_indent (text);
  580. text_printf (text, "'type' => '%s',\n", element_type_name(e));
  581. }
  582. if (e->cmd)
  583. {
  584. dump_indent (text);
  585. text_append (text, "'cmdname' => '");
  586. dump_string (command_data(e->cmd).cmdname, text);
  587. text_append_n (text, "',\n", 3);
  588. }
  589. if (e->line_nr.line_nr)
  590. {
  591. dump_indent (text);
  592. text_append (text, "'line_nr' => ");
  593. dump_line_nr (&e->line_nr, text);
  594. }
  595. if (e->text.text)
  596. {
  597. dump_indent (text);
  598. text_append (text, "'text' => '");
  599. dump_string (e->text.text, text);
  600. text_append_n (text, "',\n", 3);
  601. }
  602. if (e->args.number > 0)
  603. {
  604. dump_indent (text);
  605. text_append (text, "'args' => ");
  606. dump_args (e, text);
  607. }
  608. if (e->extra_number > 0)
  609. {
  610. dump_indent (text);
  611. text_append (text, "'extra' => ");
  612. dump_extra (e, text);
  613. }
  614. text_append_n (text, "};\n", 3);
  615. return textb.text;
  616. }
  617. char *
  618. dump_root_element_2 (void)
  619. {
  620. static int i = 0;
  621. TEXT text;
  622. ELEMENT *e = Root;
  623. if (i == e->contents.number)
  624. {
  625. i++;
  626. return 0;
  627. }
  628. text_init (&text);
  629. text_printf (&text, TREE_ROOT_VAR "->{'contents'}[%d] = ", i);
  630. e->contents.list[i]->parent_type = route_contents;
  631. e->contents.list[i]->index_in_parent = i;
  632. dump_element (e->contents.list[i], &text);
  633. text_append (&text, ";");
  634. i++;
  635. return text.text;
  636. }
  637. char *
  638. dump_tree_to_string_1 (void)
  639. {
  640. text_init (&fixup_dump);
  641. text_init (&indices_dump);
  642. text_init (&tree_to_indices_dump);
  643. return "";
  644. }
  645. char *
  646. dump_tree_to_string_2 (void)
  647. {
  648. dump_labels_information ();
  649. if (fixup_dump.end > 0)
  650. return fixup_dump.text;
  651. return "";
  652. }
  653. char *
  654. dump_tree_to_string_25 (void)
  655. {
  656. dump_indices_information ();
  657. if (indices_dump.end > 0)
  658. return indices_dump.text;
  659. return "";
  660. }
  661. char *
  662. dump_tree_to_string_3 (void)
  663. {
  664. /* This must be output at the end so that both the tree and the indices
  665. will exist by the time this is read. */
  666. if (tree_to_indices_dump.end > 0)
  667. return tree_to_indices_dump.text;
  668. return "";
  669. }