--- rpl/src/simplification.c 2019/11/11 13:16:25 1.73 +++ rpl/src/simplification.c 2019/11/14 18:54:48 1.74 @@ -141,10 +141,12 @@ transcription_arbre(struct_processus *s_ // Ajout des fonctions + if ((*s_arbre).nombre_branches != 0) + { + free((*s_arbre).branches); + } + l_liste = (*s_arbre).feuille; -uprintf("avant free %p\n", s_arbre->branches); - free((*s_arbre).branches); -uprintf("après free %p\n", s_arbre->branches); free(s_arbre); // Chaînage des arguments @@ -225,6 +227,39 @@ ordonnancement_branches(const void *a1, } +static int +ordonnancement_instructions_neg(const void *a1, const void *a2) +{ + struct_arbre **_a1; + + _a1 = (struct_arbre **) a1; + + if ((**_a1).feuille != NULL) + { + // On rejette NEG à la fin de l'arbre. + + if ((*(*(**_a1).feuille).donnee).type == FCT) + { + if (strcmp((*((struct_fonction *) (*(*(**_a1).feuille).donnee) + .objet)).nom_fonction, "NEG") == 0) + { + return(1); + } + else + { + return(-1); + } + } + else + { + return(0); + } + } + + return(0); +} + + static void simplification_arbre(struct_processus *s_etat_processus, struct_arbre *s_arbre) @@ -335,6 +370,10 @@ simplification_arbre(struct_processus *s if (strcmp((*((struct_fonction *) (*(*(*s_arbre).feuille).donnee).objet)) .nom_fonction, "+") == 0) { + qsort((*s_arbre).branches, (size_t) (*s_arbre) + .nombre_branches, sizeof(struct_arbre *), + ordonnancement_instructions_neg); + for(i = 0; i < (*s_arbre).nombre_branches; i++) { s_objet = (*((*((*s_arbre).branches[i])).feuille)).donnee;