--- rpl/src/instructions_v1.c 2011/04/11 13:02:26 1.16.2.1 +++ rpl/src/instructions_v1.c 2011/06/21 07:45:27 1.22 @@ -1,6 +1,6 @@ /* ================================================================================ - RPL/2 (R) version 4.0.22 + RPL/2 (R) version 4.1.0.prerelease.1 Copyright (C) 1989-2011 Dr. BERTRAND Joël This file is part of RPL/2. @@ -38,10 +38,6 @@ void instruction_var(struct_processus *s_etat_processus) { - logical1 presence_variable; - - long i; - struct_objet *s_objet_statistique; struct_objet *s_objet_resultat; struct_objet *s_objet_temporaire; @@ -85,74 +81,39 @@ instruction_var(struct_processus *s_etat * Recherche d'une variable globale référencée par SIGMA */ - if (recherche_variable(s_etat_processus, ds_sdat) == d_faux) + if (recherche_variable_globale(s_etat_processus, ds_sdat) == d_faux) { /* * Aucune variable SIGMA */ (*s_etat_processus).erreur_systeme = d_es; - (*s_etat_processus).erreur_execution = d_ex_absence_observations; - return; - } - else - { - /* - * Il existe une variable locale SIGMA. Reste à vérifier l'existence - * d'une variable SIGMA globale... - */ - i = (*s_etat_processus).position_variable_courante; - presence_variable = d_faux; - - while(i >= 0) + if ((*s_etat_processus).erreur_execution == d_ex) { - if ((strcmp((*s_etat_processus).s_liste_variables[i].nom, - ds_sdat) == 0) && ((*s_etat_processus) - .s_liste_variables[i].niveau == 1)) - { - presence_variable = d_vrai; - break; - } - - i--; + (*s_etat_processus).erreur_execution = d_ex_absence_observations; } - if (presence_variable == d_faux) + return; + } + else + { + if (((*(*(*s_etat_processus).pointeur_variable_courante).objet) + .type != MIN) && ((*(*(*s_etat_processus) + .pointeur_variable_courante).objet).type != MRL)) { - (*s_etat_processus).erreur_execution = d_ex_absence_observations; + (*s_etat_processus).erreur_execution = + d_ex_matrice_statistique_invalide; return; } - else - { - (*s_etat_processus).position_variable_courante = i; - - if ((*s_etat_processus).s_liste_variables[i].objet == NULL) - { - (*s_etat_processus).erreur_execution = d_ex_variable_partagee; - return; - } - if (((*((*s_etat_processus).s_liste_variables - [(*s_etat_processus).position_variable_courante].objet)) - .type != MIN) && ((*((*s_etat_processus) - .s_liste_variables[(*s_etat_processus) - .position_variable_courante].objet)).type != MRL)) - { - (*s_etat_processus).erreur_execution = - d_ex_matrice_statistique_invalide; - return; - } - - nombre_colonnes = (*((struct_matrice *) (*((*s_etat_processus) - .s_liste_variables[(*s_etat_processus) - .position_variable_courante].objet)).objet)) - .nombre_colonnes; - } + nombre_colonnes = (*((struct_matrice *) (*(*(*s_etat_processus) + .pointeur_variable_courante).objet).objet)) + .nombre_colonnes; } - s_objet_statistique = ((*s_etat_processus).s_liste_variables - [(*s_etat_processus).position_variable_courante]).objet; + s_objet_statistique = (*(*s_etat_processus).pointeur_variable_courante) + .objet; if (((*s_objet_statistique).type == MIN) || ((*s_objet_statistique).type == MRL)) @@ -959,6 +920,9 @@ instruction_version(struct_processus *s_ void instruction_vars(struct_processus *s_etat_processus) { + int i; + int nb_variables; + logical1 variable_partagee; struct_liste_chainee *l_element_courant; @@ -966,7 +930,7 @@ instruction_vars(struct_processus *s_eta struct_objet *s_objet_resultat; - unsigned long i; + struct_tableau_variables *tableau; (*s_etat_processus).erreur_execution = d_ex; @@ -1010,7 +974,20 @@ instruction_vars(struct_processus *s_eta (*s_objet_resultat).objet = NULL; l_element_precedent = NULL; - for(i = 0; i < (*s_etat_processus).nombre_variables; i++) + nb_variables = nombre_variables(s_etat_processus, + (*s_etat_processus).s_arbre_variables); + + if ((tableau = malloc(nb_variables * sizeof(struct_tableau_variables))) + == NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + liste_variables(s_etat_processus, tableau, 0, + (*s_etat_processus).s_arbre_variables); + + for(i = 0; i < nb_variables; i++) { if (l_element_precedent == NULL) { @@ -1060,7 +1037,7 @@ instruction_vars(struct_processus *s_eta * Mise en place d'un verrou si la variable est partagée. */ - if ((*s_etat_processus).s_liste_variables[i].objet == NULL) + if (tableau[i].objet == NULL) { if (pthread_mutex_lock(&((*(*s_etat_processus) .s_liste_variables_partagees).mutex)) != 0) @@ -1070,10 +1047,8 @@ instruction_vars(struct_processus *s_eta } if (recherche_variable_partagee(s_etat_processus, - ((*s_etat_processus).s_liste_variables[i]).nom, - ((*s_etat_processus).s_liste_variables[i]) - .variable_partagee, ((*s_etat_processus) - .s_liste_variables[i]).origine) == d_faux) + tableau[i].nom, tableau[i].variable_partagee, + tableau[i].origine) == d_faux) { // La variable partagée n'existe plus. @@ -1122,7 +1097,7 @@ instruction_vars(struct_processus *s_eta if (((*((struct_nom *) (*(*((struct_liste_chainee *) (*((struct_objet *) (*l_element_courant).donnee)).objet)).donnee).objet)).nom = - malloc((strlen((*s_etat_processus).s_liste_variables[i].nom) + malloc((strlen(tableau[i].nom) + 1) * sizeof(unsigned char))) == NULL) { if (variable_partagee == d_vrai) @@ -1141,8 +1116,7 @@ instruction_vars(struct_processus *s_eta strcpy((*((struct_nom *) (*(*((struct_liste_chainee *) (*((struct_objet *) (*l_element_courant).donnee)).objet)) - .donnee).objet)).nom, (*s_etat_processus) - .s_liste_variables[i].nom); + .donnee).objet)).nom, tableau[i].nom); /* * Préparation du niveau @@ -1186,7 +1160,7 @@ instruction_vars(struct_processus *s_eta (*((integer8 *) (*(*(*((struct_liste_chainee *) (*((struct_objet *) (*l_element_courant).donnee)).objet)).suivant).donnee).objet)) = - (integer8) (*s_etat_processus).s_liste_variables[i].niveau; + (integer8) tableau[i].niveau; /* * Préparation du contenu de la variable @@ -1210,7 +1184,7 @@ instruction_vars(struct_processus *s_eta return; } - if ((*s_etat_processus).s_liste_variables[i].objet == NULL) + if (tableau[i].objet == NULL) { // Variable partagée @@ -1246,8 +1220,8 @@ instruction_vars(struct_processus *s_eta if (((*(*(*((struct_liste_chainee *) (*((struct_objet *) (*l_element_courant).donnee)).objet)).suivant).suivant) - .donnee = copie_objet(s_etat_processus, (*s_etat_processus) - .s_liste_variables[i].objet, 'P')) == NULL) + .donnee = copie_objet(s_etat_processus, tableau[i].objet, + 'P')) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; @@ -1274,11 +1248,9 @@ instruction_vars(struct_processus *s_eta return; } - if (((*s_etat_processus).s_liste_variables[i].origine == 'P') - ? ((*s_etat_processus).s_liste_variables[i] - .variable_statique.adresse != 0) - : ((*s_etat_processus).s_liste_variables[i] - .variable_statique.pointeur != NULL)) + if ((tableau[i].origine == 'P') + ? (tableau[i].variable_statique.adresse != 0) + : (tableau[i].variable_statique.pointeur != NULL)) { if (((*(*(*(*(*((struct_liste_chainee *) (*((struct_objet *) (*l_element_courant).donnee)).objet)).suivant).suivant) @@ -1331,8 +1303,7 @@ instruction_vars(struct_processus *s_eta return; } - if ((*s_etat_processus).s_liste_variables[i].variable_verrouillee - == d_vrai) + if (tableau[i].variable_verrouillee == d_vrai) { if (((*(*(*(*(*(*((struct_liste_chainee *) (*((struct_objet *) (*l_element_courant).donnee)).objet)).suivant).suivant) @@ -1431,6 +1402,8 @@ instruction_vars(struct_processus *s_eta l_element_precedent = l_element_courant; } + free(tableau); + if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), s_objet_resultat) == d_erreur) { @@ -1641,10 +1614,6 @@ instruction_visit(struct_processus *s_et void instruction_variable(struct_processus *s_etat_processus) { - logical1 presence_variable; - - long i; - struct_liste_chainee *l_element_courant; struct_objet *s_objet; @@ -1691,7 +1660,7 @@ instruction_variable(struct_processus *s if ((*s_objet).type == NOM) { - if (recherche_variable(s_etat_processus, ((*((struct_nom *) + if (recherche_variable_globale(s_etat_processus, ((*((struct_nom *) (*s_objet).objet)).nom)) == d_faux) { liberation(s_etat_processus, s_objet); @@ -1701,34 +1670,8 @@ instruction_variable(struct_processus *s return; } - i = (*s_etat_processus).position_variable_courante; - presence_variable = d_faux; - - while(i >= 0) - { - if ((strcmp((*s_etat_processus).s_liste_variables[i].nom, - (*((struct_nom *) (*s_objet).objet)).nom) == 0) - && ((*s_etat_processus).s_liste_variables[i].niveau == 1)) - { - presence_variable = d_vrai; - break; - } - - i--; - } - - (*s_etat_processus).position_variable_courante = i; - - if (presence_variable == d_faux) - { - liberation(s_etat_processus, s_objet); - - (*s_etat_processus).erreur_execution = d_ex_variable_non_definie; - return; - } - - ((*s_etat_processus).s_liste_variables[(*s_etat_processus) - .position_variable_courante]).variable_verrouillee = d_faux; + (*(*s_etat_processus).pointeur_variable_courante) + .variable_verrouillee = d_faux; } else if ((*s_objet).type == LST) { @@ -1744,7 +1687,7 @@ instruction_variable(struct_processus *s return; } - if (recherche_variable(s_etat_processus, (*((struct_nom *) + if (recherche_variable_globale(s_etat_processus, (*((struct_nom *) (*(*l_element_courant).donnee).objet)).nom) == d_faux) { liberation(s_etat_processus, s_objet); @@ -1755,36 +1698,8 @@ instruction_variable(struct_processus *s return; } - i = (*s_etat_processus).position_variable_courante; - presence_variable = d_faux; - - while(i >= 0) - { - if ((strcmp((*s_etat_processus).s_liste_variables[i].nom, - (*((struct_nom *) (*(*l_element_courant).donnee) - .objet)).nom) == 0) && ((*s_etat_processus) - .s_liste_variables[i].niveau == 1)) - { - presence_variable = d_vrai; - break; - } - - i--; - } - - (*s_etat_processus).position_variable_courante = i; - - if (presence_variable == d_faux) - { - liberation(s_etat_processus, s_objet); - - (*s_etat_processus).erreur_execution = - d_ex_variable_non_definie; - return; - } - - ((*s_etat_processus).s_liste_variables[(*s_etat_processus) - .position_variable_courante]).variable_verrouillee = d_faux; + (*(*s_etat_processus).pointeur_variable_courante) + .variable_verrouillee = d_faux; l_element_courant = (*l_element_courant).suivant; }