/* ================================================================================ RPL/2 (R) version 4.1.18 Copyright (C) 1989-2014 Dr. BERTRAND Joël This file is part of RPL/2. RPL/2 is free software; you can redistribute it and/or modify it under the terms of the CeCILL V2 License as published by the french CEA, CNRS and INRIA. RPL/2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License for more details. You should have received a copy of the CeCILL License along with RPL/2. If not, write to info@cecill.info. ================================================================================ */ #include "rpl-conv.h" /* ================================================================================ Fonction 'simplification' (ne libère pas les paramètres) ================================================================================ Entrées : pointeur sur une structure struct_processus -------------------------------------------------------------------------------- Sorties : -------------------------------------------------------------------------------- Effets de bord : néant ================================================================================ */ struct_objet * simplification(struct_processus *s_etat_processus, struct_objet *s_objet) { #ifdef EXPERIMENTAL_CODE struct_arbre *s_arbre; struct_arbre *s_noeud_courant; struct_liste_chainee *l_element_courant; #endif struct_objet *s_objet_simplifie; #ifdef EXPERIMENTAL_CODE struct_objet **t_expression; unsigned long i; unsigned long nombre_elements; s_arbre = NULL; #endif if ((*s_objet).type == ALG) { #ifdef EXPERIMENTAL_CODE // Inversion de l'ordre des instructions dans l'expression nombre_elements = 0; l_element_courant = (*s_objet).objet; while(l_element_courant != NULL) { nombre_elements++; l_element_courant = (*l_element_courant).suivant; } if ((t_expression = malloc(nombre_elements * sizeof(struct_objet *))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return(NULL); } i = nombre_elements - 1; l_element_courant = (*s_objet).objet; while(l_element_courant != NULL) { if ((t_expression[i--] = copie_objet(s_etat_processus, (*l_element_courant).donnee, 'O')) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return(NULL); } l_element_courant = (*l_element_courant).suivant; } // L'objet est toujours évaluable car il s'agit d'une expression // algébrique (cela revient à dire qu'il n'y a qu'un seul arbre // et que celui-ci est terminé). s_arbre = creation_arbre(s_etat_processus, t_expression, 0, nombre_elements - 1); for(i = 0; i < nombre_elements; liberation(t_expression[i++])); free(t_expression); #endif s_objet_simplifie = copie_objet(s_etat_processus, s_objet, 'P'); // On essaye déjà de voir si l'arbre est cohérent... } else { s_objet_simplifie = copie_objet(s_etat_processus, s_objet, 'P'); } return(s_objet_simplifie); } /* ================================================================================ Fonction créant un noeud dans l'arbre ================================================================================ Entrées : pointeur sur une structure struct_arbre -------------------------------------------------------------------------------- Sorties : -------------------------------------------------------------------------------- Effets de bord : néant ================================================================================ */ struct_arbre * creation_arbre(struct_processus *s_etat_processus, struct_objet **t_objets, integer8 indice, integer8 indice_maximal) { struct_arbre *s_noeud; //unsigned long i; if ((s_noeud = malloc(sizeof(struct_arbre))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return(NULL); } // indice ne peut jamais être supérieur à indice_maximal #if 0 // Création de la racine de l'arbre if ((s_arbre = malloc(sizeof(struct_arbre))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return(NULL); } s_noeud_courant = s_arbre; for(i = 0; i < nombre_elements; i++) { if (strcmp((*t_expression[i]).type, "FCT") == 0) { if ((strcmp((*((struct_fonction *) (*t_expression[i]).objet)) .nom_fonction, "<<") != 0) && (strcmp((*((struct_fonction *) (*t_expression[i]).objet)).nom_fonction, ">>") != 0)) { // Création d'un noeud } } } #endif return(NULL); } /* ================================================================================ Fonction simplifiant l'arbre q-aire en arbre q'-aire (q <= q') ================================================================================ Entrées : pointeur sur une structure struct_arbre -------------------------------------------------------------------------------- Sorties : -------------------------------------------------------------------------------- Effets de bord : néant ================================================================================ */ void simplification_arbre(struct_processus *s_etat_processus, struct_arbre *s_noeud) { unsigned long i; if ((*s_noeud).feuilles != NULL) { for(i = 0; i < (*s_noeud).nombre_feuilles; i++) { simplification_arbre(s_etat_processus, (*s_noeud).feuilles[i]); /* * Si le noeud est une fonction compatible avec une fonction * présente dans les feuilles, on réunit les deux. */ if ((*(*((*s_noeud).feuilles[i])).objet).type == FCT) { if (((strcmp((*((struct_fonction *) (*s_noeud).objet)) .nom_fonction, "+") == 0) && (strcmp( (*((struct_fonction *) (*(*((*s_noeud).feuilles[i])) .objet).objet)).nom_fonction, "+") == 0)) || ((strcmp((*((struct_fonction *) (*s_noeud).objet)) .nom_fonction, "*") == 0) && (strcmp( (*((struct_fonction *) (*(*((*s_noeud).feuilles[i])) .objet).objet)).nom_fonction, "*") == 0))) { } } } } return; } /* ================================================================================ Fonction parcourant l'arbre q-aire ================================================================================ Entrées : pointeur sur une structure struct_arbre -------------------------------------------------------------------------------- Sorties : -------------------------------------------------------------------------------- Effets de bord : néant ================================================================================ */ void parcours_arbre(struct_processus *s_etat_processus, struct_arbre *s_noeud) { unsigned long i; if ((*s_noeud).feuilles != NULL) { for(i = 0; i < (*s_noeud).nombre_feuilles; i++) { parcours_arbre(s_etat_processus, (*s_noeud).feuilles[i]); } } return; } /* ================================================================================ Fonction libérant l'arbre q-aire ================================================================================ Entrées : pointeur sur une structure struct_arbre -------------------------------------------------------------------------------- Sorties : -------------------------------------------------------------------------------- Effets de bord : néant ================================================================================ */ void liberation_arbre(struct_processus *s_etat_processus, struct_arbre *s_noeud) { unsigned long i; if ((*s_noeud).feuilles != NULL) { for(i = 0; i < (*s_noeud).nombre_feuilles; i++) { } } return; } // vim: ts=4