1: /*
2: ================================================================================
3: RPL/2 (R) version 4.1.17
4: Copyright (C) 1989-2013 Dr. BERTRAND Joël
5:
6: This file is part of RPL/2.
7:
8: RPL/2 is free software; you can redistribute it and/or modify it
9: under the terms of the CeCILL V2 License as published by the french
10: CEA, CNRS and INRIA.
11:
12: RPL/2 is distributed in the hope that it will be useful, but WITHOUT
13: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14: FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License
15: for more details.
16:
17: You should have received a copy of the CeCILL License
18: along with RPL/2. If not, write to info@cecill.info.
19: ================================================================================
20: */
21:
22:
23: #include "rpl-conv.h"
24:
25:
26: /*
27: ================================================================================
28: Fonction 'simplification' (ne libère pas les paramètres)
29: ================================================================================
30: Entrées : pointeur sur une structure struct_processus
31: --------------------------------------------------------------------------------
32: Sorties :
33: --------------------------------------------------------------------------------
34: Effets de bord : néant
35: ================================================================================
36: */
37:
38: struct_objet *
39: simplification(struct_processus *s_etat_processus, struct_objet *s_objet)
40: {
41: #ifdef EXPERIMENTAL_CODE
42: struct_arbre *s_arbre;
43: struct_arbre *s_noeud_courant;
44:
45: struct_liste_chainee *l_element_courant;
46: #endif
47: struct_objet *s_objet_simplifie;
48: #ifdef EXPERIMENTAL_CODE
49: struct_objet **t_expression;
50:
51: unsigned long i;
52: unsigned long nombre_elements;
53:
54: s_arbre = NULL;
55: #endif
56:
57: if ((*s_objet).type == ALG)
58: {
59: #ifdef EXPERIMENTAL_CODE
60: // Inversion de l'ordre des instructions dans l'expression
61:
62: nombre_elements = 0;
63: l_element_courant = (*s_objet).objet;
64:
65: while(l_element_courant != NULL)
66: {
67: nombre_elements++;
68: l_element_courant = (*l_element_courant).suivant;
69: }
70:
71: if ((t_expression = malloc(nombre_elements * sizeof(struct_objet *)))
72: == NULL)
73: {
74: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
75: return(NULL);
76: }
77:
78: i = nombre_elements - 1;
79: l_element_courant = (*s_objet).objet;
80:
81: while(l_element_courant != NULL)
82: {
83: if ((t_expression[i--] = copie_objet(s_etat_processus,
84: (*l_element_courant).donnee, 'O')) == NULL)
85: {
86: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
87: return(NULL);
88: }
89:
90: l_element_courant = (*l_element_courant).suivant;
91: }
92:
93: // L'objet est toujours évaluable car il s'agit d'une expression
94: // algébrique (cela revient à dire qu'il n'y a qu'un seul arbre
95: // et que celui-ci est terminé).
96:
97: s_arbre = creation_arbre(s_etat_processus, t_expression, 0,
98: nombre_elements - 1);
99:
100: for(i = 0; i < nombre_elements; liberation(t_expression[i++]));
101: free(t_expression);
102: #endif
103:
104: s_objet_simplifie = copie_objet(s_etat_processus, s_objet, 'P');
105:
106: // On essaye déjà de voir si l'arbre est cohérent...
107: }
108: else
109: {
110: s_objet_simplifie = copie_objet(s_etat_processus, s_objet, 'P');
111: }
112:
113: return(s_objet_simplifie);
114: }
115:
116:
117: /*
118: ================================================================================
119: Fonction créant un noeud dans l'arbre
120: ================================================================================
121: Entrées : pointeur sur une structure struct_arbre
122: --------------------------------------------------------------------------------
123: Sorties :
124: --------------------------------------------------------------------------------
125: Effets de bord : néant
126: ================================================================================
127: */
128:
129: struct_arbre *
130: creation_arbre(struct_processus *s_etat_processus,
131: struct_objet **t_objets, integer8 indice, integer8 indice_maximal)
132: {
133: struct_arbre *s_noeud;
134:
135: //unsigned long i;
136:
137: if ((s_noeud = malloc(sizeof(struct_arbre))) == NULL)
138: {
139: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
140: return(NULL);
141: }
142:
143: // indice ne peut jamais être supérieur à indice_maximal
144:
145: #if 0
146: // Création de la racine de l'arbre
147:
148: if ((s_arbre = malloc(sizeof(struct_arbre))) == NULL)
149: {
150: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
151: return(NULL);
152: }
153:
154: s_noeud_courant = s_arbre;
155:
156: for(i = 0; i < nombre_elements; i++)
157: {
158: if (strcmp((*t_expression[i]).type, "FCT") == 0)
159: {
160: if ((strcmp((*((struct_fonction *) (*t_expression[i]).objet))
161: .nom_fonction, "<<") != 0) &&
162: (strcmp((*((struct_fonction *)
163: (*t_expression[i]).objet)).nom_fonction, ">>") != 0))
164: {
165: // Création d'un noeud
166: }
167: }
168: }
169: #endif
170: return(NULL);
171: }
172:
173:
174: /*
175: ================================================================================
176: Fonction simplifiant l'arbre q-aire en arbre q'-aire (q <= q')
177: ================================================================================
178: Entrées : pointeur sur une structure struct_arbre
179: --------------------------------------------------------------------------------
180: Sorties :
181: --------------------------------------------------------------------------------
182: Effets de bord : néant
183: ================================================================================
184: */
185:
186: void
187: simplification_arbre(struct_processus *s_etat_processus, struct_arbre *s_noeud)
188: {
189: unsigned long i;
190:
191: if ((*s_noeud).feuilles != NULL)
192: {
193: for(i = 0; i < (*s_noeud).nombre_feuilles; i++)
194: {
195: simplification_arbre(s_etat_processus, (*s_noeud).feuilles[i]);
196:
197: /*
198: * Si le noeud est une fonction compatible avec une fonction
199: * présente dans les feuilles, on réunit les deux.
200: */
201:
202: if ((*(*((*s_noeud).feuilles[i])).objet).type == FCT)
203: {
204: if (((strcmp((*((struct_fonction *) (*s_noeud).objet))
205: .nom_fonction, "+") == 0) && (strcmp(
206: (*((struct_fonction *) (*(*((*s_noeud).feuilles[i]))
207: .objet).objet)).nom_fonction, "+") == 0)) ||
208: ((strcmp((*((struct_fonction *) (*s_noeud).objet))
209: .nom_fonction, "*") == 0) && (strcmp(
210: (*((struct_fonction *) (*(*((*s_noeud).feuilles[i]))
211: .objet).objet)).nom_fonction, "*") == 0)))
212: {
213: }
214: }
215: }
216: }
217:
218: return;
219: }
220:
221:
222: /*
223: ================================================================================
224: Fonction parcourant l'arbre q-aire
225: ================================================================================
226: Entrées : pointeur sur une structure struct_arbre
227: --------------------------------------------------------------------------------
228: Sorties :
229: --------------------------------------------------------------------------------
230: Effets de bord : néant
231: ================================================================================
232: */
233:
234: void
235: parcours_arbre(struct_processus *s_etat_processus, struct_arbre *s_noeud)
236: {
237: unsigned long i;
238:
239: if ((*s_noeud).feuilles != NULL)
240: {
241: for(i = 0; i < (*s_noeud).nombre_feuilles; i++)
242: {
243: parcours_arbre(s_etat_processus, (*s_noeud).feuilles[i]);
244: }
245: }
246:
247: return;
248: }
249:
250:
251: /*
252: ================================================================================
253: Fonction libérant l'arbre q-aire
254: ================================================================================
255: Entrées : pointeur sur une structure struct_arbre
256: --------------------------------------------------------------------------------
257: Sorties :
258: --------------------------------------------------------------------------------
259: Effets de bord : néant
260: ================================================================================
261: */
262:
263: void
264: liberation_arbre(struct_processus *s_etat_processus, struct_arbre *s_noeud)
265: {
266: unsigned long i;
267:
268: if ((*s_noeud).feuilles != NULL)
269: {
270: for(i = 0; i < (*s_noeud).nombre_feuilles; i++)
271: {
272: }
273: }
274:
275: return;
276: }
277:
278: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>