graphVizHelper.c
Description du code
Génération d'une image d'un arbre syntaxique abstrait.Classe d'intégration de l'outil GraphViz. Compilateur LSD010
Code source ou contenu du fichier
Code c (graphVizHelper.c) (235 lignes)
/* * graphVizHelper.c : Helper for the graphViz tool (generation of images from a tree) * @see http://www.graphviz.org/doc/info/command.html * Part of the compiler project for LSD10 language * Gaudry Stéphane * More information on http://www.gaudry.be/programmer-arbre-image-noeuds.html */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include "common.h" #include "graphVizHelper.h" #include "y.tab.h" #if(VERBOSE_LEVEL<=DEB_E) #include <errno.h> #endif extern AstNode *rootNode; /* * ********************************************************** * Internal business * ********************************************************** */ #define GRAPH_RIGHT 0 #define GRAPH_LEFT 1 #define GRAPH_ROOT -1 int isGraphVisInstalled() { return 1;//todo : get it dynamically } /** * http://www.graphviz.org/doc/info/command.html */ void generateImage(char *dotFileName) { time_t now; struct tm *timeinfo; char commandString[100]; //todo : set the timeinfo int values on a 2 digits format commandString, "%slsd10_Img%d%d%d%d%d%d.jpg %s", "dot -Tjpg -o", timeinfo->tm_year+1900, timeinfo->tm_mon+1, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, dotFileName); int ret = 0; //printf ("ret = %d\n", ret); } void printGraphDotHeader(FILE * graphFile) { if(graphFile!=NULL) { } } void printGraphDotFooter(FILE * graphFile) { if(graphFile!=NULL) { time_t now; struct tm *timeinfo; // fprintf(graphFile, "}\n"); // fprintf(graphFile, "digraph INFO{\n"); graphFile, "\t\"Generated by the SSHD09 LSD010 compiler\\n%d/%d/%d %dHr %d\\nWith GraphViz engine\" [", timeinfo->tm_mday, timeinfo->tm_mon+1, timeinfo->tm_year+1900, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec ); } } /** * Prints an AST node into the graph file * Pre-condition : dotFile not null */ void printGraphNode(FILE *dotFile, AstNode *node, int depth, int psn) { if(node!=NULL) { if(node->parent!=NULL) { } else { } dotFile, "\"%p\";\n\t\"%p\" [shape=%s, color=\"%s\", fontcolor=\"%s\", label=\"%s%s%s%s : \\n%s %s\\nLine %d char %d\"];\n",//print position? node, node, //node->type>LEX_FIRST_TOKEN&&node->type<LEX_LAST_TOKEN?"polygon":"box", psn==GRAPH_LEFT?"hexagon":(psn==GRAPH_RIGHT?"box":"doublecircle"), (node->type==NODE_TYPE_DECLARATION || node->type==NODE_TYPE_FUNCTION || node->type==NODE_TYPE_PARAM_DECL )?"#677E96":psn==GRAPH_LEFT?"#e6e8f2":(psn==GRAPH_RIGHT?"#AAB5C6":"#C0C0C0"), (node->type==NODE_TYPE_DECLARATION || node->type==NODE_TYPE_FUNCTION || node->type==NODE_TYPE_PARAM_DECL )?"#FFFFFF":"#000000", typeToString(node->type), node->subtype!=NODE_TYPE_NOTHING?" (":"", node->subtype!=NODE_TYPE_NOTHING?typeToString(node->subtype):"", node->subtype!=NODE_TYPE_NOTHING?")":"", typeToString(node->info->type), node->info->name, node->debug->line, node->debug->linePsn ); printGraphNode(dotFile, node->left, depth+1, GRAPH_LEFT); printGraphNode(dotFile, node->right, depth+1, GRAPH_RIGHT); } //else fprintf(dotFile, "null"); } void printGraphDotFromXML(char *xmlFileName, char *dotFileName) { FILE * graphFile; if(xmlFileName==NULL)xmlFileName=AST_XML_FILE; if(dotFileName==NULL)dotFileName=GRAPHVIZ_CONFIG_FILE; if(graphFile!=NULL) { printf("\n;\tGenerating AST Graph from %s into %s file ... (%s, col %d)", xmlFileName, dotFileName, __FILE__, __LINE__); printGraphDotHeader(graphFile); //todo : read info from XML file to generate the dot file printGraphDotFooter(graphFile); #if(VERBOSE_LEVEL<=DEB_EXEC) printMsg(DEB_EXEC,"...OK Graph printed", __FILE__, __LINE__); #endif if(isGraphVisInstalled()==1) { generateImage(dotFileName); } } else { #if(VERBOSE_LEVEL<=DEB_EXEC) printMsg(DEB_EXEC,"Printing AST into Graph file ... Can't open file", __FILE__, __LINE__); #endif } } void printGraphDotFromAST(char *dotFileName) { FILE * graphFile; if(dotFileName==NULL)dotFileName=GRAPHVIZ_CONFIG_FILE; if(graphFile!=NULL) { printf("\n;\tGenerating AST Graph from last compilation into %s file ... (%s, col %d)", dotFileName, __FILE__, __LINE__); printGraphDotHeader(graphFile); printGraphNode(graphFile, rootNode, 0, GRAPH_ROOT); printGraphDotFooter(graphFile); #if(VERBOSE_LEVEL<=DEB_EXEC) printMsg(DEB_EXEC,"...OK Graph printed", __FILE__, __LINE__); #endif } else { #if(VERBOSE_LEVEL<=DEB_EXEC) printMsg(DEB_EXEC,"Printing AST into Graph file ... Can't open file", __FILE__, __LINE__); #endif } } /* * ********************************************************** * Implementation of the header exposed items * See graphVizHelper.h for these functions comments * ********************************************************** */ void printGraph() { printGraphDotFromAST(GRAPHVIZ_CONFIG_FILE); if(isGraphVisInstalled()==1) { generateImage(GRAPHVIZ_CONFIG_FILE); } }
Autres extraits de codes en c
- DisquetteDispo Vérifier la disponibilité du lecteur de disquette
- Suite de Fibonacci Exemple d'itération en C
- Suite de Fibonacci Exemple de récursion en C
- astDataRepresentation.h Représentation de données de l'arbre syntaxique abstrait Compilateur LSD010
- ast.h Arbre syntaxique abstrait Compilateur LSD010
- ast.c Arbre syntaxique abstrait Compilateur LSD010
- symbolsTableDataRepresentation.h Représentation de données de la table des symboles Compilateur LSD010
- symbolsTable.h Fonctions de gestion de la table des symboles Compilateur LSD010
- symbolsTable.c Fonctions de gestion de la table des symboles Compilateur LSD010
- hashCode.h Fonctions de hachage Compilateur LSD010
- hashCode.c Fonctions de hachage Compilateur LSD010
- scopeStack.h Fonctions de gestion d'une pile de portées Compilateur LSD010
- scopeStack.c Fonctions de gestion d'une pile de portées Compilateur LSD010
- scopeHelper.h Fonctions de gestion de la portée courante Compilateur LSD010
- console.h Fonctions d'affichage Compilateur LSD010
- console.c Fonctions d'affichage Compilateur LSD010
- graphVizHelper.h Génération d'une image d'un arbre syntaxique abstrait.
Classe d'intégration de l'outil GraphViz. Compilateur LSD010 - graphVizHelper.c Génération d'une image d'un arbre syntaxique abstrait.
Classe d'intégration de l'outil GraphViz. Compilateur LSD010 - common.h Définition des constantes et variables communes Compilateur LSD010
- pcode.c Génération de p-code Compilateur LSD010
- pcode.h Génération de p-code Compilateur LSD010
- Tous les extraits
Version en cache
09/03/2025 23:32:05 Cette version de la page est en cache (à la date du 09/03/2025 23:32:05) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 05/10/2009, dernière modification le 28/10/2018
Source du document imprimé : https://www.gaudry.be/sniplet-rf-lsd010/project/source/graphVizHelper.c.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.