PIPS
type.c
Go to the documentation of this file.
1 /*
2 
3  $Id: type.c 23180 2016-09-09 12:37:41Z irigoin $
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 
25 #ifdef HAVE_CONFIG_H
26  #include "pips_config.h"
27 #endif
28 #include <stdio.h>
29 
30 #include "linear.h"
31 
32 #include "genC.h"
33 #include "ri.h"
34 #include "misc.h"
35 
36 #include "ri-util.h"
37 #include "text-util.h"
38 
39 #include "prettyprint.h"
40 
41 /* Provide a full ASCII description of type "t"
42  *
43  * FI: I am not sure about the language used.
44  */
46 {
47  debug_on("PRETTYPRINT_DEBUG_LEVEL");
48  list pdl = NIL;
49  string s = words_to_string(words_type(t, &pdl, false));
50  gen_free_list(pdl);
51  debug_off();
52  return s;
53 }
54 
55 // same as above, but without the leak...
56 string string_of_type(const type t)
57 {
58  list pdl = NIL;
59  list wl = words_type(t, &pdl, false);
60  gen_free_list(pdl);
61  string s = words_to_string(wl);
62  FOREACH(STRING,s,wl) free(s);
63  gen_free_list(wl);
64  return s;
65 }
66 
67 /* For naming homogeneity: expression_to_string(), reference_to_string()... but type_to_string() is already implemented in ri-util in a less useful form */
68 /* string type_to_string(cons type t) */
69 /* { */
70 /* return string_of_type(t); */
71 /* } */
72 
73 /* This function cannot be in ri-util because of string_of_type() */
74 bool same_type_name_p(const type t0, const type t1) {
75  string s0 = string_of_type(t0),
76  s1 =string_of_type(t1);
77  bool same = same_string_p(s0,s1);
78  free(s0); free(s1);
79  return same;
80 }
81 
82 ␌
83 
84 /*
85  * returns the string to declare a basic type.
86  */
88 {
89  /* Nga Nguyen, 19/09/2003: To not rewrite the same thing, I use the words_basic() function*/
90  list pdl = NIL;
91  return list_to_string(words_basic(b, &pdl));
92  gen_free_list(pdl);
93 }
94 
95 /* Very basic and crude debugging function */
96 void print_types(list tl)
97 {
98  bool first_p = true;
99 
100  fprintf(stderr, "Type list: ");
101 
102  FOREACH(TYPE, t, tl) {
103  fprintf(stderr, first_p? "%p" : ", %p", t);
104  first_p = false;
105  }
106 
107  fprintf(stderr, "\n");
108 }
109 
110 /* For debugging */
112 {
113  debug_on("RI-UTIL_DEBUG_LEVEL");
114  if(t==NULL)
115  fprintf(stderr, "type is NULL.\n");
116  else if(type_undefined_p(t))
117  fprintf(stderr, "type is undefined.\n");
118  else if(type_domain_number(t)!=type_domain)
119  fprintf(stderr, "The argument is not a type.\n");
120  else {
121  // Might be better to pass true, or even more information, to see
122  // what happens with the unknown type
123  list pdl = NIL;
124  list wl = words_type(t, &pdl, false);
125  gen_free_list(pdl);
126  dump_words(wl);
127  }
128  debug_off();
129 }
130 
132 {
133  list wl = words_qualifiers(ql);
134  dump_words(wl);
135  gen_full_free_list(wl);
136 }
137 
139 {
140  list ql = CONS(QUALIFIER, q, NIL);
141  print_qualifiers(ql);
142  gen_free_list(ql);
143 }
string list_to_string(list l)
Return the malloc()ed version of the concatenation of all the strings in the list.
Definition: args.c:74
#define TYPE(bp)
non user domain must be taken care from outside?
Definition: genC.c:50
#define STRING(x)
Definition: genC.h:87
void gen_full_free_list(list l)
Definition: genClib.c:1023
void free(void *)
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
#define same_string_p(s1, s2)
list words_basic(basic obj, list *ppdl)
what about simple DOUBLE PRECISION, REAL, INTEGER...
Definition: declarations.c:323
list words_qualifiers(list obj)
Definition: declarations.c:795
list words_type(type obj, list *ppdl, bool argument_p)
obj is the type to describe
Definition: declarations.c:821
string string_of_type(const type t)
Definition: type.c:56
void print_qualifier(qualifier q)
Definition: type.c:138
string type_to_full_string_definition(type t)
Provide a full ASCII description of type "t".
Definition: type.c:45
void print_types(list tl)
Very basic and crude debugging function.
Definition: type.c:96
bool same_type_name_p(const type t0, const type t1)
For naming homogeneity: expression_to_string(), reference_to_string()...
Definition: type.c:74
void print_qualifiers(list ql)
Definition: type.c:131
void print_type(type t)
For debugging.
Definition: type.c:111
string basic_to_string(basic b)
RI-UTIL Library: Functions dealing with and constants related to PIPS intermediate representation ri....
Definition: type.c:87
#define QUALIFIER(x)
QUALIFIER.
Definition: ri.h:2106
#define type_undefined_p(x)
Definition: ri.h:2884
#define type_domain_number(x)
Definition: ri.h:2939
#define type_domain
newgen_transformer_domain_defined
Definition: ri.h:434
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
s1
Definition: set.c:247
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
void dump_words(list lw)
Definition: print.c:251
string words_to_string(cons *lw)
Definition: print.c:211