Output tree in Aroma SPT JSON format. See aroma-schema.json. */
| 155 | /** Output tree in Aroma SPT JSON format. See aroma-schema.json. |
| 156 | */ |
| 157 | static void show_spt(Graph g, FILE *fp) |
| 158 | { |
| 159 | unsigned indent = 0; |
| 160 | Node root = g->root ? node_find(g, g->root) : NULL; |
| 161 | if (!root || !check_tree(root)) { |
| 162 | fprintf(stderr, "(F): Graph has no root, or is not a tree.\n"); |
| 163 | exit(7); |
| 164 | } |
| 165 | |
| 166 | fputc('{', fp); |
| 167 | if (pprint) { |
| 168 | fputc('\n', fp); |
| 169 | indent = 2; |
| 170 | } |
| 171 | fprintf(fp, "%*s\"path\":", indent, ""); |
| 172 | if (filename) { |
| 173 | fputc('"', fp); |
| 174 | fputs(filename, fp); /* assume no need to escape any char */ |
| 175 | fputc('"', fp); |
| 176 | } |
| 177 | else |
| 178 | if (g->label) |
| 179 | show(fp, g->label, 1); |
| 180 | else |
| 181 | fputs("\"jgf2spt\"", fp); |
| 182 | fputc(',', fp); |
| 183 | if (pprint) fputc('\n', fp); |
| 184 | /* Fake class, method, beginline, endline: */ |
| 185 | fprintf(fp, "%*s\"class\":\"MyClass\",", indent, ""); |
| 186 | if (pprint) fputc('\n', fp); |
| 187 | fprintf(fp, "%*s\"method\":\"MyMethod\",", indent, ""); |
| 188 | if (pprint) fputc('\n', fp); |
| 189 | fprintf(fp, "%*s\"beginline\":1,", indent, ""); |
| 190 | if (pprint) fputc('\n', fp); |
| 191 | fprintf(fp, "%*s\"endline\":10,", indent, ""); |
| 192 | if (pprint) fputc('\n', fp); |
| 193 | |
| 194 | fprintf(fp, "%*s\"ast\":", indent, ""); |
| 195 | show_spt_aux(root, indent, fp); |
| 196 | if (pprint) fputc('\n', fp); |
| 197 | fputs("}\n", fp); |
| 198 | } |
| 199 | |
| 200 | int main(int argc, char *argv[]) |
| 201 | { |
no test coverage detected