PIPS
variable.c
Go to the documentation of this file.
1 /*
2 
3  $Id: variable.c 1641 2016-03-02 08:20:19Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of Linear/C3 Library.
8 
9  Linear/C3 Library is free software: you can redistribute it and/or modify it
10  under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  Linear/C3 Library 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 Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with Linear/C3 Library. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 
25  /* package vecteur - routines sur les variables
26  *
27  * Francois Irigoin
28  *
29  * Notes:
30  * - variable_equal() and variable_default_name() should be overriden
31  * by application specific routines
32  * - the same holds for variable_make()
33  * - variable are identified by opaque void * (Variable)
34  *
35  * Modifications:
36  */
37 
38 /*LINTLIBRARY*/
39 #ifdef HAVE_CONFIG_H
40  #include "config.h"
41 #endif
42 
43 #include <stdio.h>
44 #include <string.h>
45 
46 #include "boolean.h"
47 #include "arithmetique.h"
48 #include "vecteur.h"
49 
50 /* bool variable_equal(Variable v1, Variable v2): returns true if
51  * variables v1 and v2 have the same VALUE
52  *
53  * Type Variable is assumed here to be char *
54  *
55  * Modifications:
56  *
57  * - no assumptions are made on type Variable; v1 and v2 may be of
58  * any type; all computations in vecteur.dir are based on pointer
59  * comparisons (FI, 28/12/89); this may lead to disaster for unit
60  * testing (FI, 11/12/2011)
61  */
62 bool variable_equal(v1, v2)
63 Variable v1;
64 Variable v2;
65 {
66  /*
67  * if(v1==NULL&&v2==NULL)
68  * return(true);
69  * else if (v1==NULL||v2==NULL)
70  * return(false);
71  *
72  * return(!strcmp(v1,v2));
73  */
74  return v1==v2;
75 }
76 
77 /* char * variable_default_name(Variable v): returns the name of variable v
78  *
79  * Type variable is assumed here to be char *
80  */
82 Variable v;
83 {
84  return((char *)v);
85 }
86 
87 /* variable_dump_name() returns an unambiguous name for variable v, based
88  * on the pointer used to really identify variables in the vecteur
89  * package; the name starts with the letter X and contains the hexadecimal
90  * representation of v
91  *
92  * Bugs:
93  * - the name is build in a local buffer; so a call to this function
94  * overwrite the previous returned value
95  */
97  /* Room for X0x1234567812345678\0 for example on 64 bit address
98  architecture since Variable is a pointer to something: */
99  static char buffer[sizeof(void *)*2+4];
100 
101  buffer[0] = 'X';
102  (void) sprintf(&buffer[1],"%p", v);
103  return(buffer);
104 }
105 
106 /* Debug support: pointer to the function used by debug print outs.
107  *
108  * It can be set to point to other packages' own definition of
109  * Value. For instance, entity_local_name() for Linear/C3 Library.
110  *
111  * For unit tests within linear, it should be set to point to
112  * variable_default_name()
113  */
114 char * (*variable_debug_name)(Variable) = variable_dump_name;
115 
116 /* This function is mostly intended for use from within gdb */
117 void init_variable_debug_name(char *(*name)(Variable))
118 {
119  variable_debug_name = name;
120 }
122 {
124 }
125 
126 /* Variable variable_make(char * name): defines a new variable of a given
127  * name
128  */
130 char * name;
131 {
132  return((Variable) strdup(name));
133 }
bool variable_equal(Variable v1, Variable v2)
package vecteur - routines sur les variables
Definition: variable.c:62
char * variable_default_name(Variable v)
char * variable_default_name(Variable v): returns the name of variable v
Definition: variable.c:81
void reset_variable_debug_name(void)
Definition: variable.c:121
Variable variable_make(char *name)
Variable variable_make(char * name): defines a new variable of a given name.
Definition: variable.c:129
char * variable_dump_name(Variable v)
variable_dump_name() returns an unambiguous name for variable v, based on the pointer used to really ...
Definition: variable.c:96
void init_variable_debug_name(char *(*name)(Variable))
This function is mostly intended for use from within gdb.
Definition: variable.c:117
char *(* variable_debug_name)(Variable)
Debug support: pointer to the function used by debug print outs.
Definition: variable.c:114
char * strdup()
static string buffer
Definition: string.c:113
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