/** * @brief writes the nodes of the tree to a file */ void writeTreeHelper(node *tree, FILE* f){ fprintf(f,"%ld [label=\"%s\"];\n",(long int)tree,tree->name); if( tree->left){ fprintf(f,"%ld -> %ld;\n",(long int)tree->left,(long int)tree); writeTreeHelper(tree->left,f); } if (tree->right){ fprintf(f,"%ld -> %ld;\n",(long int)tree->right,(long int)tree); writeTreeHelper(tree->right,f); } }
void writeOther(FILE * outc, FILE * outh, Object * tree, int indent) { ListObject *oIter; ListString *sIter; oIter = tree->definedSymbols; while (oIter != 0) { if (oIter->value->category == Variable) { //declare all local variables writeDeclareVariable (oIter, outc, tree); } else { writeTreeHelper(outc, outh, oIter->value, indent + 1); } oIter = oIter->next; } if (tree->code != 0 && tree->code->value != 0) { sIter = tree->code; while (sIter != 0) { fprintf(outc, "\t%s\n", sIter->value); sIter = sIter->next; } } }
void writeClass(FILE * outc, FILE * outh, Object * tree, int indent) { ListObject *oIter; oIter = tree->definedSymbols; //fprintf(outh, "%s %s " COMPILER_SEP "%s %s;\n", "typedef", "struct", tree->name, // tree->name); fprintf(outh, "%s " COMPILER_SEP "%s {\n", "struct", tree->name); while (oIter != 0) { if (oIter->value->category == Variable) { writeDeclareClassVariable (oIter, outh, tree); } else { oIter = oIter->next; break; } oIter = oIter->next; } fprintf(outh, "};\n"); while (oIter != 0) { if (isVerb(oIter->value)) { writeFunction(outh, tree, indent, false); } else { writeTreeHelper(outc, outh, tree, indent); } } }
/** * @brief Writes a tree to the provided filename. * The format of the file is such that it can be read by Graphviz */ void writeTree(node *tree, char *filename){ FILE* f = NULL; if ((f = fopen(filename,"w"))){ fprintf(f,"strict digraph G{\n"); writeTreeHelper(tree,f); fprintf(f,"}\n"); fclose(f); } else{ fprintf(stderr,"Could not open file %s\n",filename); } }
void writeTree(FILE * outc, FILE * outh, Object * tree) { writeTypeDefs(outh, tree); writeForwardDeclarations(outh, tree); writeTreeHelper(outc, outh, tree, 0); }