Diff for /rpl/src/gestion_variables.c between versions 1.52 and 1.64

version 1.52, 2012/03/01 10:14:04 version 1.64, 2012/12/13 16:59:41
Line 1 Line 1
 /*  /*
 ================================================================================  ================================================================================
   RPL/2 (R) version 4.1.7    RPL/2 (R) version 4.1.11
   Copyright (C) 1989-2012 Dr. BERTRAND Joël    Copyright (C) 1989-2012 Dr. BERTRAND Joël
   
   This file is part of RPL/2.    This file is part of RPL/2.
Line 237  liste_variables_par_feuilles(struct_proc Line 237  liste_variables_par_feuilles(struct_proc
 ================================================================================  ================================================================================
 */  */
   
 static inline struct_arbre_variables *  struct_arbre_variables *
 allocation_noeud(struct_processus *s_etat_processus)  allocation_noeud(struct_processus *s_etat_processus)
 {  {
     struct_arbre_variables          *objet;      struct_arbre_variables          *objet;
Line 272  liberation_noeud(struct_processus *s_eta Line 272  liberation_noeud(struct_processus *s_eta
     return;      return;
 }  }
   
 static inline struct_arbre_variables **  struct_arbre_variables **
 allocation_tableau_noeuds(struct_processus *s_etat_processus)  allocation_tableau_noeuds(struct_processus *s_etat_processus)
 {  {
     struct_arbre_variables          **objet;      struct_arbre_variables          **objet;
Line 426  ajout_variable(struct_processus *s_etat_ Line 426  ajout_variable(struct_processus *s_etat_
         }          }
   
         (*(*s_etat_processus).s_arbre_variables).feuille = NULL;          (*(*s_etat_processus).s_arbre_variables).feuille = NULL;
           (*(*s_etat_processus).s_arbre_variables).feuille_statique = NULL;
           (*(*s_etat_processus).s_arbre_variables).feuille_partagee = NULL;
         (*(*s_etat_processus).s_arbre_variables).noeuds_utilises = 0;          (*(*s_etat_processus).s_arbre_variables).noeuds_utilises = 0;
         (*(*s_etat_processus).s_arbre_variables).indice_tableau_pere = -1;          (*(*s_etat_processus).s_arbre_variables).indice_tableau_pere = -1;
         (*(*s_etat_processus).s_arbre_variables).noeud_pere = NULL;          (*(*s_etat_processus).s_arbre_variables).noeud_pere = NULL;
           INITIALISATION_MUTEX((*(*s_etat_processus).s_arbre_variables)
                   .mutex_feuille_partagee);
   
         if (((*(*s_etat_processus).s_arbre_variables).noeuds =          if (((*(*s_etat_processus).s_arbre_variables).noeuds =
                     allocation_tableau_noeuds(s_etat_processus)) == NULL)                  allocation_tableau_noeuds(s_etat_processus)) == NULL)
         {          {
             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;              (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
             return(d_erreur);              return(d_erreur);
Line 476  ajout_variable(struct_processus *s_etat_ Line 480  ajout_variable(struct_processus *s_etat_
             (*(*l_variable_courante).noeuds[(*s_etat_processus)              (*(*l_variable_courante).noeuds[(*s_etat_processus)
                     .pointeurs_caracteres_variables[*ptr]]).feuille = NULL;                      .pointeurs_caracteres_variables[*ptr]]).feuille = NULL;
             (*(*l_variable_courante).noeuds[(*s_etat_processus)              (*(*l_variable_courante).noeuds[(*s_etat_processus)
                       .pointeurs_caracteres_variables[*ptr]]).feuille_statique
                       = NULL;
               (*(*l_variable_courante).noeuds[(*s_etat_processus)
                       .pointeurs_caracteres_variables[*ptr]]).feuille_partagee
                       = NULL;
               (*(*l_variable_courante).noeuds[(*s_etat_processus)
                     .pointeurs_caracteres_variables[*ptr]]).noeuds_utilises = 0;                      .pointeurs_caracteres_variables[*ptr]]).noeuds_utilises = 0;
               INITIALISATION_MUTEX((*(*l_variable_courante).noeuds
                       [(*s_etat_processus).pointeurs_caracteres_variables[*ptr]])
                       .mutex_feuille_partagee);
   
             // Le champ noeud_pere de la structure créée pointe sur              // Le champ noeud_pere de la structure créée pointe sur
             // la structure parente et l'indice tableau_pere correspond à la              // la structure parente et l'indice tableau_pere correspond à la
Line 1292  retrait_variable(struct_processus *s_eta Line 1305  retrait_variable(struct_processus *s_eta
                     [(*(*variable_a_supprimer).noeud).indice_tableau_pere]))                      [(*(*variable_a_supprimer).noeud).indice_tableau_pere]))
                     .feuille = NULL;                      .feuille = NULL;
   
             while((*s_arbre_courant).noeuds_utilises == 0)              while(((*s_arbre_courant).noeuds_utilises == 0) &&
                       ((*s_arbre_courant).feuille_statique == NULL) &&
                       ((*s_arbre_courant).feuille_partagee == NULL))
             {              {
                 s_arbre_a_supprimer = s_arbre_courant;                  s_arbre_a_supprimer = s_arbre_courant;
                 s_arbre_courant = (*s_arbre_courant).noeud_pere;                  s_arbre_courant = (*s_arbre_courant).noeud_pere;
Line 1494  retrait_variable(struct_processus *s_eta Line 1509  retrait_variable(struct_processus *s_eta
 */  */
   
 logical1  logical1
 retrait_variable_par_niveau(struct_processus *s_etat_processus)  retrait_variables_par_niveau(struct_processus *s_etat_processus)
 {  {
     struct_liste_variables          *l_element_a_supprimer;      struct_liste_variables          *l_element_a_supprimer;
   
Line 1548  retrait_variable_par_niveau(struct_proce Line 1563  retrait_variable_par_niveau(struct_proce
                                 .l_liste_variables_par_niveau).liste).donnee))                                  .l_liste_variables_par_niveau).liste).donnee))
                                 .variable_statique, ((*s_etat_processus)                                  .variable_statique, ((*s_etat_processus)
                                 .mode_execution_programme                                  .mode_execution_programme
                                  == 'Y') ? 'P' : 'E') == d_vrai)                                   == 'Y') ? 'P' : 'E') != NULL)
                         {                          {
                             (*s_etat_processus).s_liste_variables_statiques                              (*(*s_etat_processus)
                                     [(*s_etat_processus)                                      .pointeur_variable_statique_courante)
                                     .position_variable_statique_courante]                                      .objet = (*((struct_variable *)
                                     .objet = (*((struct_variable *)  
                                     (*(*(*s_etat_processus)                                      (*(*(*s_etat_processus)
                                     .l_liste_variables_par_niveau).liste)                                      .l_liste_variables_par_niveau).liste)
                                     .donnee)).objet;                                      .donnee)).objet;
Line 1587  retrait_variable_par_niveau(struct_proce Line 1601  retrait_variable_par_niveau(struct_proce
                                 .l_liste_variables_par_niveau).liste).donnee))                                  .l_liste_variables_par_niveau).liste).donnee))
                                 .variable_statique, ((*s_etat_processus)                                  .variable_statique, ((*s_etat_processus)
                                 .mode_execution_programme                                  .mode_execution_programme
                                  == 'Y') ? 'P' : 'E') == d_vrai)                                   == 'Y') ? 'P' : 'E') != NULL)
                         {                          {
                             (*s_etat_processus).s_liste_variables_statiques                              (*(*s_etat_processus)
                                     [(*s_etat_processus)                                      .pointeur_variable_statique_courante)
                                     .position_variable_statique_courante]  
                                     .objet = (*((struct_variable *)                                      .objet = (*((struct_variable *)
                                     (*(*(*s_etat_processus)                                      (*(*(*s_etat_processus)
                                     .l_liste_variables_par_niveau).liste)                                      .l_liste_variables_par_niveau).liste)
Line 1666  void Line 1679  void
 liberation_arbre_variables(struct_processus *s_etat_processus,  liberation_arbre_variables(struct_processus *s_etat_processus,
         struct_arbre_variables *arbre, logical1 retrait_definitions)          struct_arbre_variables *arbre, logical1 retrait_definitions)
 {  {
     int                     i;      int                                 i;
   
       struct_liste_chainee                *l_element_courant_liste;
       struct_liste_chainee                *l_element_suivant_liste;
   
     struct_liste_chainee    *l_element_courant_liste;      struct_liste_variables              *l_element_courant;
     struct_liste_chainee    *l_element_suivant_liste;      struct_liste_variables              *l_element_suivant;
   
     struct_liste_variables  *l_element_courant;      struct_liste_variables_statiques    *l_element_statique_courant;
     struct_liste_variables  *l_element_suivant;      struct_liste_variables_statiques    *l_element_statique_suivant;
   
     // Libération de l'arbre des variables. Le contenu des variables n'est      // Libération de l'arbre des variables. Le contenu des variables n'est
     // pas détruit par cette opération, il sera détruit lors de la libération      // pas détruit par cette opération, il sera détruit lors de la libération
Line 1697  liberation_arbre_variables(struct_proces Line 1713  liberation_arbre_variables(struct_proces
         (*arbre).feuille = NULL;          (*arbre).feuille = NULL;
     }      }
   
       l_element_statique_courant = (*arbre).feuille_statique;
   
       while(l_element_statique_courant != NULL)
       {
           l_element_statique_suivant = (*l_element_statique_courant).suivant;
   
           free((*(*l_element_statique_courant).variable).nom);
           liberation(s_etat_processus, (*(*l_element_statique_courant)
                   .variable).objet);
           free((*l_element_statique_courant).variable);
           free(l_element_statique_courant);
   
           l_element_statique_courant = l_element_statique_suivant;
       }
   
     for(i = 0; i < (*s_etat_processus).nombre_caracteres_variables; i++)      for(i = 0; i < (*s_etat_processus).nombre_caracteres_variables; i++)
     {      {
         if ((*arbre).noeuds[i] != NULL)          if ((*arbre).noeuds[i] != NULL)
Line 1772  int Line 1803  int
 nombre_variables(struct_processus *s_etat_processus,  nombre_variables(struct_processus *s_etat_processus,
         struct_arbre_variables *l_element_courant)          struct_arbre_variables *l_element_courant)
 {  {
     int                     i;      int                                 i;
     int                     n;      int                                 n;
   
     struct_liste_variables  *l_variable;      struct_liste_variables              *l_variable;
       struct_liste_variables_statiques    *l_variable_statique;
   
     n = 0;      n = 0;
   
Line 1790  nombre_variables(struct_processus *s_eta Line 1822  nombre_variables(struct_processus *s_eta
         } while(l_variable != (*l_element_courant).feuille);          } while(l_variable != (*l_element_courant).feuille);
     }      }
   
       if ((*l_element_courant).feuille_statique != NULL)
       {
           l_variable_statique = (*l_element_courant).feuille_statique;
   
           do
           {
               // Si le pointeur est nul, la variable est accessible et a été
               // copiée dans l'arbre des variables.
   
               if ((*(*l_variable_statique).variable).objet != NULL)
               {
                   n++;
               }
   
               l_variable_statique = (*l_variable_statique).suivant;
           } while(l_variable_statique != NULL);
       }
   
     for(i = 0; i < (*s_etat_processus).nombre_caracteres_variables; i++)      for(i = 0; i < (*s_etat_processus).nombre_caracteres_variables; i++)
     {      {
         if ((*l_element_courant).noeuds[i] != NULL)          if ((*l_element_courant).noeuds[i] != NULL)
Line 1802  nombre_variables(struct_processus *s_eta Line 1852  nombre_variables(struct_processus *s_eta
     return(n);      return(n);
 }  }
   
   
 int  int
 liste_variables(struct_processus *s_etat_processus,  liste_variables(struct_processus *s_etat_processus,
         struct_tableau_variables *tableau, int position,          struct_tableau_variables *tableau, int position,
         struct_arbre_variables *l_element_courant)          struct_arbre_variables *l_element_courant)
 {  {
     int                     i;      int                                 i;
   
     struct_liste_variables  *l_variable;      struct_liste_variables              *l_variable;
       struct_liste_variables_statiques    *l_variable_statique;
   
     if ((*l_element_courant).feuille != NULL)      if ((*l_element_courant).feuille != NULL)
     {      {
Line 1827  liste_variables(struct_processus *s_etat Line 1879  liste_variables(struct_processus *s_etat
                     (*(*l_variable).variable).variable_statique;                      (*(*l_variable).variable).variable_statique;
             tableau[position].variable_partagee =              tableau[position].variable_partagee =
                     (*(*l_variable).variable).variable_partagee;                      (*(*l_variable).variable).variable_partagee;
               tableau[position].variable_masquee = d_faux;
   
             position++;              position++;
             l_variable = (*l_variable).suivant;              l_variable = (*l_variable).suivant;
         } while(l_variable != (*l_element_courant).feuille);          } while(l_variable != (*l_element_courant).feuille);
     }      }
   
       if ((*l_element_courant).feuille_statique != NULL)
       {
           l_variable_statique = (*l_element_courant).feuille_statique;
   
           do
           {
               if ((*(*l_variable_statique).variable).objet != NULL)
               {
                   tableau[position].origine = 'E';
                   tableau[position].nom = (*(*l_variable_statique).variable).nom;
                   tableau[position].niveau =
                           (*(*l_variable_statique).variable).niveau;
                   tableau[position].objet =
                           (*(*l_variable_statique).variable).objet;
                   tableau[position].variable_verrouillee = d_faux;
                   tableau[position].variable_statique =
                           (*(*l_variable_statique).variable).variable_statique;
                   tableau[position].variable_partagee.pointeur = NULL;
                   tableau[position].variable_masquee = d_vrai;
   
                   position++;
               }
   
               l_variable_statique = (*l_variable_statique).suivant;
           } while(l_variable_statique != NULL);
       }
   
     for(i = 0; i < (*s_etat_processus).nombre_caracteres_variables; i++)      for(i = 0; i < (*s_etat_processus).nombre_caracteres_variables; i++)
     {      {
         if ((*l_element_courant).noeuds[i] != NULL)          if ((*l_element_courant).noeuds[i] != NULL)
Line 1875  copie_arbre_variables(struct_processus * Line 1955  copie_arbre_variables(struct_processus *
     // structure. Les variables de niveau 0 étant non modifiables, elles      // structure. Les variables de niveau 0 étant non modifiables, elles
     // ne sont pas dupliquées.      // ne sont pas dupliquées.
   
     int                             i;      int                                 i;
   
       logical1                            niveau_0_traite;
       logical1                            niveau_1_traite;
   
     logical1                        niveau_0_traite;      struct_arbre_variables              *l_variable_courante;
     logical1                        niveau_1_traite;  
   
     struct_liste_chainee            *l_element_courant;      struct_liste_chainee                *l_element_courant;
   
     struct_liste_variables          *l_niveau_courant;      struct_liste_variables              *l_niveau_courant;
       struct_liste_variables_statiques    *l_element_statique_courant;
   
     struct_variable                 s_variable;      struct_variable                     s_variable;
       struct_variable_statique            s_variable_statique;
   
       unsigned char                       *ptr;
   
     (*s_nouvel_etat_processus).s_arbre_variables = NULL;      (*s_nouvel_etat_processus).s_arbre_variables = NULL;
     (*s_nouvel_etat_processus).l_liste_variables_par_niveau = NULL;      (*s_nouvel_etat_processus).l_liste_variables_par_niveau = NULL;
Line 1982  copie_arbre_variables(struct_processus * Line 2068  copie_arbre_variables(struct_processus *
         l_niveau_courant = (*l_niveau_courant).precedent;          l_niveau_courant = (*l_niveau_courant).precedent;
     }      }
   
       // Copie des variables statiques
   
       l_element_statique_courant = (*s_etat_processus)
               .l_liste_variables_statiques;
   
       while(l_element_statique_courant != NULL)
       {
           // Création des branches de l'arbre si nécessaire.
   
           if ((*s_nouvel_etat_processus).s_arbre_variables == NULL)
           {
               if (((*s_nouvel_etat_processus).s_arbre_variables =
                           allocation_noeud(s_nouvel_etat_processus)) == NULL)
               {
                   (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   return;
               }
   
               (*(*s_nouvel_etat_processus).s_arbre_variables).feuille = NULL;
               (*(*s_nouvel_etat_processus).s_arbre_variables).feuille_statique
                       = NULL;
               (*(*s_nouvel_etat_processus).s_arbre_variables).noeuds_utilises = 0;
               (*(*s_nouvel_etat_processus).s_arbre_variables).indice_tableau_pere
                       = -1;
               (*(*s_nouvel_etat_processus).s_arbre_variables).noeud_pere = NULL;
   
               if (((*(*s_nouvel_etat_processus).s_arbre_variables).noeuds =
                       allocation_tableau_noeuds(s_nouvel_etat_processus)) == NULL)
               {
                   (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   return;
               }
   
               for(i = 0; i < (*s_nouvel_etat_processus)
                       .nombre_caracteres_variables; i++)
               {
                   (*(*s_nouvel_etat_processus).s_arbre_variables).noeuds[i]
                           = NULL;
               }
           }
   
           l_variable_courante = (*s_nouvel_etat_processus).s_arbre_variables;
           ptr = (*(*l_element_statique_courant).variable).nom;
   
           while((*ptr) != d_code_fin_chaine)
           {
               BUG((*s_nouvel_etat_processus).pointeurs_caracteres_variables
                       [*ptr] < 0, uprintf("Variable=\"%s\", (*ptr)='%c'\n",
                       (*(*l_element_statique_courant).variable).nom, *ptr));
   
               if ((*l_variable_courante).noeuds[(*s_nouvel_etat_processus)
                       .pointeurs_caracteres_variables[*ptr]] == NULL)
               {
                   // Le noeud n'existe pas encore, on le crée et on le marque
                   // comme utilisé dans la structure parente.
   
                   if (((*l_variable_courante).noeuds[(*s_nouvel_etat_processus)
                           .pointeurs_caracteres_variables[*ptr]] =
                           allocation_noeud(s_nouvel_etat_processus)) == NULL)
                   {
                       (*s_etat_processus).erreur_systeme =
                               d_es_allocation_memoire;
                       return;
                   }
   
                   (*l_variable_courante).noeuds_utilises++;
   
                   // La feuille est par défaut vide et aucun élément du tableau
                   // noeuds (les branches qui peuvent être issues de ce nouveau
                   // noeud) n'est encore utilisée.
   
                   (*(*l_variable_courante).noeuds[(*s_nouvel_etat_processus)
                           .pointeurs_caracteres_variables[*ptr]]).feuille = NULL;
                   (*(*l_variable_courante).noeuds[(*s_nouvel_etat_processus)
                           .pointeurs_caracteres_variables[*ptr]]).feuille_statique
                           = NULL;
                   (*(*l_variable_courante).noeuds[(*s_nouvel_etat_processus)
                           .pointeurs_caracteres_variables[*ptr]]).noeuds_utilises
                           = 0;
   
                   // Le champ noeud_pere de la structure créée pointe sur
                   // la structure parente et l'indice tableau_pere correspond à la
                   // position réelle dans le tableau noeuds[] de la structure
                   // parente du noeud courant. Cette valeur sera utilisée lors de
                   // la destruction du noeud pour annuler le pointeur contenu dans
                   // le tableau noeuds[] de la structure parente.
   
                   (*(*l_variable_courante).noeuds[(*s_nouvel_etat_processus)
                           .pointeurs_caracteres_variables[*ptr]]).noeud_pere =
                           l_variable_courante;
                   (*(*l_variable_courante).noeuds[(*s_nouvel_etat_processus)
                           .pointeurs_caracteres_variables[*ptr]])
                           .indice_tableau_pere = (*s_nouvel_etat_processus)
                           .pointeurs_caracteres_variables[*ptr];
   
                   // Allocation du tableau noeuds[] et initialisation à zéro de
                   // tous les pointeurs.
   
                   if (((*(*l_variable_courante).noeuds[(*s_nouvel_etat_processus)
                           .pointeurs_caracteres_variables[*ptr]]).noeuds =
                           allocation_tableau_noeuds(s_nouvel_etat_processus))
                           == NULL)
                   {
                       (*s_etat_processus).erreur_systeme
                               = d_es_allocation_memoire;
                       return;
                   }
   
                   for(i = 0; i < (*s_nouvel_etat_processus)
                           .nombre_caracteres_variables; i++)
                   {
                       (*(*l_variable_courante).noeuds[(*s_nouvel_etat_processus)
                               .pointeurs_caracteres_variables[*ptr]]).noeuds[i]
                               = NULL;
                   }
               }
   
               l_variable_courante = (*l_variable_courante).noeuds
                       [(*s_nouvel_etat_processus).pointeurs_caracteres_variables
                       [*ptr]];
   
               ptr++;
           }
   
           // Il faut copier la variable pour la dissocier de la variable
           // restant dans le thread parent.
   
           s_variable_statique = (*(*l_element_statique_courant).variable);
   
           if (copie_objet(s_etat_processus, s_variable_statique.objet, 'P')
                   == NULL)
           {
               (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
               return;
           }
   
           if ((s_variable_statique.nom = malloc((strlen(
                   (*(*l_element_statique_courant).variable).nom) + 1) *
                   sizeof(unsigned char))) == NULL)
           {
               (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
               return;
           }
   
           strcpy(s_variable_statique.nom, (*(*l_element_statique_courant)
                   .variable).nom);
   
           if (creation_variable_statique(s_nouvel_etat_processus,
                   &s_variable_statique) == d_erreur)
           {
               (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
               return;
           }
   
           l_element_statique_courant = (*l_element_statique_courant).suivant;
       }
   
     return;      return;
 }  }
   

Removed from v.1.52  
changed lines
  Added in v.1.64


CVSweb interface <joel.bertrand@systella.fr>