PIPS
polynome_ri.c
Go to the documentation of this file.
1 /*
2 
3  $Id: polynome_ri.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /* polynome_ri.c */
28 
29 /* This file gathers some functions interfacing
30  * polynomial library and the RI.
31  *
32  * The "Variable" type used by polynomials is
33  * casted to "entity", the "Value" type, to int.
34  *
35  * char *variable_name(Variable var)
36  * return the complete name of the entity var
37  *
38  * char *variable_local_name(Variable var)
39  * return the abbreviated, local name of var
40  *
41  * bool is_inferior_var(Variable var1, var2)
42  * return true if the complete name of var1
43  * is lexicographically before var2's one.
44  *
45  * Variable name_to_variable(char *name)
46  * inverse function of variable_name.
47  * name must be the complete name of the variable.
48  */
49 /* Modif:
50  -- entity_local_name is replaced by module_local_name. LZ 230993
51 */
52 
53 #include <stdlib.h>
54 #include <stdio.h>
55 //#include <stdlib.h>
56 #include <string.h>
57 
58 #include "linear.h"
59 
60 #include "genC.h"
61 #include "ri.h"
62 #include "effects.h"
63 #include "complexity_ri.h"
64 #include "ri-util.h"
65 #include "pipsdbm.h"
66 #include "workspace-util.h"
67 #include "effects-util.h"
68 #include "misc.h"
69 #include "matrice.h"
70 //#include "preprocessor.h"
71 #include "complexity.h"
72 
73 char *variable_name(var)
74 Variable var;
75 {
76  string s = (string) malloc(10);
77 
78  if (var == TCST)
79  s = strdup(TCST_NAME);
80  /* FI: no longer useful */
81  /*
82  else if (var == UNKNOWN_VARIABLE)
83  s = strdup(UNKNOWN_VARIABLE_NAME);
84  else if (var == UNKNOWN_RANGE)
85  s = strdup(UNKNOWN_RANGE_NAME);
86  */
87  else if (var == (Variable) chunk_undefined)
88  pips_internal_error("unexpected var == chunk_undefined.");
89  else
90  s = strdup(entity_name((entity) var));
91 
92  return (s);
93 }
94 
96 Variable var;
97 {
98  string s = NULL;
99 
100  if (var == TCST)
101  s = strdup(TCST_NAME);
102  /*
103  else if (var == UNKNOWN_VARIABLE)
104  s = strdup(UNKNOWN_VARIABLE_NAME);
105  else if (var == UNKNOWN_RANGE)
106  s = strdup(UNKNOWN_RANGE_NAME);
107  */
108  else if (var == (Variable) chunk_undefined)
109  pips_internal_error("unexpected var == chunk_undefined.");
110  else {
111  // s = strdup(entity_local_name((entity) var));
112  s = strdup(entity_minimal_name((entity) var));
113  }
114 
115  return (s);
116 }
117 
118 bool is_inferior_var(var1, var2)
119 Variable var1, var2;
120 {
121  bool is_inferior = true;
122 
123  if (var1 == TCST)
124  is_inferior = true;
125  else if(var2 == TCST)
126  is_inferior = false;
127  else
128  is_inferior = (strcmp(variable_local_name(var1),
129  variable_local_name(var2)) <= 0 );
130 
131  return is_inferior;
132 }
133 
134 int is_inferior_varval(Pvecteur varval1, Pvecteur varval2)
135 {
136  int is_inferior;
137 
138  if (term_cst(varval1))
139  is_inferior = 1;
140  else if(term_cst(varval2))
141  is_inferior = -1;
142  else
143  is_inferior = - strcmp(variable_local_name(vecteur_var(varval1)),
144  variable_local_name(vecteur_var(varval2)));
145 
146  return is_inferior;
147 }
148 
149 int is_inferior_pvarval(Pvecteur * pvarval1, Pvecteur * pvarval2)
150 {
151  int is_inferior;
152 
153  if (term_cst(*pvarval1))
154  is_inferior = -1;
155  else if(term_cst(*pvarval2))
156  is_inferior = 1;
157  else {
158  // FI: should be entity_user_name...
159  is_inferior = strcmp(variable_local_name(vecteur_var(*pvarval1)),
160  variable_local_name(vecteur_var(*pvarval2)));
161  }
162 
163  // FI: Make sure that you do not return 0 for two different entities
164  if(is_inferior==0 && vecteur_var(*pvarval1)!=vecteur_var(*pvarval2)) {
165  is_inferior = strcmp(entity_name((entity)vecteur_var(*pvarval1)),
166  entity_name((entity)vecteur_var(*pvarval2)));
167  }
168 
169  return is_inferior;
170 }
171 
173 {
174  if (strcmp(name, TCST_NAME) == 0)
175  return(TCST);
176  /*
177  else if (strcmp(name, UNKNOWN_VARIABLE_NAME) == 0)
178  return (UNKNOWN_VARIABLE);
179  else if (strcmp(name, UNKNOWN_RANGE_NAME) == 0)
180  return (UNKNOWN_RANGE);
181  */
182  else {
184  if (e != entity_undefined)
185  return ((Variable) e);
186  else {
187  user_warning("name_to_variable",
188  "entity '%s' not found:return chunk_undefined\n", name);
189  return((Variable) chunk_undefined);
190  }
191  }
192 }
193 
195 char *name;
196 {
197  string s = make_entity_fullname("TOP-LEVEL", name);
198 
199  if (strcmp(name, TCST_NAME)==0)
200  return(TCST);
201  /*
202  else if (strcmp(name, UNKNOWN_VARIABLE_NAME) == 0)
203  return (UNKNOWN_VARIABLE);
204  else if (strcmp(name, UNKNOWN_RANGE_NAME) == 0)
205  return (UNKNOWN_RANGE);
206  */
207  else {
209  if (e != entity_undefined)
210  return ((Variable) e);
211  else {
212  user_warning("local_name_to_variable",
213  "entity '%s' not found:return chunk_undefined\n", name);
214  return((Variable) chunk_undefined);
215  }
216  }
217 }
#define TCST_NAME
string make_entity_fullname(const char *module_name, const char *local_name)
END_EOLE.
Definition: entity_names.c:230
#define chunk_undefined
obsolete
Definition: genC.h:79
void * malloc(YYSIZE_T)
#define pips_internal_error
Definition: misc-local.h:149
#define user_warning(fn,...)
Definition: misc-local.h:262
const char * entity_minimal_name(entity e)
Do preserve scope informations.
Definition: naming.c:214
void * gen_find_tabulated(const char *, int)
Definition: tabulated.c:218
char * string
STRING.
Definition: newgen_types.h:39
int is_inferior_pvarval(Pvecteur *pvarval1, Pvecteur *pvarval2)
Definition: polynome_ri.c:149
int is_inferior_varval(Pvecteur varval1, Pvecteur varval2)
Definition: polynome_ri.c:134
Variable local_name_to_variable(char *name)
Definition: polynome_ri.c:194
char * variable_name(Variable var)
polynome_ri.c
Definition: polynome_ri.c:73
Variable name_to_variable(char *name)
Definition: polynome_ri.c:172
bool is_inferior_var(Variable var1, Variable var2)
Definition: polynome_ri.c:118
char * variable_local_name(Variable var)
Definition: polynome_ri.c:95
#define entity_undefined
Definition: ri.h:2761
#define entity_name(x)
Definition: ri.h:2790
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410
char * strdup()
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
#define vecteur_var(v)
void * Variable
arithmetique is a requirement for vecteur, but I do not want to inforce it in all pips files....
Definition: vecteur-local.h:60
#define term_cst(varval)