PIPS
type.c
Go to the documentation of this file.
1 /*
2 
3  $Id: type.c 23495 2018-10-24 09:19:47Z coelho $
4 
5  Copyright 1989-2015 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  * Modifications :
26  * --------------
27  *
28  * Molka Becher (MB), June-July 2010
29  *
30  * Add of functions on Long Int, Long Long Int, Long Double and Long Double Complex types
31  *
32  */
33 
34 #ifdef HAVE_CONFIG_H
35  #include "pips_config.h"
36 #endif
37 #include <stdio.h>
38 
39 #include "linear.h"
40 
41 #include "genC.h"
42 #include "ri.h"
43 #include "misc.h"
44 #include "properties.h"
45 
46 #include "ri-util.h"
47 
48 /*
49  * for debugging, returns a string describing a type.
50  */
51 string type_to_string(const type t)
52 {
53  string s = type_tag_as_string(type_tag(t));
54  pips_assert("type tag is ok", s != string_undefined);
55  return s;
56 }
57 
58 // for debugging
59 string safe_type_to_string(const type t)
60 {
61  if (type_undefined_p(t))
62  return "undefined type";
63  else
64  return type_to_string(t);
65 }
66 
67 /* bool same_type_name_p(const type t0, const type t1) { */
68 /* string s0 = string_of_type(t0), */
69 /* s1 =string_of_type(t1); */
70 /* bool same = same_string_p(s0,s1); */
71 /* free(s0); free(s1); */
72 /* return same; */
73 /* } */
74 
75 /* generation of types */
76 
78 {
80 }
81 
83 {
85 }
86 
88 {
89  return(make_mode(is_mode_value, NIL));
90 }
91 
93 {
95 }
96 
98 {
99  return(make_type(is_type_unknown, NIL));
100 }
101 
103 {
104  return(make_type(is_type_void, NIL));
105 }
106 
108 {
110 }
111 
112 /* BEGIN_EOLE */ /* - please do not remove this line */
113 /* Lines between BEGIN_EOLE and END_EOLE tags are automatically included
114  in the EOLE project (JZ - 11/98) */
115 
117 basic b;
118 cons * ld;
119 {
120  return(make_type(is_type_variable, make_variable(b, ld,NIL)));
121 }
122 
123 /* END_EOLE */
124 
125 /*
126  *
127  */
128 basic MakeBasic(the_tag)
129 int the_tag;
130 {
131  switch(the_tag)
132  {
133  case is_basic_int:
134  return(make_basic(is_basic_int, UUINT(4)));
135  break;
136  case is_basic_float:
137  return(make_basic(is_basic_float, UUINT(4)));
138  break;
139  case is_basic_logical:
140  return(make_basic(is_basic_logical, UUINT(4)));
141  break;
142  case is_basic_complex:
143  return(make_basic(is_basic_complex, UUINT(8)));
144  break;
145  case is_basic_overloaded:
147  break;
148  case is_basic_string:
150  break;
151  default:
152  pips_internal_error("unexpected basic tag: %d",
153  the_tag);
154  break;
155  }
156 
157  return(basic_undefined);
158 }
159 
160 /* functions on types */
161 
163 {
164  return(make_type(is_type_variable, make_variable(b, ld,NIL)));
165 }
166 
168 {
170 }
171 
172 //unused
174 {
175  pips_internal_error("Wrong signature, wrong implementation.\n");
177 }
179 {
182 }
183 
185 {
187 }
188 
190 {
192 }
193 
195 {
197 }
198 
200 {
202 }
203 
205 {
207 }
208 
210 {
212 }
213 
215 {
217 }
218 
220 {
222 }
223 
225 {
227 }
228 
230 {
232 }
233 
235 {
237 }
238 
240 {
245  NIL),
248 }
249 
250 /* For Fortran */
252 {
253  return make_parameter(MakeTypeArray(make_basic(t, UUINT(size)), NIL),
256 }
257 
258 /* this function creates a default fortran operator result, i.e. a zero
259  * dimension variable with an overloaded basic type.
260  */
262 {
264 }
266 {
269 }
270 
272 {
274 }
275 
277 {
279 }
280 
282 {
284 }
285 
287 {
289 }
290 
292 {
294 }
295 
297 {
299 }
300 
302 {
304 }
305 
307 {
309 }
310 
312 {
314 }
315 
317 {
320 }
321 
323 {
326 }
327 
329 {
334  NIL);
335 }
336 
338 {
339  return MakeTypeArray(make_basic(t, UUINT(size)), NIL);
340 }
341 
342 ␌
343 /* Type equality and equivalence
344  *
345  * Issues mostly due to C:
346  *
347  * - typedefs: do you want a syntactic equality only?
348  *
349  * - qualifiers: should they be taken into account or not?
350  *
351  * - C defined type equivalence/compatibility: char * == char[],
352  * char[N][M]==char (*)[M]
353  *
354  * - functions and pointers to functions are equivalent
355  *
356  * - dependent types: how do you compare the dimension expressions?
357  *
358  * Issues dur to PIPS internal representation:
359  *
360  * - newgen basic "string" is sometimes used instead of unsigned char[]
361  *
362  * - constant string like all constants are functions; for instance, a
363  * char * pointer can be assigned a functional void->string...
364  *
365  * These issues lead to the concepts of "ultimate" type and of "basic
366  * concrete" type, and to the development of many different type
367  * "equality" functions.
368  */
369 
370 /* same_type_p(): similar to type_equals but bypasses typedefs
371  *
372  * FI Warning: current version only compares ultimate_types
373  * but check the various typedef that follows.
374  *
375  * typedef int foo;
376  *
377  * type_equal_p(int, foo)==true, because foo is simply a renaming for
378  * int, but note that type_int_p(entity_type(foo)) returns
379  * false. Hence, type_int_p(t1) and type_equal_p(t1,t2) does not imply
380  * type_int_p(t2), which may lead to funny bugs.
381  *
382  * typedef struct a {
383  * int x;
384  * int y;
385  * } a_t;
386  *
387  * typedef struct b {
388  * int x;
389  * int y;
390  * } b_t;
391  *
392  * type_equal_p(a_t, b_t)==false, because the underlying structures
393  * have different names and because the C type system does not use
394  * structural equivalence.
395  *
396  * typedef struct {
397  * int x;
398  * int y;
399  * } c_t;
400  *
401  * typedef struct {
402  * int x;
403  * int y;
404  * } d_t;
405  *
406  * type_EQUAL_P(c_t, d_t)==FALSE because structures (or unions or
407  * enums) with implicit names receive each a unique name.
408  */
409 bool same_type_p(type t1, type t2)
410 {
411  t1= ultimate_type(t1);
412  t2= ultimate_type(t2);
413  return type_equal_p(t1,t2);
414 }
415 
416 static bool generic_type_equal_p(type t1, type t2, bool strict_p, bool qualifier_p, hash_table structural_table);
417 
418 /* This function is only used for structural type equality */
419 static bool generic_field_list_equal_p(list fl1, list fl2, bool strict_p, bool qualifier_p, hash_table structural_table)
420 {
421  bool equal_p = gen_length(fl1)==gen_length(fl2);
422  if(equal_p) {
423  list cfl1 = fl1, cfl2 = fl2;
424  for(;equal_p && !ENDP(cfl1); POP(cfl1), POP(cfl2)) {
425  entity e1 = ENTITY(CAR(cfl1));
426  entity e2 = ENTITY(CAR(cfl2));
427  /* FI: we might want the fields to have the same user name. */
428  equal_p = generic_type_equal_p(entity_type(e1), entity_type(e2), strict_p, qualifier_p, structural_table);
429  }
430  }
431  return equal_p;
432 }
433 
434 /* In case you are not protected against recursivity, check field names only */
436 {
437  bool equal_p = gen_length(fl1)==gen_length(fl2);
438  if(equal_p) {
439  list cfl1 = fl1, cfl2 = fl2;
440  for(;equal_p && !ENDP(cfl1); POP(cfl1), POP(cfl2)) {
441  entity e1 = ENTITY(CAR(cfl1));
442  entity e2 = ENTITY(CAR(cfl2));
443  /* FI: we only use the field names. */
444  string n1 = (string) entity_user_name(e1);
445  string n2 = (string) entity_user_name(e2);
446  equal_p = strcmp(n1, n2)==0;
447  }
448  }
449  return equal_p;
450 }
451 
452 /* Warning: the lengths of string basics are not checked!!!
453  * string_type_size() could be used but it is probably not very robust.
454  *
455  * typedef int foo[n+n];
456  *
457  * typedef int fii[2*n];
458  *
459  * type_equal_p(foo, fii)==undefined, because it depends on their
460  * respective stores. FI: I do not know what's implemented, see
461  * variable_equal_p().
462  */
463 /* the unknown type is not handled in a satisfactory way: in some
464  sense, it should be declared equal to any other type but the
465  undefined type; currently unknown is equal to unknown, and
466  different from other types.
467 
468  undefined types could also be seen in a different way, as really
469  undefined values; so if t1 or t2 is undefined, the procedure
470  should abort; but type_undefined is considered equal to type_undefined.
471 
472  Francois Irigoin, 10 March 1992
473 */
474 /* If strict_p, a typedef type is not equal to its definition (default value).
475  *
476  * If qualifier_p, qualifiers must be equal (default value).
477  *
478  * If structural_table is defined, the concrete types must be equal (to be refined? similar to strict_p? See also the equality of concrete types below)
479  *
480  * This function should be static and used only indirectly via
481  * type_equal_p(), etc.
482  */
483 static bool generic_type_equal_p(type t1, type t2, bool strict_p, bool qualifier_p, hash_table structural_table)
484 {
485  bool tequal = false;
486 
487  if(t1 == t2)
488  return true;
489  else if (t1 == type_undefined && t2 != type_undefined)
490  return false;
491  else if (t1 != type_undefined && t2 == type_undefined)
492  return false;
493  else if (type_tag(t1) != type_tag(t2))
494  return false;
495 
496  /* For a structural type equality, type pairs already visited are
497  assumed equal. The walk can only prove they are not equal. */
498  if(!hash_table_undefined_p(structural_table)) {
499  type t12 = (type) hash_get(structural_table, (void *) t1);
500  if(t2==t12)
501  return true;
502  type t21 = (type) hash_get(structural_table, (void *) t2);
503  if(t1==t21)
504  return true;
505  hash_put(structural_table, t1, t2);
506  /* Fortunately, we do not have to remove the pairs when we go up
507  * in the recursion across types. The hash_table can be freed by
508  * the caller that has allocated it.
509  */
510  }
511 
512  /* assertion: t1 and t2 are defined and have the same tag */
513  switch(type_tag(t1)) {
514  case is_type_statement:
515  return true;
516  case is_type_area:
517  return area_equal_p(type_area(t1), type_area(t2));
518  case is_type_variable:
519  tequal = generic_variable_equal_p(type_variable(t1), type_variable(t2), strict_p, qualifier_p, structural_table);
520  return tequal;
521  case is_type_functional:
522  return generic_functional_equal_p(type_functional(t1), type_functional(t2), strict_p, qualifier_p, structural_table);
523  case is_type_unknown:
524  return true;
525  case is_type_void:
526  return true;
527  case is_type_struct: // FI: not OK if structual_table is not available
528  case is_type_union:
529  case is_type_enum: {
530  list fl1 = derived_type_fields(t1);
531  list fl2 = derived_type_fields(t2);
532  if(!hash_table_undefined_p(structural_table)) {
533  tequal = generic_field_list_equal_p(fl1, fl2, strict_p, qualifier_p, structural_table);
534  }
535  else {
536  tequal = generic_field_list_names_equal_p(fl1, fl2);
537  }
538  return tequal;
539  }
540  default:
541  pips_internal_error("unexpected tag %d.\n", type_tag(t1));
542  }
543 
544  return false; /* just to avoid a warning */
545 }
546 
547 bool type_equal_p(type t1, type t2)
548 {
549  return generic_type_equal_p(t1, t2, true, true, hash_table_undefined);
550 }
551 
553 {
554  return generic_type_equal_p(t1, t2, true, false, hash_table_undefined);
555 }
556 
558 {
559  // FI: the last false is weird...
560  return generic_type_equal_p(t1, t2, false, false, hash_table_undefined);
561 }
562 
564 {
565  type ut1 = ultimate_type(t1);
566  type ut2 = ultimate_type(t2);
567  return generic_type_equal_p(ut1, ut2, false, true, hash_table_undefined);
568 }
569 
570 /* Expand typedefs before the type comparison. */
572 {
575  bool equal_p = generic_type_equal_p(ct1, ct2, false, true, hash_table_undefined);
576  free_type(ct1), free_type(ct2);
577  return equal_p;
578 }
579 
580 /* Type t1 and t2 are equal if their basic concrete components are equal
581  *
582  * 1-D arrays and pointers are compatible if build on the same type.
583  *
584  * Qualifiers are ignored.
585 */
587 {
588  hash_table structural_table = hash_table_make(hash_pointer, 0);
589  bool equal_p = generic_type_equal_p(t1, t2, false, false, structural_table);
590  hash_table_free(structural_table);
591  return equal_p;
592 }
593 
594 /* T is assumed to be an array type. Get rid of the last dimension and
595  allocate the new type. */
597 {
598  variable v = type_variable(t);
599  list dl = variable_dimensions(v);
600  list ndl = gen_full_copy_list(dl); // new dimension list
601  list lndl = gen_last(ndl); // last dimension
602  gen_list_and_not(&ndl, lndl); // the discarded element is freed
604  type nt = make_type_variable(nv);
605  return nt;
606 }
607 
608 /* assume that a pointer to type x is equal to a 1-D array of x */
610 {
611  bool equal_p = true;
612  if(!type_equal_up_to_qualifiers_p(t1,t2)) {
613  if(pointer_type_p(t1) && array_type_p(t2)) {
614  type pt = type_to_pointed_type(t1);
615  if(type_void_p(pt)) {
616  // Conventionally, you should have an array of overloaded elements...
617  //array_element_type();
618  equal_p = false;
619  }
620  else {
621  // Generalization
623  equal_p = array_pointer_type_equal_p(pt, st);
624  free_type(st);
625  }
626  }
627  else if(pointer_type_p(t2) && array_type_p(t1)) {
628  type pt = type_to_pointed_type(t2);
629  if(type_void_p(pt)) {
630  // Conventionally, you should have an array of overloaded elements...
631  //array_element_type();
632  equal_p = false;
633  }
634  else {
635  // Generalization
637  equal_p = array_pointer_type_equal_p(pt, st);
638  free_type(st);
639  }
640  }
641  else if(array_type_p(t1) && array_type_p(t2)) {
642  /* Reduce the number of dimensions and try again */
643  type nt1 = array_type_projection(t1);
644  type nt2 = array_type_projection(t2);
645  equal_p = array_pointer_type_equal_p(nt1, nt2);
646  free_type(nt1), free_type(nt2);
647  }
648  else
649  equal_p = false;
650  }
651  return equal_p;
652 }
653 
654 /* Assume that a pointer to type x is equal to a 1-D array of x. And
655  * do not forget the PIPS "string" exception. Constants strings are
656  * given type void->string instead of char[n] or char *.
657  */
659 {
660  bool equal_p = true;
661  if(string_type_p(t1))
662  if(string_type_p(t2))
663  equal_p = type_equal_p(t1,t2);
664  else {
665  /* Convert t1 */
667  equal_p = array_pointer_type_equal_p(nt1, t2);
668  free_type(nt1);
669  }
670  else
671  if(string_type_p(t2)) {
672  /* Convert t2 */
674  equal_p = array_pointer_type_equal_p(t1, nt2);
675  free_type(nt2);
676  }
677  else
678  equal_p = array_pointer_type_equal_p(t1, t2);
679 
680  return equal_p;
681 }
682 
683 /* is "et" the type of an element of an array of type "at"? */
685 {
686  bool equal_p = false;
687 
688  if(array_type_p(at)) {
689  if(type_variable_p(et)) {
692  equal_p = basic_equal_p(ab, eb);
693  }
694  }
695 
696  return equal_p;
697 }
698 
699 /* Same as above, but resolve typedefs first. */
701 {
704  bool equal_p = array_pointer_type_equal_p(ct1, ct2);
705  // Basic concrete types are memoized in a hash-table.
706  // They should not be freed (see corresponding functions)
707  // free_type(ct1), free_type(ct2);
708  return equal_p;
709 }
710 
711 ␌
713 {
716  return t;
717 }
718 
720 {
723  return t;
724 }
725 
727 {
730  return t;
731 }
732 ␌
733 bool area_equal_p(area a1, area a2)
734 {
735  if(a1 == a2)
736  return true;
737  else if (a1 == area_undefined && a2 != area_undefined)
738  return false;
739  else if (a1 != area_undefined && a2 == area_undefined)
740  return false;
741  else
742  /* layouts are independent ? */
743  return (area_size(a1) == area_size(a2));
744 }
745 
746 bool
748 {
749  return /* same values */
752 }
753 
754 bool dimensions_equal_p(list dims1, list dims2) {
755  return gen_equals(dims1,dims2,(gen_eq_func_t)dimension_equal_p);
756 }
757 
758 bool qualifiers_equal_p(list dims1, list dims2) {
759  return gen_equals(dims1,dims2,(gen_eq_func_t)qualifier_equal_p);
760 }
761 
762 bool generic_variable_equal_p(variable v1, variable v2, bool strict_p, bool qualifier_p, hash_table structural_table)
763 {
764  if(v1 == v2)
765  return true;
766  else if (v1 == variable_undefined && v2 != variable_undefined)
767  return false;
768  else if (v1 != variable_undefined && v2 == variable_undefined)
769  return false;
770  else {
771  /* must check basic, dimension and qualifiers
772  *
773  * The decomposed condition is much easier to debug than the
774  * global predicate.
775  */
776  bool equal_p = false;
777  bool beq_p = generic_basic_equal_p(variable_basic(v1), variable_basic(v2), strict_p, qualifier_p, structural_table);
778  if(beq_p) {
780  if(deq_p)
781  equal_p = (!qualifier_p || qualifiers_equal_p(variable_qualifiers(v1), variable_qualifiers(v2)));
782  }
783  return equal_p;
784  //generic_basic_equal_p(variable_basic(v1), variable_basic(v2), strict_p, qualifier_p, structural_table)
785  //&& dimensions_equal_p(variable_dimensions(v1), variable_dimensions(v2))
786  //&& (!qualifier_p || qualifiers_equal_p(variable_qualifiers(v1), variable_qualifiers(v2))) ;
787 
788  // FI: the next lines seem to be dead code
789  list ld1 = variable_dimensions(v1);
790  list ld2 = variable_dimensions(v2);
791 
792  if(ld1==NIL && ld2==NIL)
793  return true;
794  else
795  {
796  /* dimensions should be checked, but it's hard: the only
797  Fortran requirement is that the space allocated in
798  the callers is bigger than the space used in the
799  callee; stars represent any strictly positive integer;
800  we do not know if v1 is the caller type or the callee type;
801  I do not know what should be done; FI */
802  /* FI: I return false because the exact test should never be useful
803  in the parser; 1 February 1994 */
804  /* FC: I need this in the prettyprinter... */
805  int l1 = gen_length(ld1), l2 = gen_length(ld2);
806  if (l1!=l2)
807  return false;
808  for (; ld1; POP(ld1), POP(ld2))
809  {
810  dimension d1 = DIMENSION(CAR(ld1)), d2 = DIMENSION(CAR(ld2));
811  if (!dimension_equal_p(d1, d2))
812  return false;
813  }
814  }
815  }
816  return true;
817 }
818 
820 {
821  return generic_variable_equal_p(v1, v2, true, true, hash_table_undefined);
822 }
823 
824 bool generic_basic_equal_p(basic b1, basic b2, bool strict_p, bool qualifier_p, hash_table structural_table)
825 {
826  if(b1 == b2)
827  return true;
828  else if (b1 == basic_undefined && b2 != basic_undefined)
829  return false;
830  else if (b1 != basic_undefined && b2 == basic_undefined)
831  return false;
832  else if (basic_tag(b1) != basic_tag(b2)) {
833  if(strict_p)
834  return false;
835  else
836  return same_basic_p(b1, b2);
837  }
838 
839  /* assertion: b1 and b2 are defined and have the same tag
840  (see previous tests) */
841 
842  switch(basic_tag(b1)) {
843  case is_basic_int:
844  return basic_int(b1) == basic_int(b2);
845  case is_basic_float:
846  return basic_float(b1) == basic_float(b2);
847  case is_basic_logical:
848  return basic_logical(b1) == basic_logical(b2);
849  case is_basic_overloaded:
850  return true;
851  case is_basic_complex:
852  return basic_complex(b1) == basic_complex(b2);
853  case is_basic_bit: {
854  symbolic s1 = basic_bit(b1);
855  symbolic s2 = basic_bit(b2);
856 
857  /* FI: there are two definition of equality, one more strict via
858  the expression, and one more practical via the constant. But
859  the constant is not always defined. And the Newgen declaration
860  of symbolic looks wrong with "float:int"... */
861 
864  return expression_equal_p(e1, e2);
865  }
866  case is_basic_pointer:
867  {
868  type t1 = basic_pointer(b1);
869  type t2 = basic_pointer(b2);
870  return generic_type_equal_p(t1, t2, strict_p, qualifier_p, structural_table);
871  //return (type_void_p(t1) && type_void_p(t2)) ||
872  // (type_variable_p(t1) && type_variable_p(t2) &&
873  // generic_basic_equal_p(variable_basic(type_variable(t1)),
874  // variable_basic(type_variable(t2)),
875  // strict_p, qualifier_p, structural_table));
876  }
877  case is_basic_derived:
878  {
879  entity e1 = basic_derived(b1);
880  entity e2 = basic_derived(b2);
881  bool equal_p = true;
882 
883  // FI: THIS IS MORE COMPLICATED THAN A POINTER COMPARISON...
884  // qualifier_p should be provided...
885  if(e1!=e2)
886  equal_p = generic_type_equal_p(entity_type(e1), entity_type(e2), strict_p, qualifier_p, structural_table);
887  return equal_p;
888  }
889  case is_basic_string:
890  /* Do we want string types to be equal only if lengths are equal?
891  * I do not think so
892  */
893  /*
894  pips_internal_error("string type comparison not implemented");
895  */
896  /* could be a star or an expression; a value_equal_p() is needed! */
897  return true;
898  case is_basic_typedef: {
899  // FI: just like fields, the same typedef can be defined in
900  // different files by different entities; it would be easier with
901  // concrete types
902 
903  // It is not clear how strict_p should be used...
904  entity nt1 = basic_typedef(b1);
905  entity nt2 = basic_typedef(b2);
906  if(same_entity_p(nt1, nt2))
907  return true;
908  else {
909  string nt1n = (string) entity_user_name(nt1);
910  string nt2n = (string) entity_user_name(nt2);
911  if(same_string_p(nt1n, nt2n)) {
912  type nt1t = entity_type(nt1);
913  type nt2t = entity_type(nt2);
914  return generic_type_equal_p(nt1t, nt2t, strict_p, qualifier_p, structural_table);
915  }
916  else
917  return false;
918  }
919  //return basic_typedef_p(b2)
920  // && same_entity_p(basic_typedef(b1),basic_typedef(b2));
921  }
922  default: pips_internal_error("unexpected tag %d", basic_tag(b1));
923  }
924  return false; /* just to avoid a warning */
925 }
926 
928 {
929  return generic_basic_equal_p(b1, b2, true, false, hash_table_undefined);
930 }
931 
932 /* Used to implement the next two functions */
933 static bool compare_basic_p(basic b1, basic b2, bool same_p)
934 {
935  bool compare_p = false;
936 
937  /* Take care of typedefs */
938  if( basic_typedef_p(b1) )
939  {
941  if(type_variable_p(t1))
943  else // for instance, void
945  }
946 
947  if( basic_typedef_p(b2) )
948  {
950  if(type_variable_p(t2))
952  else // for instance, void
954  }
955 
957  if(same_p)
958  compare_p = basic_equal_p(b1,b2);
959  else
960  compare_p = (basic_tag(b1)==basic_tag(b2));
961  }
962  else
963  compare_p = false;
964 
965  return compare_p;
966 }
967 
968 /* check if two basics are similar. That is if they are equal modulo typedefs. */
970 {
971  return compare_basic_p(b1,b2, true);
972 }
973 
974 /* check if two basics are similar. That is if they are equal modulo
975  * typedefs and modulo the precision. For instance, "int" and "unsigned
976  * int" and "long int" are all considered compatible.
977  */
979 {
980  return compare_basic_p(b1,b2, false);
981 }
982 
984  bool qualifier_p, hash_table structural_table)
985 {
986  if(f1 == f2)
987  return true;
988  else if (f1 == functional_undefined && f2 != functional_undefined)
989  return false;
990  else if (f1 != functional_undefined && f2 == functional_undefined)
991  return false;
992  else {
993  list lp1 = functional_parameters(f1);
995 
996  if(gen_length(lp1) != gen_length(lp2))
997  return false;
998 
999  for( ; !ENDP(lp1); POP(lp1), POP(lp2)) {
1000  parameter p1 = PARAMETER(CAR(lp1));
1001  parameter p2 = PARAMETER(CAR(lp2));
1002 
1003  if(!generic_parameter_equal_p(p1, p2, strict_p, qualifier_p, structural_table))
1004  return false;
1005  }
1006 
1007  return generic_type_equal_p(functional_result(f1), functional_result(f2), strict_p, qualifier_p, structural_table);
1008  }
1009 }
1010 
1012 {
1013  return generic_functional_equal_p(f1, f2, true, true, false);
1014 }
1015 
1016 bool generic_parameter_equal_p(parameter p1, parameter p2, bool strict_p,
1017  bool qualifier_p, hash_table structural_table)
1018 {
1019  if(p1 == p2)
1020  return true;
1021  else if (p1 == parameter_undefined && p2 != parameter_undefined)
1022  return false;
1023  else if (p1 != parameter_undefined && p2 == parameter_undefined)
1024  return false;
1025  else
1026  return generic_type_equal_p(parameter_type(p1), parameter_type(p2), strict_p, qualifier_p, structural_table)
1028 }
1029 
1031 {
1032  return generic_parameter_equal_p(p1, p2, true, true, false);
1033 }
1034 
1035 bool mode_equal_p(mode m1, mode m2)
1036 {
1037  if(m1 == m2)
1038  return true;
1039  else if (m1 == mode_undefined && m2 != mode_undefined)
1040  return false;
1041  else if (m1 != mode_undefined && m2 == mode_undefined)
1042  return false;
1043  else
1044  return mode_tag(m1) == mode_tag(m2);
1045 }
1046 ␌
1048 {
1049  int size = -1;
1050  value v = basic_string(b);
1052 
1053  switch(value_tag(v)) {
1054  case is_value_constant:
1055  c = value_constant(v);
1056  if(constant_int_p(c))
1057  size = constant_int(c);
1058  else
1059  pips_internal_error("Non-integer constant to size a string");
1060  break;
1061  case is_value_unknown:
1062  /* The size may be unknown as in CHARACTER*(*) */
1063  /* No way to check it really was a '*'? */
1064  size = -1;
1065  break;
1066  default:
1067  pips_internal_error("Non-constant value to size a string");
1068  }
1069 
1070  return size;
1071 }
1072 
1073 /* See also SizeOfElements() */
1075 {
1076  int size = -1;
1077 
1078  switch(basic_tag(b)) {
1079  case is_basic_int: size = basic_int(b);
1080  break;
1081  case is_basic_float: size = basic_float(b);
1082  break;
1083  case is_basic_logical: size = basic_logical(b);
1084  break;
1085  case is_basic_overloaded:
1086  pips_internal_error("undefined for type overloaded");
1087  break;
1088  case is_basic_complex: size = basic_complex(b);
1089  break;
1090  case is_basic_string:
1091  /* pips_internal_error("undefined for type string"); */
1092  size = string_type_size(b);
1093  break;
1094  case is_basic_pointer:
1096  break;
1097  default: size = basic_int(b);
1098  pips_internal_error("ill. tag %d", basic_tag(b));
1099  break;
1100  }
1101 
1102  return size;
1103 }
1104 
1105 
1106 /*
1107  * See basic_of_expression() which is much more comprehensive
1108  * Intrinsic overloading is not resolved!
1109  *
1110  * IO statements contain call to labels of type statement. An
1111  * undefined_basic is returned for such expressions.
1112  *
1113  * WARNING: a pointer to an existing data structure is returned.
1114  */
1116 {
1117  syntax the_syntax=expression_syntax(expr);
1118  basic b = basic_undefined;
1119 
1120  switch(syntax_tag(the_syntax))
1121  {
1122  case is_syntax_reference:
1124  break;
1125  case is_syntax_range:
1126  /* should be int */
1127  b = expression_basic(range_lower(syntax_range(the_syntax)));
1128  break;
1129  case is_syntax_call:
1130  /*
1131  * here is a little problem with pips... every intrinsics are
1132  * overloaded, what is not exactly what is desired...
1133  */
1134  return(entity_basic(call_function(syntax_call(the_syntax))));
1135  break;
1136  case is_syntax_cast:
1137  {
1138  cast c = syntax_cast(the_syntax);
1139  type t = cast_type(c);
1140  type ut = ultimate_type(t);
1141  b = variable_basic(type_variable(ut));
1142  pips_assert("Type is \"variable\"", type_variable_p(ut));
1143  break;
1144  }
1146  {
1147  /* How to void a memory leak? Where can we find a basic int? A static variable? */
1148  b = make_basic(is_basic_int, (void *) 4);
1149  break;
1150  }
1151  default:
1152  pips_internal_error("unexpected syntax tag");
1153  break;
1154  }
1155 
1156  return b;
1157 }
1158 
1160 {
1164 }
1165 
1167 {
1168  list result = NIL ;
1169 
1170  MAPL(cd,
1171  {
1172  result = CONS(DIMENSION, dimension_dup(DIMENSION(CAR(cd))),
1173  result);
1174  },
1175  l);
1176 
1177  return(gen_nreverse(result));
1178 }
1179 
1181 {
1182  cons * pc;
1183 
1184  if (!type_variable_p(entity_type(e)))
1185  pips_internal_error("not a variable");
1186 
1187  if (i <= 0)
1188  pips_internal_error("invalid dimension");
1189 
1191 
1192  while (pc != NULL && --i > 0)
1193  pc = CDR(pc);
1194 
1195  if (pc == NULL)
1196  pips_internal_error("not enough dimensions");
1197 
1198  return(DIMENSION(CAR(pc)));
1199 }
1200 ␌
1201 /* BEGIN_EOLE */ /* - please do not remove this line */
1202 /* Lines between BEGIN_EOLE and END_EOLE tags are automatically included
1203  in the EOLE project (JZ - 11/98) */
1204 
1205 /* SG: added so that the basic of a dereferenced pointer is the basic of the dereferenced value
1206 BC : modified because it was assumed that each dimension was of pointer type which is not
1207 true when tab is declared int ** tab[10] and the expression is tab[3][4][5].
1208 */
1210 {
1211  bool finished = false;
1212  for(list l_ind = indices ; !ENDP(l_ind) && !finished ; POP(l_ind) )
1213  {
1214  if(basic_pointer_p(b))
1215  {
1216  type t = basic_pointer(b);
1217  if(type_variable_p(t)) {
1218  basic bt =
1220  ultimate_p?ultimate_type(t):t)));
1221  free_basic(b);
1222  b=bt;
1223  }
1224  else if(type_functional_p(t)) {
1225  /* The expression can denote a function, because a
1226  function is equivalent to a pointer towards a
1227  function */
1228  /* FI: we might as well return a pointer to a
1229  function */
1230  ;
1231  }
1232  else if(type_void_p(t))
1233  pips_user_error("Apparent dereferencing of a void object. "
1234  "Check gcc warnings about typing.\n");
1235  else
1236  pips_internal_error("Unexpected basic kind");
1237  }
1238  else
1239  {
1240  /* the basic type is reached. Should I add pips_assert("basic reached, it should be the last index\n", ENDP(CAR(l_ind)))? */
1241  finished = true;
1242  }
1243  }
1244  return b;
1245 }
1246 
1247 ␌
1248 /* basic basic_of_any_expression(expression exp, bool apply_p): Makes
1249  * a basic of the same basic as the expression "exp" if "apply_p" is
1250  * FALSE. If "apply_p" is true and if the expression returns a
1251  * function, then return the resulting type of the function.
1252  *
1253  * WARNING: a new basic object is allocated
1254  *
1255  * PREFER (???) expression_basic
1256  *
1257  */
1258 basic some_basic_of_any_expression(expression exp, bool apply_p, bool ultimate_p)
1259 {
1261  basic b = basic_undefined;
1262 
1263  ifdebug(6){
1264  pips_debug(6, "begins with apply_p=%s and expression ", bool_to_string(apply_p));
1265  // FI: to avoid cycles betwen librairies ri-util and prettyprint
1266  /* print_expression(exp); */
1267  /* pips_debug(6, "\n"); */
1268  }
1269 
1270  switch(syntax_tag(sy)) {
1271  case is_syntax_reference:
1272  {
1273  b = basic_of_any_reference(syntax_reference(sy),apply_p,ultimate_p);
1274  break;
1275  }
1276  case is_syntax_call:
1277  b = basic_of_call(syntax_call(sy), apply_p, ultimate_p);
1278  break;
1279  case is_syntax_range:
1280  /* Well, let's assume range are well formed... */
1282  break;
1283  case is_syntax_cast:
1284  {
1285  type t = cast_type(syntax_cast(sy));
1286 
1287  if (type_tag(t) != is_type_variable) {
1288  if(type_void_p(t))
1289  /* This happens with the assert macro... but could happen
1290  anywhere as in (void) printf(...); */
1291  /* FI: I cannot think of anything better... */
1292  b = basic_undefined;
1293  else
1294  pips_internal_error("Bad reference type tag %d",type_tag(t));
1295  }
1296  else
1298  break;
1299  }
1301  /* SG: following code fragment seems wrong to me
1302  {
1303  sizeofexpression se = syntax_sizeofexpression(sy);
1304  if (sizeofexpression_type_p(se))
1305  {
1306  type t = sizeofexpression_type(se);
1307  if (type_tag(t) != is_type_variable)
1308  pips_internal_error("Bad reference type tag %d",type_tag(t));
1309  b = copy_basic(variable_basic(type_variable(t)));
1310  }
1311  else
1312  {
1313  b = some_basic_of_any_expression(sizeofexpression_expression(se), apply_p, ultimate_p);
1314  }
1315  */
1316 
1318  break;
1319 
1320  case is_syntax_subscript:
1321  {
1322  b = some_basic_of_any_expression(subscript_array(syntax_subscript(sy)), apply_p, ultimate_p);
1323  /* depending on the depth of the subscript, we should change the basic */
1325  break;
1326  }
1327  case is_syntax_application:
1328  {
1330  break;
1331  }
1332  case is_syntax_va_arg:
1333  {
1334  /* the second argument is the type of the returned object */
1336 
1337  if(sizeofexpression_type_p(sofe)) {
1339 
1340  if(type_variable_p(t))
1342  else
1343  pips_internal_error("Not implemented");
1344  }
1345  else {
1347  b = basic_of_any_expression(e, true);
1348  pips_internal_error("expression not expected here");
1349  }
1350  break;
1351  }
1352  default:
1353  pips_internal_error("Bad syntax tag %d", syntax_tag(sy));
1354  /* Never go there... */
1356  }
1357 
1358  /* pips_debug(6, "returns with %s\n", basic_to_string(b)); */
1359 
1360  return b;
1361 }
1362 
1363 
1365 {
1366  return some_basic_of_any_expression(exp, apply_p, true);
1367 }
1368 
1369 /* basic basic_of_expression(expression exp): Makes a basic of the same
1370  * basic as the expression "exp". Indeed, "exp" will be assigned to
1371  * a temporary variable, which will have the same declaration as "exp".
1372  *
1373  * Does not work if the expression is a reference to a functional
1374  * entity, as may be the case in a Fortran call or a C functional
1375  * pointer initialization. For C, a pointer to a functional should
1376  * be/is returned.
1377  *
1378  * WARNING: a new basic object is allocated
1379  *
1380  * PREFER (???) expression_basic
1381  *
1382  */
1384 {
1385  return basic_of_any_expression(exp, false);
1386 }
1387 
1388 /**
1389  * Retrieves the basic of a reference in a newly allocated basic object
1390  *
1391  * @param r reference we want the basic of
1392  *
1393  * @return allocated basic of the reference
1394  */
1395 basic basic_of_any_reference(reference r, bool apply_p, bool ultimate_p) {
1396  basic b = basic_undefined;
1397  entity v = reference_variable(r);
1398  type vt = entity_type(v);
1399 
1400  /* When called from the parser, the entity type may not yet be
1401  stored in the field type. This happens when
1402  simplify_C_expression is called for initialization
1403  expressions which are grouped in one statement. */
1404  if(!type_undefined_p(vt)) {
1405  type exp_type = ultimate_p ? ultimate_type(vt) : copy_type(entity_type(v));
1406  list l_dim = NIL;
1407 
1408  if(apply_p) {
1409  if(!type_functional_p(exp_type))
1410  pips_internal_error("Bad reference type tag %d \"%s\"",
1411  type_tag(exp_type));
1412  else {
1413  type rt = functional_result(type_functional(exp_type));
1414  type urt = ultimate_p ? ultimate_type(rt) : copy_type(rt);
1415 
1416  if(type_variable_p(urt))
1418  else {
1419  pips_internal_error("Unexpected type tag %s", type_to_string(urt));
1420  }
1421  }
1422  } else {
1423  if(type_variable_p(exp_type)) {
1424  b = copy_basic(variable_basic(type_variable(exp_type)));
1425 
1426  /* BC : if the variable has dimensions, then it's an array name which is converted
1427  into a pointer itself. And each dimension is converted into a pointer on the next one.
1428  (except in a few cases which should be handled in basic_of_call)
1429  to be verified or done
1430  */
1431 
1432  for (l_dim = variable_dimensions(type_variable(exp_type)); !ENDP(l_dim); POP(l_dim)) {
1433  b
1435  }
1436  } else if(type_functional_p(exp_type)) {
1437  /* A reference to a function returns a pointer to a function of the very same time */
1438  b = make_basic_pointer(copy_type(exp_type));
1439  } else {
1440  pips_internal_error("Bad reference type tag %d \"%s\"",
1441  type_tag(exp_type), type_to_string(exp_type));
1442  }
1443  }
1445  reference_indices(r),
1446  ultimate_p);
1447  }
1448  return b;
1449 }
1450 
1451 
1452 /**
1453  * Retrieves the basic of a reference in a newly allocated basic object
1454  *
1455  * @param r reference we want the basic of
1456  *
1457  * @return allocated basic of the reference
1458  */
1460  return basic_of_any_reference(r,false,true);
1461 }
1462 
1463 /* basic basic_of_call(call c): returns the basic of the result given
1464  * by the call "c". If ultimate_p is true, replaced typdef'ed types by
1465  * their definitions recursively. If not, preserve typedef'ed types.
1466  *
1467  * WARNING: a new basic is allocated
1468  */
1469 basic basic_of_call(call c, bool apply_p, bool ultimate_p)
1470 {
1471  entity e = call_function(c);
1472  tag t = value_tag(entity_initial(e));
1473  basic b = basic_undefined;
1474 
1475  switch (t)
1476  {
1477  case is_value_code:
1478  b = copy_basic(basic_of_external(c));
1479  break;
1480  case is_value_intrinsic:
1481  b = basic_of_intrinsic(c, apply_p, ultimate_p);
1482  break;
1483  case is_value_symbolic:
1484  /* b = make_basic(is_basic_overloaded, UU); */
1485  b = copy_basic(basic_of_constant(c));
1486  break;
1487  case is_value_constant:
1488  b = copy_basic(basic_of_constant(c));
1489  break;
1490  case is_value_unknown:
1491  pips_debug(1, "function %s has no initial value.\n"
1492  " Maybe it has not been parsed yet.\n",
1493  entity_name(e));
1494  b = copy_basic(basic_of_external(c));
1495  break;
1496  default: pips_internal_error("unknown tag %d", t);
1497  /* Never go there... */
1498  }
1499  return b;
1500 }
1501 
1502 
1503 
1504 /* basic basic_of_external(call c): returns the basic of the result given by
1505  * the call to an external function.
1506  *
1507  * WARNING: returns a pointer
1508  */
1510 {
1511  type return_type = type_undefined;
1512  entity f = call_function(c);
1513  basic b = basic_undefined;
1514  type call_type = entity_type(f);
1515 
1516 
1517  pips_debug(7, "External call to %s\n", entity_name(f));
1518 
1519  /* support calling a function pointer :) */
1520  type ut = ultimate_type(call_type);
1521  if(type_variable_p(ut) &&
1524 
1525  if (! type_functional_p(ut) )
1526  pips_internal_error("Bad call type tag");
1527 
1528  return_type = functional_result(type_functional(ut));
1529 
1530  if (!type_variable_p(return_type)) {
1531  if(type_void_p(return_type)) {
1532  pips_user_error("A subroutine or void returning function is used as an expression\n");
1533  }
1534  else {
1535  pips_internal_error("Bad return call type tag \"%s\"", type_to_string(return_type));
1536  }
1537  }
1538 
1539  b = (variable_basic(type_variable(return_type)));
1540 
1541  /* pips_debug(7, "Returned type is %s\n", basic_to_string(b)); */
1542 
1543  return b;
1544 }
1545 
1546 /* basic basic_of_intrinsic(call c): returns the basic of the result
1547  * given by call to an intrinsic function. This basic must be computed
1548  * with the basic of the arguments of the intrinsic for overloaded
1549  * operators. It should be able to accommodate more than two arguments
1550  * as for generic min and max operators. ultimate_p controls the
1551  * behavior when typedef'ed types are encountered: should they be
1552  * replaced by their definitions or not?
1553  *
1554  * WARNING: returns a newly allocated basic object */
1555 basic basic_of_intrinsic(call c, bool apply_p, bool ultimate_p)
1556 {
1557  entity f = call_function(c);
1559  pips_assert("not calling basic_of_intrinsic on something returning void",!type_void_p(rt));
1561 
1562  /* pips_debug(7, "Intrinsic call to intrinsic \"%s\" with a priori result type \"%s\"\n", */
1563  /* module_local_name(f), */
1564  /* basic_to_string(rb)); */
1565 
1566  if(basic_overloaded_p(rb)) {
1567  list args = call_arguments(c);
1568 
1569  if (ENDP(args)) {
1570  /* I don't know the type since there is no arguments !
1571  Bug encountered with a FMT=* in a PRINT.
1572  RK, 21/02/1994 : */
1573  /* leave it overloaded */
1574  ;
1575  }
1576  else if(ENTITY_ADDRESS_OF_P(f)) {
1577  //string s = entity_user_name(f);
1578  //bool b = ENTITY_ADDRESS_OF_P(f);
1579  expression e = EXPRESSION(CAR(args));
1580  basic eb = some_basic_of_any_expression(e, false, ultimate_p);
1581  // Forget multidimensional types
1583  make_variable(eb, NIL, NIL));
1584 
1585  //fprintf(stderr, "b=%d, s=%s\n", b, s);
1586  free_basic(rb);
1587  rb = make_basic(is_basic_pointer, et);
1588  }
1589  else if(ENTITY_DEREFERENCING_P(f)) {
1590  expression e = EXPRESSION(CAR(args));
1591  free_basic(rb);
1592  rb = basic_of_expression(e);
1593  if(basic_pointer_p(rb)) {
1594  type pt = type_undefined;
1595 
1596  if(ultimate_p && !type_undefined_p(basic_pointer(rb)))
1598  else
1599  pt = copy_type(basic_pointer(rb));
1600 
1601  pips_assert("The pointed type is consistent", type_consistent_p(pt));
1602  if(type_undefined_p(pt)) {
1603  /* Too bad, this may happen in the parser */
1604  free_basic(rb);
1605  rb = basic_undefined;
1606  }
1607  else if(type_variable_p(pt) && !apply_p) {
1608  free_basic(rb);
1609  variable v = type_variable(pt);
1610  if(ENDP(variable_dimensions(v)))
1611  rb = copy_basic(variable_basic(v));
1612  else {
1613  /* consider int a[12][13] is of type int (*)[13]*/
1614  rb = make_basic_pointer(
1616  make_variable(
1620  )
1621  )
1622  );
1623  }
1624  }
1625  else if(type_functional_p(pt)) {
1626  if(apply_p) {
1627  free_basic(rb);
1629  if(type_variable_p(rt))
1631  else {
1632  /* Too bad for "void"...
1633  * SG: should not happen because dereferencing a void* is a mistake */
1634  pips_internal_error("input code seems to derference a void* pointer ?");
1635  }
1636  }
1637  else {
1638  return rb;
1639  }
1640  }
1641  else {
1642  pips_internal_error("unhandled case");
1643  }
1644  }
1645  else {
1646  type et = call_to_type(c);
1647  if(ultimate_p) et=ultimate_type(et);
1648  if( type_variable_p(et) )
1649  {
1650  variable v=type_variable(et);
1651  free_basic(rb);
1652  if(ENDP(variable_dimensions(v)))
1653  rb = copy_basic(variable_basic(v));
1654  else {
1655  /* consider int a[12][13] is of type int (*)[13]*/
1656  rb = make_basic_pointer(
1658  make_variable(
1662  )
1663  )
1664  );
1665  }
1666  }
1667  if( !type_variable_p(et) ) {
1668 
1669  /* This can also be a user error, but if the function is
1670  called from the parser, a CParserError() should be called:
1671  how to guess what to do? */
1672  pips_internal_error("Dereferencing of a non-pointer, non array expression"
1673  "Please use gcc to check that your source code is legal\n");
1674  }
1675  if(ultimate_p) free_type(et);
1676  }
1677  }
1678  else if(ENTITY_POINT_TO_P(f)) {
1679  //pips_internal_error("Point to case not implemented yet");
1680  //expression e1 = EXPRESSION(CAR(args));
1681  expression e2 = EXPRESSION(CAR(CDR(args)));
1682  free_basic(rb);
1683  pips_assert("Two arguments for ENTITY_POINT_TO", gen_length(args)==2);
1684  // FI: to avoid cycles betwen librairies ri-util and prettyprint
1685  /* ifdebug(8) { */
1686  /* pips_debug(8, "Point to case, e1 = "); */
1687  /* print_expression(e1); */
1688  /* pips_debug(8, " and e2 = "); */
1689  /* print_expression(e1); */
1690  /* pips_debug(8, "\n"); */
1691  /* } */
1692  rb = basic_of_expression(e2);
1693  }
1694  else if(ENTITY_BRACE_INTRINSIC_P(f)) {
1695  /* We should reconstruct a struct type or an array type... */
1696  rb = make_basic_overloaded();
1697  }
1698  else if(ENTITY_ASSIGN_P(f)) {
1699  /* returns the type of the left hand side */
1700  rb = basic_of_expression(EXPRESSION(CAR(args)));
1701  }
1702  else if(ENTITY_FIELD_P(f)) {
1703  free_basic(rb);
1704  rb = basic_of_expression(EXPRESSION(CAR(CDR(args))));
1705  }
1706  else if(ENTITY_COMMA_P(f)) {
1707  /* The value returned is the value of the last expression in the list. */
1708  free_basic(rb);
1710  }
1711  else if(ENTITY_CONDITIONAL_P(f)) {
1712  /* The value returned is the value of the first expression in
1713  the list after the condition. The second expression is
1714  assumed to have the same value because the code is assumed
1715  correct. */
1716  free_basic(rb);
1717  rb = basic_of_expression(EXPRESSION(CAR(CDR(args))));
1718  }
1719  else if(ENTITY_MINUS_C_P(f)) {
1720  /* This must be a pointer difference. Else, the parser
1721  would have used ENTITY_MINUS (see
1722  simplify_C_expression()). */
1723  free_basic(rb);
1725  }
1726  else {
1727  free_basic(rb);
1728  // FI: within declaration initializations, rb may be
1729  // undefined because the expressions uses a variable that
1730  // has not yet been typed by the parser. See C_syntax/simplify01.c
1731  rb = basic_of_expression(EXPRESSION(CAR(args)));
1732 
1733  FOREACH(EXPRESSION, arg, CDR(args)){
1734  basic b = basic_of_expression(arg);
1735  basic new_rb = basic_maximum(rb, b);
1736 
1737  free_basic(rb);
1738  free_basic(b);
1739  rb = new_rb;
1740  }
1741  /* logical variables can be used as integer arguments */
1742  if(!basic_undefined_p(rb) && basic_logical_p(rb))
1743  if(arithmetic_intrinsic_p(f)) {
1744  free_basic(rb);
1746  }
1747  }
1748 
1749  }
1750 
1751  /* pips_debug(7, "Intrinsic call to intrinsic \"%s\" with a posteriori result type \"%s\"\n", */
1752  /* module_local_name(f), */
1753  /* basic_to_string(rb)); */
1754 
1755  return rb;
1756 }
1757 
1758 /* basic basic_of_constant(call c): returns the basic of the call to a
1759  * constant.
1760  *
1761  * WARNING: returns a pointer towards an existing data structure
1762  */
1764 {
1765  type call_type, return_type;
1766 
1767  debug(7, "basic_of_constant", "Constant call\n");
1768 
1769  call_type = entity_type(call_function(c));
1770 
1771  if (type_tag(call_type) != is_type_functional)
1772  pips_internal_error("Bad call type tag");
1773 
1774  return_type = functional_result(type_functional(call_type));
1775 
1776  if (type_tag(return_type) != is_type_variable)
1777  pips_internal_error("Bad return call type tag");
1778 
1779  return(variable_basic(type_variable(return_type)));
1780 }
1781 
1782 ␌
1783 /* basic basic_union(expression exp1 exp2): returns the basic of the
1784  * expression which has the most global basic. Then, between "int" and
1785  * "float", the most global is "float".
1786  *
1787  * Note: there are two different "float" : DOUBLE PRECISION and REAL.
1788  *
1789  * WARNING: a new basic data structure is allocated (because you cannot
1790  * always find a proper data structure to return simply a pointer
1791  */
1793 {
1794  basic b1 = basic_of_expression(exp1);
1795  basic b2 = basic_of_expression(exp2);
1796  basic b = basic_maximum(b1, b2);
1797 
1798  free_basic(b1);
1799  free_basic(b2);
1800  return b;
1801 }
1802 
1803 /* get the ultimate basic from a basic typedef
1804  */
1805 basic
1807 {
1808  if(basic_typedef_p(b)) {
1810  pips_assert("typedef really has a variable type", type_variable_p(t) );
1811  b = variable_basic(type_variable(t));
1812  }
1813  return b;
1814 }
1815 
1817 {
1818  basic b = basic_undefined;
1819  basic b1 = basic_ultimate(fb1);
1820  basic b2 = basic_ultimate(fb2);
1821 
1822 
1823  if(basic_derived_p(fb1)) {
1824  entity e1 = basic_derived(fb1);
1825 
1826  if(entity_enum_p(e1)) {
1827  b1 = make_basic(is_basic_int, (void *) 4);
1828  b = basic_maximum(b1, fb2);
1829  free_basic(b1);
1830  return b;
1831  }
1832  else
1833  pips_internal_error("Unanalyzed derived basic b1");
1834  }
1835 
1836  if(basic_derived_p(fb2)) {
1837  entity e2 = basic_derived(fb2);
1838 
1839  if(entity_enum_p(e2)) {
1840  b2 = make_basic(is_basic_int, (void *) 4);
1841  b = basic_maximum(fb1, b2);
1842  free_basic(b2);
1843  return b;
1844  }
1845  else
1846  pips_internal_error("Unanalyzed derived basic b2");
1847  }
1848 
1849  /* FI: I do not believe this is correct for all intrinsics! */
1850 
1851  pips_debug(7, "Tags: tag exp1 = %d, tag exp2 = %d\n",
1852  basic_tag(b1), basic_tag(b2));
1853 
1854 
1855  if(basic_overloaded_p(b2)) {
1856  b = copy_basic(b2);
1857  }
1858  else {
1859  switch(basic_tag(b1)) {
1860 
1861  case is_basic_overloaded:
1862  b = copy_basic(b1);
1863  break;
1864 
1865  case is_basic_string:
1866  if(basic_string_p(b2)) {
1867  int s1 = SizeOfElements(b1);
1868  int s2 = SizeOfElements(b2);
1869 
1870  /* Type checking problem for ? : with gcc... */
1871  if(s1>s2)
1872  b = copy_basic(b1);
1873  else
1874  b = copy_basic(b2);
1875  }
1876  else
1878  break;
1879 
1880  case is_basic_logical:
1881  if(basic_logical_p(b2)) {
1882  _int s1 = basic_logical(b1);
1883  _int s2 = basic_logical(b2);
1884 
1885  b = make_basic(is_basic_logical,UUINT(s1>s2?s1:s2));
1886  }
1887  else if(basic_int_p(b2)) {
1888  b = copy_basic(b2);
1889  }
1890  else
1892  break;
1893 
1894  case is_basic_complex:
1896  _int s1 = SizeOfElements(b1);
1897  _int s2 = SizeOfElements(b2);
1898 
1899  b = make_basic(is_basic_complex, UUINT(s1>s2?s1:s2));
1900  }
1901  else
1903  break;
1904 
1905  case is_basic_float:
1906  if(basic_complex_p(b2)) {
1907  _int s1 = SizeOfElements(b1);
1908  _int s2 = SizeOfElements(b2);
1909 
1910  b = make_basic(is_basic_complex, UUINT(s1>s2?s1:s2));
1911  }
1912  else if(basic_float_p(b2) || basic_int_p(b2)) {
1913  _int s1 = SizeOfElements(b1);
1914  _int s2 = SizeOfElements(b2);
1915 
1916  b = make_basic(is_basic_float, UUINT(s1>s2?s1:s2));
1917  }
1918  else
1920  break;
1921 
1922  case is_basic_int:
1923  if(basic_complex_p(b2) || basic_float_p(b2)) {
1924  _int s1 = SizeOfElements(b1);
1925  _int s2 = SizeOfElements(b2);
1926 
1927  b = make_basic(basic_tag(b2), UUINT(s1>s2?s1:s2));
1928  }
1929  else if(basic_int_p(b2)) {
1930  _int s1 = SizeOfElements(b1);
1931  _int s2 = SizeOfElements(b2);
1932 
1933  b = make_basic(is_basic_int, UUINT(s1>s2?s1:s2));
1934  }
1935  else if(basic_logical_p(b2)) {
1936  b = copy_basic(b1);
1937  }
1938  else if(basic_pointer_p(b2)) {
1939  return copy_basic(b2);
1940  }
1941  else
1943  break;
1944  /* NN: More cases are added for C. To be refined */
1945  case is_basic_bit:
1946  if(basic_bit_p(b2)) {
1947  if(basic_bit(b1)>=basic_bit(b2))
1948  b = copy_basic(b1);
1949  else
1950  b = copy_basic(b2);
1951  }
1952  else
1953  /* bit is a lesser type */
1954  b = copy_basic(b2);
1955  break;
1956  case is_basic_pointer:
1957  {
1958  if(basic_int_p(b2) || basic_bit_p(b2))
1959  b = copy_basic(b1);
1960  else if(basic_float_p(b2) || basic_logical_p(b2) || basic_complex_p(b2)) {
1961  /* Are they really comparable? */
1962  b = copy_basic(b1);
1963  }
1964  else if(basic_overloaded_p(b2))
1965  b = copy_basic(b1);
1966  else if(basic_pointer_p(b2)) {
1967  /* How can we compare two pointer types? Equality? Comparison of the pointed types? */
1968  /* pips_internal_error("Comparison of two pointer types not implemented"); */
1969  type t1 = basic_pointer(b1);
1970  type t2 = basic_pointer(b2);
1971 
1972  if(type_variable_p(t1) && type_variable_p(t2)) {
1973  /* SG checks for equality, he doesn't understand the meaning of
1974  * having a float as the basic maximum of two float*
1975  * and cowardly refuses to fix the code */
1976  if(type_equal_p(t1,t2))
1977  b = copy_basic(b1);
1978  else {
1979  basic nb1 = variable_basic(type_variable(t1));
1980  basic nb2 = variable_basic(type_variable(t2));
1981 
1982 
1983  /* FI: not convincing. As in other places, assuming this
1984  is meaningful, it would be better to use a basic
1985  comparator, basic_greater_p(), which could return 1, -1
1986  or 0 or ??? and deal with non comparable type. */
1987  b = basic_maximum(nb1, nb2);
1988  }
1989 
1990  }
1991  else if (type_void_p(t1) && type_void_p(t2) )
1992  b = copy_basic(b1);
1993  else
1994  pips_internal_error("Comparison of two pointer types not meaningful");
1995  }
1996  else if(basic_derived_p(b2))
1997  pips_internal_error("Comparison between pointer and struct/union not implemented");
1998  else if(basic_typedef_p(b2))
1999  pips_internal_error("b2 cannot be a typedef basic");
2000  else
2001  pips_internal_error("unknown tag %d for basic b2", basic_tag(b2));
2002  break;
2003  }
2004  case is_basic_derived:
2005  /* How do you compare a structure or a union to another type?
2006  The only case which seems to make sense is equality. */
2007  pips_internal_error("Derived basic b1 it not comparable to another basic");
2008  break;
2009  case is_basic_typedef:
2010  pips_internal_error("b1 cannot be a typedef basic");
2011  break;
2012  default: pips_internal_error("Ill. basic tag %d", basic_tag(b1));
2013  }
2014  }
2015 
2016  return b;
2017 
2018  /*
2019  if( (t1 != is_basic_complex) && (t1 != is_basic_float) &&
2020  (t1 != is_basic_int) && (t2 != is_basic_complex) &&
2021  (t2 != is_basic_float) && (t2 != is_basic_int) )
2022  pips_internal_error("Bad basic tag for expression in numerical function");
2023 
2024  if(t1 == is_basic_complex)
2025  return(b1);
2026  if(t2 == is_basic_complex)
2027  return(b2);
2028  if(t1 == is_basic_float) {
2029  if( (t2 != is_basic_float) ||
2030  (basic_float(b1) == DOUBLE_PRECISION_SIZE) )
2031  return(b1);
2032  return(b2);
2033  }
2034  if(t2 == is_basic_float)
2035  return(b2);
2036  return(b1);
2037  */
2038 }
2039 
2040 basic basic_of_expressions(list expressions,bool skip_overloaded)
2041 {
2042  if(ENDP(expressions)) return basic_undefined;
2043  else if(ENDP(CDR(expressions))) return basic_of_expression(EXPRESSION(CAR(expressions)));
2044  else {
2045  basic out = basic_of_expression(EXPRESSION(CAR(expressions)));
2046  FOREACH(EXPRESSION,exp,CDR(expressions)) {
2048  if(skip_overloaded && basic_overloaded_p(out)) {
2049  free_basic(out);
2050  out=b;
2051  }
2052  else if( skip_overloaded && basic_overloaded_p(b)) {
2053  free_basic(b);
2054  }
2055  else {
2056  basic tmp =basic_maximum(out,b);
2057  free_basic(b);
2058  free_basic(out);
2059  out=tmp;
2060  }
2061  }
2062  return out;
2063  }
2064 }
2065 
2066 
2067 /* END_EOLE */
2068 
2069 /**************************************************** expression_to_type */
2070 
2071 /**
2072  @return the (newly allocated) type of the result given by call to
2073  an intrinsic function.
2074 
2075  This type must be computed with the basic of the arguments of the
2076  intrinsic for overloaded operators. It should be able to accomodate
2077  more than two arguments as for generic min and max operators.
2078 */
2079 
2081 {
2082 
2083  entity f = call_function(c);
2084  list args = call_arguments(c);
2085  type t = type_undefined; /* the result */
2087 
2088  if(type_void_p(rt)) {
2089  t = copy_type(rt);
2090  }
2091  else if(type_variable_p(rt)) {
2093 
2094  // FI: to avoid cycles between librairies ri-util and prettyprint
2095  /* pips_debug(9, "Intrinsic call to intrinsic \"%s\" with a priori result type \"%s\"\n", */
2096  /* module_local_name(f), */
2097  /* words_to_string(words_type(rt, NIL, false))); */
2098 
2099  if(basic_overloaded_p(rb))
2100  {
2101 
2102  if (ENDP(args))
2103  {
2104  /* I don't know the type since there is no arguments !
2105  Bug encountered with a FMT=* in a PRINT.
2106  RK, 21/02/1994 : */
2107  /* leave it overloaded */
2108  t = copy_type(rt);
2109  }
2110  else if(ENTITY_ADDRESS_OF_P(f))
2111  {
2112  expression e = EXPRESSION(CAR(args));
2113  t = expression_to_type(e);
2116  NIL, NIL ));
2117 
2118  }
2119  else if(ENTITY_DEREFERENCING_P(f))
2120  {
2121  expression e = EXPRESSION(CAR(args));
2122  type ct = ultimate_type(expression_to_type(e)); /* isn't expression_to_type expected to return a bct?
2123  well, there are cases (casts) which are not clear on this point... BC. */
2124 
2125  if (type_variable_p(ct))
2126  {
2127  variable cv = type_variable(ct);
2128  basic cb = variable_basic(cv);
2129  list cd = variable_dimensions(cv);
2130  if( ENDP(cd)) {
2131  if(basic_pointer_p(cb))
2132  {
2134  pips_assert("The pointed type is consistent",
2135  type_consistent_p(t));
2136  free_type(ct); /* isn't it dangerous?, an ultimate_type can be an entity type! */
2137  }
2138  else if(basic_string_p(cb))
2139  {
2141  }
2142  else
2143  {
2144  pips_assert("Dereferencing of a non-pointer expression : it must be an array\n", !ENDP(cd));
2145  }
2146  }
2147  else {
2148  variable_dimensions(cv) = CDR(cd);
2149  cd->cdr = NIL;
2150  gen_full_free_list(cd);
2151  t = ct;
2152  }
2153  }
2154  else
2155  {
2156  pips_internal_error("dereferencing of a non-variable : not handled yet");
2157  }
2158  }
2159  else if(ENTITY_POINT_TO_P(f) || ENTITY_FIELD_P(f))
2160  {
2161  //expression e1 = EXPRESSION(CAR(args));
2162  expression e2 = EXPRESSION(CAR(CDR(args)));
2163 
2164  pips_assert("Two arguments for POINT_TO or FIELD \n",
2165  gen_length(args)==2);
2166 
2167  // FI: to avoid cycles betwen librairies ri-util and prettyprint
2168  /* ifdebug(9) */
2169  /* { */
2170  /* pips_debug(8, "Point to case, e1 = "); */
2171  /* print_expression(e1); */
2172  /* pips_debug(8, " and e2 = "); */
2173  /* print_expression(e2); */
2174  /* pips_debug(8, "\n"); */
2175  /* } */
2176  t = expression_to_type(e2);
2177  }
2178  else if(ENTITY_BRACE_INTRINSIC_P(f))
2179  {
2180  /* We should reconstruct a struct type or an array type... */
2182  NIL,NIL));
2183  }
2184  else if(ENTITY_ASSIGN_P(f))
2185  {
2186  /* returns the type of the left hand side */
2187  t = expression_to_type(EXPRESSION(CAR(args)));
2188  }
2189  else if(ENTITY_COMMA_P(f))
2190  {
2191  /* The value returned is the value of the last expression in the list. */
2192 
2194  }
2195  else if( ENTITY_CONDITIONAL_P(f))
2196  {
2197  /* let us assume that the two last arguments have the same
2198  type : basic_maximum does not preserve types enough
2199  (see Effects/lhs01.c, expression *(i>2?&i:&j) ). BC.
2200  */
2201  t = expression_to_type(EXPRESSION(CAR(CDR(args))));
2202  }
2203  else
2204  {
2205  bool minus_c_pointer_arithmetic = false;
2206 
2207  // special case for minus operator when first argument is a pointer type
2208  if (ENTITY_MINUS_C_P(f) )
2209  {
2210  expression exp1 = EXPRESSION(CAR(args));
2211  expression exp2 = EXPRESSION(CAR(CDR(args)));
2212  type t1 = expression_to_type(exp1);
2213  type t2 = expression_to_type(exp2);
2214 
2215  if (pointer_type_p(t1))
2216  {
2217  if (pointer_type_p(t2))
2218  {
2219  type pt1 = pointed_type(t1);
2220  type pt2 = pointed_type(t2);
2221  if (!type_equal_p(pt1, pt2))
2222  {
2223  // user application should not pass compilation by a standard compiler
2224  // should we also trigger an error here?
2225  // FI: to avoid cycles between librairies ri-util and prettyprint
2226  /* pips_user_warning("Non matching pointed types in pointer arithmetic expression %s - %s\n", */
2227  /* expression_to_string(exp1), expression_to_string(exp2)); */
2228  pips_user_warning("Non matching pointed types in pointer arithmetic expressions.\n");
2229  }
2230  // result is of type ptrdiff_t (ISO/IEC 9899:TC3)
2232  NIL,NIL));
2233 
2234 
2235  }
2236  else
2237  {
2238  t = copy_type(t1);
2239  }
2240  minus_c_pointer_arithmetic = true;
2241  free_type(t1); free_type(t2);
2242  }
2243  }
2244 
2245  if (! minus_c_pointer_arithmetic )
2246  {
2247  /* current type of expression is type of first
2248  argument, except if it is an array, e.g. "fifi+3"
2249  after declaration "int fifi[3];" */
2250  type ct = expression_to_type(EXPRESSION(CAR(args)));
2251 
2252  if(array_type_p(ct)) {
2254  type nct = type_to_pointer_type(sct);
2255  free_type(ct);
2256  ct = nct;
2257  }
2258 
2259  FOREACH(EXPRESSION, arg, CDR(args)) {
2260  type nt = expression_to_type(arg);
2263 
2266 
2267  /* we need to check the variable dimensions */
2268  if (gen_length(nd) == gen_length(cd))
2269  {
2270  /* re-use an existing function. we do not take into
2271  account variable dimensions here. It may not be correct.
2272  but it's not worse than the previously existing version
2273  of expression_to_type
2274  */
2275  pips_debug(9,"same number of dimensions\n");
2276  basic b = basic_maximum(cb, nb);
2277  free_type(ct);
2278  free_type(nt);
2280  }
2281  else
2282  {
2283  pips_debug(9,"different number of dimensions\n");
2284  pips_assert("pointer arithmetic with array name, first element must be the address expression",
2285  gen_length(cd) > gen_length(nd));
2286  /* current type is still valid */
2287  free_type(nt);
2288  }
2289 
2290 
2291  }
2292  t = ct;
2293  }
2294  }
2295  }
2296  else {
2297  t = copy_type(rt);
2298  }
2299  }
2300  else
2301  pips_internal_error("Unexpected return type.");
2302 
2303  // FI: to avoid cycles between librairies ri-util and prettyprint
2304  /* pips_debug(9, "Intrinsic call to intrinsic \"%s\" " */
2305  /* "with a posteriori result type \"%s\"\n", */
2306  /* module_local_name(f), */
2307  /* words_to_string(words_type(t, NIL, false))); */
2308 
2309  return t;
2310 }
2311 
2312 
2314 {
2315  entity e = call_function(c);
2316  type t = type_undefined;
2317 
2318  switch (value_tag(entity_initial(e)))
2319  {
2320  case is_value_code:
2323  NIL, NIL));
2324  break;
2325  case is_value_intrinsic:
2326  t = intrinsic_call_to_type(c);
2327  break;
2328  case is_value_symbolic:
2329  /* b = make_basic(is_basic_overloaded, UU); */
2332  NIL, NIL));
2333  break;
2334  case is_value_constant:
2337  NIL, NIL));
2338  break;
2339  case is_value_unknown:
2340  pips_debug(1, "function %s has no initial value.\n"
2341  " Maybe it has not been parsed yet.\n",
2342  entity_name(e));
2345  NIL, NIL));
2346  break;
2347  default: pips_internal_error("unknown tag %d", t);
2348  /* Never go there... */
2349  }
2350 
2351  return t;
2352 }
2353 
2355 {
2356  type t = type_undefined;
2357 
2358  // FI: to avoid cycles betwen librairies ri-util and prettyprint
2359  /* pips_debug(9, "input entity type %s\n", */
2360  /* words_to_string(words_type(entity_type(reference_variable(ref)), */
2361  /* NIL, false))); */
2362 
2364 
2365  // FI: to avoid cycles betwen librairies ri-util and prettyprint
2366  /* pips_debug(9, "reference case \n"); */
2367  /* pips_debug(9, "exp_type %s\n", words_to_string(words_type(exp_type, NIL, false))); */
2368 
2369  if(type_variable_p(exp_type))
2370  {
2371  type ct = exp_type; /* current type */
2372  basic cb = variable_basic(type_variable(exp_type)); /* current basic */
2373 
2374  list cd = variable_dimensions(type_variable(exp_type)); /* current dimensions */
2375  list l_inds = reference_indices(ref);
2376 
2377  pips_debug(9, "reference to a variable, "
2378  "we iterate over the indices if any \n");
2379 
2380  while (!ENDP(l_inds))
2381  {
2382  // FI: to avoid cycles betwen librairies ri-util and prettyprint
2383  /* ifdebug(9) { */
2384  /* pips_debug(7, "new iteration : current type : %s\n", */
2385  /* words_to_string(words_type(ct, NIL, false))); */
2386  /* pips_debug(7, "current list of indices: \n"); */
2387  /* print_expressions(l_inds); */
2388  /* } */
2389  if(!ENDP(cd))
2390  {
2391  pips_debug(9, "poping one type dimension and one index\n");
2392  POP(cd);
2393  POP(l_inds);
2394  }
2395  else
2396  {
2397  pips_debug(9,"going through pointer dimension. \n");
2398  // FI: struct are only possible for constant memory path
2399  // the usual internal representation does not use fields
2400  // as indices
2401  pips_assert("reference has too many indices :"
2402  " pointer or struct expected\n",
2403  basic_pointer_p(cb) || basic_derived_p(cb));
2404  if(basic_pointer_p(cb)) {
2405  ct = basic_pointer(cb);
2406  cb = variable_basic(type_variable(ct));
2408  }
2409  else if(basic_derived_p(cb)) { // must be a struct, see assert
2410  entity de = basic_derived(cb);
2411  type st = entity_type(de);
2412  list fl = type_struct(st);
2413  // FI: I am not sure about the internal representation...
2414  // Do we find an integer or a field reference as
2415  // subscript expression?
2416  expression ind = EXPRESSION(CAR(l_inds));
2417  value ind_v = EvalExpression(ind);
2418  if(value_constant_p(ind_v)) {
2419  int n = constant_int(value_constant(ind_v));
2420  entity f = ENTITY(gen_nth(n, fl));
2421  type ft = entity_type(f);
2422  ct = ft;
2423  cb = variable_basic(type_variable(ct));
2425  }
2426  else { // FI: assume a reference to a field
2427  // pips_internal_error("Unexpected internal representation.\n");
2428  pips_assert("The subscript expression is a reference",
2429  expression_reference_p(ind));
2430  entity f =
2432  type ft = entity_type(f);
2433  ct = ft;
2434  cb = variable_basic(type_variable(ct));
2436  }
2437  }
2438  POP(l_inds);
2439  }
2440  }
2441 
2442  /* Warning : qualifiers are set to NIL, because I do not see
2443  * the need for something else for the moment. BC.
2444  */
2445  t = make_type_variable(
2447  gen_full_copy_list(cd),
2448  NIL));
2449  // FI: to avoid cycles betwen librairies ri-util and prettyprint
2450  /* pips_debug(9, "t at the end of reference case %s\n", words_to_string(words_type(t, NIL, false))); */
2451  }
2452  else if(type_functional_p(exp_type))
2453  {
2454  pips_debug(9, "functional case \n");
2455  /* A reference to a function returns a pointer to a function
2456  of the very same time */
2459  (make_basic(is_basic_pointer, copy_type(exp_type)),
2460  NIL, NIL));
2461  }
2462  else
2463  {
2464  // The unknown type ends up here
2465  pips_internal_error("Bad reference type tag %d \"%s\" for reference to %s",
2466  type_tag(exp_type),
2467  type_to_string(exp_type),
2469  }
2470  // FI: to avoid cycles betwen librairies ri-util and prettyprint
2471  /* pips_debug(9, "returns with %s\n", words_to_string(words_type(t, NIL, false))); */
2472  return t;
2473 }
2474 
2475 
2476 /**
2477  For an array declared as int a[10][20], the type returned for a[i]
2478  is int [20]. gcc claims it is int (*)[10], that is a pointer to an
2479  array of 10 elements.
2480 
2481  @param exp is an expression
2482  @return a new allocated type which is the ntype of the expression in which
2483  typedef's are replaced by combination of basic types.
2484 
2485 */
2487 {
2488  debug_on("RI-UTIL_DEBUG_LEVEL");
2489  /* does not cover references to functions ...*/
2490  /* Could be more elaborated with array types for array expressions */
2491  type t = type_undefined;
2492 
2493  syntax s_exp = expression_syntax(exp);
2494 
2495  // FI: to avoid cycles betwen librairies ri-util and prettyprint
2496  /* ifdebug(9){ */
2497  /* pips_debug(6, "begins with expression :"); */
2498  /* print_expression(exp); */
2499  /* fprintf(stderr, "\n"); */
2500  /* } */
2501 
2502  switch(syntax_tag(s_exp))
2503  {
2504  case is_syntax_reference:
2505  {
2506  pips_debug(9, "reference case \n");
2507  t = reference_to_type(syntax_reference(s_exp));
2508  break;
2509  }
2510  case is_syntax_call:
2511  {
2512  pips_debug(9, "call case \n");
2513  t = call_to_type(syntax_call(s_exp));
2514  break;
2515  }
2516  case is_syntax_range:
2517  {
2518  pips_debug(9, "range case \n");
2519  /* Well, let's assume range are well formed... */
2521  break;
2522  }
2523  case is_syntax_cast:
2524  {
2525  pips_debug(9, "cast case \n");
2526  t = copy_type(cast_type(syntax_cast(s_exp)));
2527  if (!type_void_p(t) && type_tag(t) != is_type_variable)
2528  pips_internal_error("Bad reference type tag %d",type_tag(t));
2529  break;
2530  }
2532  {
2533  /*
2534  sizeofexpression se = syntax_sizeofexpression(s_exp);
2535  pips_debug(9, "size of case \n");
2536  if (sizeofexpression_type_p(se))
2537  {
2538  t = copy_type(sizeofexpression_type(se));
2539  if (type_tag(t) != is_type_variable)
2540  pips_internal_error("Bad reference type tag %d",type_tag(t));
2541  }
2542  else
2543  {
2544  t = expression_to_type(sizeofexpression_expression(se));
2545  }*/
2547  break;
2548  }
2549  case is_syntax_subscript:
2550  {
2551  /* current type */
2553  /* current basic */
2555  /* current dimensions */
2557  list l_inds = subscript_indices(syntax_subscript(s_exp));
2558 
2559  pips_debug(9, "subscript case \n");
2560 
2561  while (!ENDP(l_inds))
2562  {
2563  if(!ENDP(cd))
2564  {
2565  POP(cd);
2566  }
2567  else
2568  {
2569  pips_assert("reference has too many indices : pointer expected\n", basic_pointer_p(cb));
2570  ct = basic_pointer(cb);
2571  if( type_variable_p(ct) ) {
2572  cb = variable_basic(type_variable(ct));
2574  }
2575  else {
2576  abort();
2577  pips_internal_error("unhandled case");
2578  }
2579  }
2580  POP(l_inds);
2581  }
2582 
2583  /* Warning : qualifiers are set to NIL, because I do not see
2584  the need for something else for the moment. BC.
2585  */
2588  gen_full_copy_list(cd),
2589  NIL));
2590  break;
2591  }
2592  case is_syntax_application:
2593  {
2594  pips_debug(9, "application case \n");
2596  break;
2597  }
2598  case is_syntax_va_arg:
2599  {
2600  pips_debug(9, "va_arg case\n");
2601  list vararg_list = syntax_va_arg(s_exp);
2602  sizeofexpression soe = SIZEOFEXPRESSION(CAR(CDR(vararg_list)));
2603 
2604  t = copy_type(sizeofexpression_type(soe));
2605  break;
2606  }
2607 
2608  default:
2609  pips_internal_error("Bad syntax tag %d", syntax_tag(s_exp));
2610  /* Never go there... */
2611  }
2612 
2613  // FI: to avoid cycles betwen librairies ri-util and prettyprint
2614  /* pips_debug(9, "returns with %s\n", words_to_string(words_type(t, NIL, false))); */
2615  debug_off();
2616  return t;
2617 }
2618 
2619 /* If the expression is casted, return its type before cast */
2621 {
2622  type t = type_undefined;
2623  syntax s_exp = expression_syntax(exp);
2624 
2625  // FI: to avoid cycles betwen librairies ri-util and prettyprint
2626  /* ifdebug(6){ */
2627  /* pips_debug(6, "begins with expression :"); */
2628  /* print_expression(exp); */
2629  /* pips_debug(6, "\n"); */
2630  /* } */
2631 
2632  if(syntax_cast_p(s_exp)) {
2633  expression sub_exp = cast_expression(syntax_cast(s_exp));
2634 
2635  t = expression_to_uncasted_type(sub_exp);
2636  }
2637  else {
2638  t = expression_to_type(exp);
2639  }
2640 
2641  return t;
2642 }
2643 
2644 /* Preserve typedef'ed types when possible */
2646 {
2647  /* does not cover references to functions ...*/
2648  /* Could be more elaborated with array types for array expressions */
2649  type t = type_undefined;
2650  basic b = some_basic_of_any_expression(e, false, false);
2651  variable v = make_variable(b, NIL, NIL);
2652 
2653  t = make_type(is_type_variable, v);
2654 
2655  return t;
2656 }
2657 
2658 
2659 /*************************************************************************/
2660 
2661 
2662 ␌
2663 /* Returns true if t is a variable type with a basic overloaded. And
2664  * false elsewhere. See MakeTypeOverloaded().
2665  */
2667 {
2668  //pips_assert("type t is of kind variable", type_variable_p(t));
2669 
2670  if(!type_variable_p(t))
2671  return false;
2672 
2674 }
2675 
2676 /* bool is_inferior_basic(basic1, basic2)
2677  * return true if basic1 is less complex than basic2
2678  * ex: int is less complex than float*4,
2679  * float*4 is less complex than float*8, ...
2680  * - overloaded is inferior to any basic.
2681  * - logical is inferior to any other but overloaded.
2682  * - string is inferior to any other but overloaded and logical.
2683  * Used to decide that the sum of an int and a float
2684  * is a floating-point addition (for ex.)
2685  */
2686 bool
2688 basic b1, b2;
2689 {
2690  if ( b1 == basic_undefined )
2691  pips_internal_error("first basic_undefined");
2692  else if ( b2 == basic_undefined )
2693  pips_internal_error("second basic_undefined");
2694 
2695  if (basic_overloaded_p(b1))
2696  return (true);
2697  else if (basic_overloaded_p(b2))
2698  return (false);
2699  else if (basic_logical_p(b1))
2700  return (true);
2701  else if (basic_logical_p(b2))
2702  return (false);
2703  else if (basic_string_p(b1))
2704  return (true);
2705  else if (basic_string_p(b2))
2706  return (false);
2707  else if (basic_int_p(b1)) {
2708  if (basic_int_p(b2))
2709  return (basic_int(b1) <= basic_int(b2));
2710  else
2711  return (true);
2712  }
2713  else if (basic_float_p(b1)) {
2714  if (basic_int_p(b2))
2715  return (false);
2716  else if (basic_float_p(b2))
2717  return (basic_float(b1) <= basic_float(b2));
2718  else
2719  return (true);
2720  }
2721  else if (basic_complex_p(b1)) {
2722  if (basic_int_p(b2) || basic_float_p(b2))
2723  return (false);
2724  else if (basic_complex_p(b2))
2725  return (basic_complex(b1) <= basic_complex(b2));
2726  else
2727  return (true);
2728  }
2729  else
2730  pips_internal_error("Case never occurs.");
2731  return (true);
2732 }
2733 
2734 basic
2736 {
2737  /* basic_int, basic_float, basic_logical, basic_complex are all int's */
2738  /* so we duplicate them the same manner: with basic_int. */
2739  if (basic_int_p(b) || basic_float_p(b) ||
2741  return(make_basic(basic_tag(b), UUINT(basic_int(b))));
2742  else if (basic_overloaded_p(b))
2743  return(make_basic(is_basic_overloaded, UU));
2744  else {
2745  user_warning("simple_basic_dup",
2746  "(tag %td) isn't that simple\n", basic_tag(b));
2747  if (basic_string_p(b))
2748  fprintf(stderr, "string: value tag = %d\n",
2749  value_tag(basic_string(b)));
2750  return make_basic(basic_tag(b), UUINT(basic_int(b)));
2751  }
2752 }
2753 
2754 /* returns the corresponding generic conversion entity, if any.
2755  * otherwise returns entity_undefined.
2756  */
2757 entity
2759 {
2760  entity result;
2761 
2762  switch (basic_tag(b))
2763  {
2764  case is_basic_int:
2765  /* what about INTEGER*{2,4,8} ?
2766  */
2768  break;
2769  case is_basic_float:
2770  {
2771  if (basic_float(b)==4)
2773  else if (basic_float(b)==8)
2775  else
2776  result = entity_undefined;
2777  break;
2778  }
2779  case is_basic_complex:
2780  {
2781  if (basic_complex(b)==8)
2783  else if (basic_complex(b)==16)
2785  else
2786  result = entity_undefined;
2787  break;
2788  }
2789  default:
2790  result = entity_undefined;
2791  }
2792 
2793  return result;
2794 }
2795 ␌
2796 /*
2797  * A set of predicates to distinguish between types
2798  */
2799 
2801 {
2802  if (type_variable_p(t))
2803  {
2805  if (basic_int_p(b))
2806  if (basic_int(b)/10 == DEFAULT_SIGNED_TYPE_SIZE)
2807  return true;
2808  }
2809  return false;
2810 }
2811 
2813  if (basic_int_p(b))
2815  return true;
2816  return false;
2817 }
2818 ␌
2819 /* Predicates on types */
2820 
2822 {
2823  if (type_variable_p(t))
2824  {
2826  return unsigned_basic_p(b);
2827  }
2828  return false;
2829 }
2830 
2832 {
2833  if (type_variable_p(t))
2834  {
2836  if (basic_int_p(b))
2838  return true;
2839  }
2840  return false;
2841 }
2842 
2844 {
2845  if (!type_undefined_p(t) && type_variable_p(t))
2846  {
2848  if (!basic_undefined_p(b) && basic_bit_p(b))
2849  return true;
2850  }
2851  return false;
2852 }
2853 
2855 {
2856  if (!type_undefined_p(t) && type_variable_p(t))
2857  {
2859  if (!basic_undefined_p(b) && basic_string_p(b))
2860  return true;
2861  }
2862  return false;
2863 }
2864 
2866 {
2867  if (!type_undefined_p(t) && type_variable_p(t))
2868  {
2870  if (!basic_undefined_p(b) && basic_logical_p(b))
2871  return true;
2872  }
2873  return false;
2874 }
2875 
2876 /* return true whether `t' is a char or an unsigned char */
2878 {
2879  bool is_char = false;
2880 
2881  if (!type_undefined_p(t) && type_variable_p(t)) {
2883  if (!basic_undefined_p(b) && basic_int_p(b)) {
2884  int i = basic_int(b);
2885  is_char = (i==1)||(i==11); /* see words_basic() */
2886  }
2887  }
2888  return is_char;
2889 }
2890 
2891 /* Safer than the other implementation?
2892 bool pointer_type_p(type t)
2893 {
2894  bool is_pointer = false;
2895 
2896  if (!type_undefined_p(t) && type_variable_p(t)) {
2897  basic b = variable_basic(type_variable(t));
2898  if (!basic_undefined_p(b) && basic_pointer_p(b)) {
2899  is_pointer = true;
2900  }
2901  }
2902  return is_pointer;
2903 }
2904 */
2905 
2906 /* Here is the set of mapping functions, from the RI to C language types*/
2907 
2908 /* Returns true if t is one of the following types :
2909  void, char, short, int, long, float, double, signed, unsigned,
2910  and there is no array dimensions, of course*/
2911 
2913 {
2914  if (type_variable_p(t))
2915  {
2917  return ((variable_dimensions(type_variable(t)) == NIL) &&
2918  (basic_int_p(b) || basic_float_p(b) || basic_logical_p(b)
2920  || basic_bit_p(b)));
2921  }
2922  return (type_void_p(t) || type_unknown_p(t)) ;
2923 }
2924 
2925 /*
2926  @brief tests whether the basic of the input type is one of the following:
2927  void, char, short, int, long, float, double, signed, unsigned.
2928  (even if there are array dimensions
2929 */
2931 {
2932  if (type_variable_p(t))
2933  {
2935  return (basic_int_p(b) || basic_float_p(b) || basic_logical_p(b)
2937  || basic_bit_p(b));
2938  }
2939  return (type_void_p(t) || type_unknown_p(t)) ;
2940 }
2941 
2943 {
2944  return (type_variable_p(t) && (variable_dimensions(type_variable(t)) != NIL));
2945 }
2946 
2948 {
2949  int d = -1;
2950  if(type_variable_p(t))
2952  return d;
2953 }
2954 
2956 {
2957  return (type_variable_p(t) && (variable_dimensions(type_variable(t)) == NIL));
2958 }
2959 
2961 {
2962  t = ultimate_type(t);
2964  {
2966  return type_struct_variable_p(pt);
2967  }
2968  return false;
2969 }
2970 
2971 /* Is this equivalent to dependent_type_p()? */
2973 {
2974  bool return_val = false;
2975  if(array_type_p(t)) {
2979  return_val=true;
2980  break;
2981  }
2982  }
2983  }
2984  return return_val;
2985 }
2986 
2988 {
2989  return array_type_p(t) && !variable_length_array_type_p(t);
2990 }
2991 
2992 /* Check for scalar pointers */
2994 {
2995  bool pointer_p = false;
2996  if(type_variable_p(t)) {
2997  variable v = type_variable(t);
2998  basic b = variable_basic(v);
2999  if(basic_pointer_p(b))
3000  pointer_p = (variable_dimensions(type_variable(t)) == NIL);
3001 }
3002  return pointer_p;
3003 }
3004 
3005 /* Returns OK for "char[]" as well as for "char *". And do not forget
3006  * "string" for PIPS internal representation.
3007  *
3008  * Does not take care of typedef. Use compute_basic_concrete_type()
3009  * first is necessary.
3010  */
3012 {
3013  bool pointer_p = false;
3014  if(type_variable_p(t)) {
3015  variable v = type_variable(t);
3016  list dl = variable_dimensions(v);
3017  basic b = variable_basic(v);
3018  pointer_p = (ENDP(dl) && basic_pointer_p(b))
3019  || (ENDP(dl) && basic_string_p(b))
3020  || ((int)gen_length(dl)==1 && unbounded_dimension_p(DIMENSION(CAR(dl))));
3021  }
3022  return pointer_p;
3023 }
3024 
3026 {
3028  && (variable_dimensions(type_variable(t)) != NIL));
3029 }
3030 ␌
3031 
3032 /**
3033  returns the type pointed by the input type if it is a pointer or an array of pointers
3034  */
3036 {
3037  type res = type_undefined;
3038 
3041  return res;
3042 }
3043 
3044 // tests if a type is FILE *
3045 // beware: costly because it contains a string operation
3047 {
3048  bool res = false;
3049  if (type_variable_p(t))
3050  {
3052  if (basic_pointer_p(b))
3053  {
3054  t = basic_pointer(b);
3055  if (type_variable_p(t))
3056  {
3058  if (basic_derived_p(b))
3059  {
3060  entity te = basic_derived(b);
3061  if (strstr(entity_name(te), "_IO_FILE") != NULL)
3062  {
3063  res = true;
3064  }
3065  }
3066  }
3067  }
3068  }
3069  return res;
3070 }
3071 
3072 
3074 {
3075  list l_res = NIL;
3076 
3077  switch (type_tag(t))
3078  {
3079  case is_type_struct:
3080  l_res = type_struct(t);
3081  break;
3082  case is_type_union:
3083  l_res = type_union(t);
3084  break;
3085  case is_type_enum:
3086  l_res = type_enum(t);
3087  break;
3088  default:
3089  pips_internal_error("type_fields improperly called");
3090  }
3091  return l_res;
3092 
3093 }
3094 
3095 /* Returns true if t is of type struct, union or enum. Need to
3096  * distinguish with the case struct/union/enum in type in RI, these
3097  * are the definitions of the struct/union/enum themselve, not a
3098  * variable of this type.
3099  *
3100  * Example : struct foo var;
3101  *
3102  * Note: arrays of struct are not considered derived types
3103  */
3105 {
3107  && (variable_dimensions(type_variable(t)) == NIL));
3108 }
3110 {
3112  && (variable_dimensions(type_variable(t)) != NIL));
3113 }
3114 
3115 /* Returns true if t is of type derived and if the derived type is a struct.
3116  *
3117  * Example : struct foo var;
3118  *
3119  * Note: different trom type_struct_p
3120  */
3122 {
3123  bool struct_p = false;
3124  if(derived_type_p(t)) {
3126  entity dte = basic_derived(b);
3127  type dt = entity_type(dte);
3128  struct_p = type_struct_p(dt);
3129  }
3130  return struct_p;
3131 }
3132 
3134 {
3135  bool struct_p = false;
3136  if(array_of_derived_type_p(t)) {
3138  entity dte = basic_derived(b);
3139  type dt = entity_type(dte);
3140  struct_p = type_struct_p(dt);
3141  }
3142  return struct_p;
3143 }
3144 
3145 /* Returns true if t is of type derived and if the derived type is a union.
3146  *
3147  * Example : union foo var;
3148  *
3149  * Note: different trom type_union_p
3150  */
3152 {
3153  bool union_p = false;
3154  if(derived_type_p(t)) {
3156  entity dte = basic_derived(b);
3157  type dt = entity_type(dte);
3158  union_p = type_union_p(dt);
3159  }
3160  return union_p;
3161 }
3162 
3163 /* Returns true if t is of type derived and if the derived type is a enum.
3164  *
3165  * Example : enum foo var;
3166  *
3167  * FI: Could be unified with the prevous two functions,
3168  * struct_type_p() and union_type_p()
3169  *
3170  * Note: different from type_enum_p
3171  */
3173 {
3174  bool enum_p = false;
3175  if(derived_type_p(t)) {
3177  entity dte = basic_derived(b);
3178  type dt = entity_type(dte);
3179  enum_p = type_enum_p(dt);
3180  }
3181  return enum_p;
3182 }
3183 
3184 /* Returns true if t is a typedefED type.
3185 
3186  Example : Myint i;
3187 */
3188 
3190 {
3192  && (variable_dimensions(type_variable(t)) == NIL));
3193 }
3194 
3195 ␌
3197 {
3198  if (t == type_undefined)
3199  {
3201  return make_type_variable(v);
3202  }
3203  else
3204  {
3205  if (signed_type_p(t) || unsigned_type_p(t))
3206  {
3208  int i = basic_int(b);
3209  variable v = make_variable(make_basic_int(10*(i/10)+size),NIL,NIL);
3210  pips_debug(8,"Old basic size: %d, new size : %d\n",i,10*(i/10)+size);
3211  return make_type_variable(v);
3212  }
3213  else
3214  {
3215  if (bit_type_p(t))
3216  /* If it is int i:5, keep the bit basic type*/
3217  return t;
3218  else
3219  user_warning("Parse error", "Standard integer types\n");
3220  return type_undefined;
3221  }
3222  }
3223 }
3224 
3225 /* Used to encode the long keyword in the parser. Used to detect long
3226  double type in parser*/
3228 {
3229  bool long_p = false;
3230  if(!type_undefined_p(t) && type_variable_p(t)) {
3231  variable v = type_variable(t);
3232  basic b = variable_basic(v);
3233  if(basic_int_p(b)) {
3234  int s = basic_int(b);
3235 
3236  long_p = ENDP(variable_dimensions(v))
3237  && ENDP(variable_qualifiers(v))
3238  && (s == DEFAULT_INTEGER_TYPE_SIZE
3241  }
3242  }
3243  return long_p;
3244 }
3245 
3247 {
3248  bool default_complex_p = false;
3249  if(!type_undefined_p(t) && type_variable_p(t)) {
3250  variable v = type_variable(t);
3251  basic b = variable_basic(v);
3252  if(basic_complex_p(b)) {
3253  int s = basic_int(b);
3254 
3255  default_complex_p = ENDP(variable_dimensions(v))
3256  && ENDP(variable_qualifiers(v))
3257  && s == DEFAULT_COMPLEX_TYPE_SIZE;
3258  }
3259  }
3260  return default_complex_p;
3261 }
3262 
3264 {
3265  bool float_p = false;
3266  if(!type_undefined_p(t) && type_variable_p(t)) {
3267  variable v = type_variable(t);
3268  basic b = variable_basic(v);
3269  if(basic_float_p(b)) {
3270  float_p = true;
3271  }
3272  }
3273  return float_p;
3274 }
3275 
3277 {
3278  bool long_p = false;
3279  if(!type_undefined_p(t) && type_variable_p(t)) {
3280  variable v = type_variable(t);
3281  basic b = variable_basic(v);
3282  if(basic_int_p(b)) {
3283 
3284  long_p = ENDP(variable_dimensions(v));
3285  /* The qualifiers do not matter
3286  && ENDP(variable_qualifiers(v))
3287  */
3288  /* unsigned are as OK as signed */ /*
3289  && (s == DEFAULT_INTEGER_TYPE_SIZE
3290  || s == DEFAULT_LONG_INTEGER_TYPE_SIZE
3291  || s == DEFAULT_LONG_LONG_INTEGER_TYPE_SIZE);
3292  */
3293  }
3294  }
3295  return long_p;
3296 }
3297 
3299 {
3300  bool int_p = false;
3301  if(!type_undefined_p(t) && type_variable_p(t)) {
3302  variable v = type_variable(t);
3303  basic b = variable_basic(v);
3304  int_p = basic_int_p(b);
3305  }
3306  return int_p;
3307 }
3308 
3310 {
3311  if (t == type_undefined)
3312  {
3314  return make_type_variable(v);
3315  }
3316  else
3317  {
3318  if (signed_type_p(t) || unsigned_type_p(t) || long_type_p(t))
3319  {
3321  int i = basic_int(b);
3322  variable v;
3323  if (i%10 == DEFAULT_INTEGER_TYPE_SIZE)
3324  {
3325  /* long */
3327  pips_debug(8,"Old basic size: %d, new size : %d\n",i,10*(i/10)+DEFAULT_LONG_INTEGER_TYPE_SIZE);
3328  }
3329  else
3330  {
3331  /* long long */
3333  pips_debug(8,"Old basic size: %d, new size : %d\n",i,10*(i/10)+DEFAULT_LONG_LONG_INTEGER_TYPE_SIZE);
3334  }
3335  return make_type_variable(v);
3336  }
3337  else
3338  {
3339  if (bit_type_p(t))
3340  /* If it is long int i:5, keep the bit basic type*/
3341  return t;
3342  else
3343  user_warning("Parse error", "Standard long integer types\n");
3344  return type_undefined;
3345  }
3346  }
3347 }
3348 ␌
3349 /* FI: there are different notions of "ultimate" types in C.
3350 
3351  We may need to reduce a type to basic concrete types, removing all
3352  typedefs wherever they are. This is done by type_to_basic_concrete_type,
3353  see below.
3354 
3355  We may also need to know if the type is compatible with a function
3356  call: we need to chase down the pointers as well as the typedefs. See
3357  call_compatible_type_p().
3358 
3359  Finally, we may need to know how much memory should be allocated to
3360  hold an object of this type. This is what was needed first, hence the
3361  semantics of the function below.
3362 
3363  Shoud this function be extended to return a type_undefined whe nthe
3364  argument is type_undefined or simply core dump to signal an issue
3365  as soon as possible? The second alternative is chosen.
3366  */
3367 
3368 /* What type should be used to perform memory allocation? No
3369  allocation of a new type. */
3370 static type private_ultimate_type(type t, bool arrays_only)
3371 {
3372  type nt;
3373 
3374  // only under debug, because there is a big impact on performance
3375  ifdebug(1) pips_assert("type consistent",type_consistent_p(t));
3376 
3377  pips_debug(9, "Begins with type \"%s\"\n", type_to_string(t));
3378 
3379  if(type_variable_p(t)) {
3380  variable vt = type_variable(t);
3381  basic bt = variable_basic(vt);
3382 
3383  /* pips_debug(9, "and basic \"%s\"\n", basic_to_string(bt)); */
3384 
3385  if(basic_typedef_p(bt)) {
3386  entity e = basic_typedef(bt);
3387  type st = entity_type(e);
3388 
3389  if (!arrays_only
3391  // recursion
3392  nt = ultimate_type(st);
3393  else
3394  nt = t;
3395 
3396  // FC->SG the following stuff requires more comments to be understandable
3397  // FC->SG why this #if ???
3398 #if 1
3399  /* without this test, we would erase the dimension ... */
3400  if( !ENDP(variable_dimensions(vt) ) )
3401  {
3402  /* what should we do ? allocate a new type ...
3403  * but this breaks the semantic of the function
3404  * we still create a leak for this case, which does not appear to
3405  * often a warning is printed out, so that we don't forget it
3406  */
3407  // ??? FC->SG why this static structure?
3408  static size_t holder_iter = 0;
3409  // ??? FC->SG: why 8? why not 314159?
3410  //
3411  // this is creazy programming and a time bomb:-(
3412  //
3413  // it seems that the returned allocated type is stored there
3414  // so that it may be freed some time later, with the hope that by
3415  // the time it is freed it will not be in use anymore.
3416  //
3417  // I would prefer a memory leak in place of this kludge.
3418  // I would rather suggest to memoize the computed types
3419  // and not to do this kind of hidden garbage collector.
3420  static type holder[8] = {// SG: this should avoid the leak
3429  };
3430  nt=copy_type(nt);
3431  holder_iter = 7 & ( 1 + holder_iter ); // too much VHDL? :-(
3435  if (!type_undefined_p(holder[holder_iter]))
3436  free_type(holder[holder_iter]);
3437  holder[holder_iter]=nt;
3438  }
3439 #endif
3440  }
3441  else
3442  nt = t;
3443  }
3444  else
3445  nt = t;
3446 
3447  pips_debug(9, "Ends with type \"%s\"\n", type_to_string(nt));
3448  /* ifdebug(9) { */
3449  /* if(type_variable_p(nt)) { */
3450  /* variable nvt = type_variable(nt); */
3451  /* basic nbt = variable_basic(nvt); */
3452 
3453  /* pips_debug(9, "and basic \"%s\"\n", basic_to_string(nbt)); */
3454  /* } */
3455  /* } */
3456 
3457  if (!arrays_only)
3458  pips_assert("nt is not a typedef",
3460 
3461  // only under debug, because there is a big impact on performance
3462  ifdebug(1) pips_assert("type consistent",type_consistent_p(nt));
3463  return nt;
3464 }
3465 
3467 {
3468  return private_ultimate_type(t, false);
3469 }
3470 
3472 {
3473  return private_ultimate_type(t, true);
3474 }
3475 
3476 /************************/
3477 /* basic_concrete_types */
3478 /* */
3479 /************************/
3480 
3481 
3482 /*
3483  basic_concrete_types are types in which all typedefs are removed and
3484  consecutive array dimensions are gathered at the same level. For
3485  entities, these new types are kept in a hash table where the keys
3486  are the original entity_types. These is done for performance
3487  reasons.
3488 
3489  At first, I tried to also keep basic concrete types to
3490  computed types, however, this could lead to memory leaks or to
3491  segmentation faults depending of whether the original type was freed
3492  or not during computations. This is not the same for entity types
3493  because entities survive to the basic concrete types table. BC.
3494  */
3495 #define BCTYPES_TABLE_INIT_SIZE 10
3497 
3498 /*
3499  Init and reset functions for the basic_concrete_types table. They
3500  are currently called by pipsmake (and callgraph) before and after
3501  performing a phase on a module. This could also be done after
3502  parsing and just before closing the database, however, I feared that
3503  it would grow too much to be efficient, and I lack time to check
3504  this assumtion. BC.
3505  */
3506 
3508 {
3509  pips_assert("types_to_bctypes must be undefined", hash_table_undefined_p(entity_types_to_bctypes));
3511 }
3512 
3514 {
3515  /* First, free all basic concrete types */
3517  {
3518  free_type(t4);
3519  }
3522 }
3523 
3524 /* evaluate constant expressions appearing in dimensions of list dl
3525  *
3526  * Related function: constant_reference_to_normalized_constant_reference()
3527  */
3529 {
3530  list ndl = NIL;
3531  FOREACH(DIMENSION, d, dl) {
3532  expression l = dimension_lower(d);
3534  expression u = dimension_upper(d);
3536  list ql = dimension_qualifiers(d);
3537  list nql = gen_full_copy_list(ql);
3538  dimension nd = make_dimension(nl, nu, nql);
3539  ndl = CONS(DIMENSION, nd, ndl);
3540  }
3541  ndl = gen_nreverse(ndl);
3542  return ndl;
3543 }
3544 
3545 /**
3546  computes a new type which is the basic concrete type of the input type
3547  (this new type is *not* stored in the entity_types_to_bctypes table).
3548 
3549  @param t is a type
3550 
3551  @return : a new type in which typedefs have been expanded to reach a basic
3552  concrete type, except for struct, union, and enum because
3553  the inner types of the fields cannot be changed (they are entities).
3554 
3555 */
3557 {
3558  type nt;
3559  debug_on("RI-UTIL_DEBUG_LEVEL");
3560 
3561  // FI: to avoid cycles betwen librairies ri-util and prettyprint
3562  /* pips_debug(8, "Begin with type \"%s\"\n", */
3563  /* words_to_string(words_type(t, NIL, false))); */
3564 
3565  switch (type_tag(t))
3566  {
3567  case is_type_variable:
3568  {
3569  variable vt = type_variable(t);
3570  basic bt = variable_basic(vt);
3571  list lt = variable_dimensions(vt);
3572 
3573  /* pips_debug(9, "of basic \"%s\"and number of dimensions %d.\n", */
3574  /* basic_to_string(bt), */
3575  /* (int) gen_length(lt)); */
3576 
3577  if(basic_typedef_p(bt))
3578  {
3579  entity e = basic_typedef(bt);
3581 
3582  pips_debug(9, "typedef : %s\n", type_to_string(st));
3583  if (type_variable_p(st))
3584  {
3585  nt = st;
3589  }
3590  else if (type_void_p(st))
3591  {
3592  if (ENDP(lt))
3593  nt = st;
3594  else
3595  {
3596  nt = copy_type(t);
3597  free_type(st);
3598  }
3599  }
3600  else if (type_struct_p(st) || type_union_p(st) || type_enum_p(st))
3601  {
3603  gen_full_copy_list(lt),
3605  free_type(st);
3606  }
3607  else
3608  {
3609  free_type(st);
3610  nt = copy_type(t);
3611  }
3612  }
3613  else if(basic_pointer_p(bt))
3614  {
3616 
3617  pips_debug(9, "pointer \n");
3618  nt = make_type_variable
3620  gen_full_copy_list(lt),
3622  }
3623  else
3624  {
3625  pips_debug(9, "other variable case \n");
3626  // Normalize the dimensions which may contain unevaluated
3627  // constant expressions
3628  // nt = copy_type(t);
3629  variable v = type_variable(t);
3630  list ql = variable_qualifiers(v);
3631  list nql = gen_full_copy_list(ql);
3632  list dl = variable_dimensions(v);
3634  basic b = variable_basic(v);
3635  basic nb = copy_basic(b);
3636  variable nv = make_variable(nb, ndl, nql);
3637  nt = make_type_variable(nv);
3638  }
3639  }
3640  break;
3641 
3642  default:
3643  nt = copy_type(t);
3644  }
3645 
3646  // FI: to avoid cycles betwen librairies ri-util and prettyprint
3647  /* pips_debug(8, "Ends with type \"%s\"\n", */
3648  /* words_to_string(words_type(nt, NIL, false))); */
3649  /* ifdebug(9) */
3650  /* { */
3651  /* if(type_variable_p(nt)) */
3652  /* { */
3653  /* variable nvt = type_variable(nt); */
3654  /* basic nbt = variable_basic(nvt); */
3655  /* list nlt = variable_dimensions(nvt); */
3656  /* pips_debug(9, "of basic \"%s\"and number of dimensions %d.\n", */
3657  /* basic_to_string(nbt), */
3658  /* (int) gen_length(nlt)); */
3659  /* } */
3660  /* } */
3661 
3662  /* pips_assert("nt is not a typedef",
3663  type_variable_p(nt)?
3664  !basic_typedef_p(variable_basic(type_variable(nt))) : true); */
3665  debug_off();
3666  return nt;
3667 }
3668 
3669 /**
3670  retrieves or computes and then returns the basic concrete type of an entity
3671 
3672  @param e is the input entity
3673  @return the basic concrete type of e stored in the entity_types_to_bctypes table.
3674 
3675  @beware don't free this type, it will be freed by pipsmake when resetting the table.
3676  */
3678 {
3679  debug_on("RI-UTIL_DEBUG_LEVEL");
3680  pips_assert("types_to_bctypes must be defined", !hash_table_undefined_p(entity_types_to_bctypes));
3681  type t = entity_type(e);
3682  type bct = (type) hash_get(entity_types_to_bctypes, (void *) t);
3683 
3684  if (type_undefined_p(bct))
3685  {
3686  bct = compute_basic_concrete_type(t);
3688  }
3689  debug_off();
3690  return bct;
3691 }
3692 
3693 
3694 /**
3695  returns true when the input type successors may be pointers
3696 
3697  the input type is supposed to be a basic_concrete_type
3698  */
3700 {
3701  bool res = false;
3702 
3703  switch (type_tag(bct))
3704  {
3705  case is_type_variable :
3706  {
3707  variable v = type_variable(bct);
3708  basic b = variable_basic(v);
3709 
3710  /* If the basic is a pointer type, return true;
3711  */
3712  if(basic_pointer_p(b))
3713  {
3714  res = true;
3715  }
3716  else if (basic_derived_p(b))
3717  {
3718  list l_fields = type_fields(entity_type(basic_derived(b)));
3719  while(!res && !ENDP(l_fields))
3720  {
3721  type current_type = entity_basic_concrete_type(ENTITY(CAR(l_fields)));
3722  // we call ourselves recursively
3723  res = basic_concrete_type_leads_to_pointer_p(current_type);
3724  POP(l_fields);
3725  }
3726  }
3727  else if (!basic_typedef_p(b))
3728  {
3729  res = false;
3730  }
3731  else
3732  {
3733  pips_internal_error("unexpected typedef basic");
3734  }
3735  break;
3736  }
3737  case is_type_void:
3738  {
3739  res = false;
3740  break;
3741  }
3742  default:
3743  {
3744  pips_internal_error("case not handled yet");
3745  }
3746  } /*switch */
3747  return res;
3748 }
3749 
3750 /* A new type is allocated */
3752 {
3753  type t = expression_to_type(e);
3755  return ct;
3756 }
3757 /*******************************/
3758 /* end of basic_concrete_types */
3759 /* */
3760 /*******************************/
3761 ␌
3762 
3763 /* Is an object of type t compatible with a call? */
3765 {
3766  bool compatible_p = true;
3767 
3768  if(!type_functional_p(t)) {
3769  if(type_variable_p(t)) {
3771 
3772  if(basic_pointer_p(b))
3773  compatible_p = call_compatible_type_p(basic_pointer(b));
3774  else if(basic_typedef_p(b)) {
3775  entity te = basic_typedef(b);
3776 
3777  compatible_p = call_compatible_type_p(entity_type(te));
3778  }
3779  else
3780  compatible_p = false;
3781  }
3782  else
3783  compatible_p = false;
3784  }
3785  return compatible_p;
3786 }
3787 
3788 /* returns the type necessary to generate or check a call to an object
3789  of type t. Does not allocate a new type. Previous function could be
3790  implemented with this one. */
3792 {
3793  type compatible = t;
3794 
3795  pips_assert("t is a consistent type", type_consistent_p(t));
3796 
3797  if(!type_functional_p(t)) {
3798  if(type_variable_p(t)) {
3800 
3801  if(basic_pointer_p(b))
3802  compatible = call_compatible_type(basic_pointer(b));
3803  else if(basic_typedef_p(b)) {
3804  entity te = basic_typedef(b);
3805 
3806  compatible = call_compatible_type(entity_type(te));
3807  }
3808  else
3809  compatible = false;
3810  }
3811  else
3812  compatible = false;
3813  }
3814  pips_assert("compatible is a functional type", type_functional_p(compatible));
3815  pips_assert("compatible is a consistent type", type_consistent_p(compatible));
3816  return compatible;
3817 }
3818 
3819 /* The function called can have a functional type, or a typedef type
3820  or a pointer type to a functional type. FI: I'm not sure this is
3821  correctly implemented. I do not know if a new type is always
3822  allocated. I do not understand the semantics if ultimate is turned
3823  off. */
3824 type call_to_functional_type(call c, bool ultimate_p)
3825 {
3826  entity f = call_function(c);
3827  type ft = entity_type(f);
3828  type rt = type_undefined;
3829 
3830  if(type_functional_p(ft))
3831  rt = entity_type(f);
3832  else if(type_variable_p(ft)) {
3833  basic ftb = variable_basic(type_variable(ft));
3834  if(basic_pointer_p(ftb)) {
3835  type pt = basic_pointer(ftb);
3836  rt = ultimate_p? ultimate_type(pt) : copy_type(pt);
3837  }
3838  else if(basic_typedef_p(ftb)) {
3839  entity te = basic_typedef(ftb);
3840  type ut = ultimate_type(entity_type(te));
3841 
3842  if(type_variable_p(ut)) {
3843  basic utb = variable_basic(type_variable(ut));
3844  if(basic_pointer_p(utb)) {
3845  type pt = basic_pointer(utb);
3846  rt = ultimate_p? ultimate_type(pt): copy_type(pt);
3847  }
3848  else
3849  /* assertion will fail anyway */
3850  free_type(ut);
3851  }
3852  else /* must be a functional type */
3853  rt = ut;
3854  }
3855  else {
3856  pips_internal_error("Basic for called function unknown");
3857  }
3858  }
3859  else
3860  pips_internal_error("Type for called function unknown");
3861 
3862  pips_assert("The typedef type is functional", type_functional_p(rt));
3863 
3864  return rt;
3865 }
3866 
3868 {
3869  t = ultimate_type(t);
3870  if(type_variable_p(t))
3873  else
3874  return false;
3875 }
3876 
3878 {
3879  t = ultimate_type(t);
3880  if(type_variable_p(t))
3883  else
3884  return false;
3885 }
3886 ␌
3887 /* Recursive number of fields in a data structure...
3888  *
3889  * union and probably enum are not taken into account.
3890  *
3891  * FI: I guess enum should be added
3892  */
3894 {
3895  int n = 1;
3896  type ut = ultimate_type(t);
3897 
3898  if(type_variable_p(ut)) {
3900 
3901  if(basic_derived_p(ub)) {
3902  entity de = basic_derived(ub);
3903  type dt = entity_type(de);
3904  n = number_of_fields(dt);
3905  }
3906  }
3907  else if(type_struct_p(t)) {
3908  list el = type_struct(t);
3909  list ce = list_undefined;
3910 
3911  n = 0;
3912  for(ce = el; !ENDP(ce); POP(ce)) {
3913  entity fe = ENTITY(CAR(ce));
3914  type ft = entity_type(fe);
3915  n += number_of_fields(ft);
3916  }
3917  }
3918  else
3919  pips_internal_error("Illegal type argument");
3920 
3921  return n;
3922 }
3923 
3924 /* Same as above, but arrays in struct are taken into account */
3926 {
3927  int n = 1;
3928  type ut = ultimate_type(t);
3929 
3930  if(type_variable_p(ut)) {
3931  variable uv = type_variable(ut);
3932  basic ub = variable_basic(uv);
3933  int ne;
3934  bool ok = NumberOfElements(ub, variable_dimensions(uv), &ne);
3935 
3936  if(basic_derived_p(ub)) {
3937  entity de = basic_derived(ub);
3938  type dt = entity_type(de);
3939  n = number_of_fields(dt);
3940  }
3941 
3942  if(ok)
3943  n = n*ne;
3944  else
3945  pips_internal_error("Unexpected use of this function");
3946  }
3947  else if(type_struct_p(t)) {
3948  list el = type_struct(t);
3949  list ce = list_undefined;
3950 
3951  n = 0;
3952  for(ce = el; !ENDP(ce); POP(ce)) {
3953  entity fe = ENTITY(CAR(ce));
3954  type ft = entity_type(fe);
3955  n += number_of_items(ft);
3956  }
3957  }
3958  else
3959  pips_internal_error("Illegal type argument");
3960 
3961  return n;
3962 }
3963 ␌
3964 /* Compute the list of entities implied in the definition of a
3965  type. This list is empty for basic types such as int or char. But
3966  it increases rapidly with typedef, struct, union, bit and dimensions
3967  which can use enum elements in sizing expressions.
3968 
3969  The supporting entities are gathered in an updated list, sel,
3970  supporting entity list. If entity a depends on entity b, b must
3971  appear first in the list. Each entity should appear only once but
3972  first we keep all occurences to make sure the partial order
3973  between.entities is respected. */
3974 
3976 
3978 {
3979  ifdebug(8) {
3980  pips_debug(8, "Begin: ");
3981  print_entities(sel);
3982  fprintf(stderr, "\n\n");
3983  }
3984 
3987  {
3989  dummy d = parameter_dummy(p);
3990  if(dummy_identifier_p(d))
3992  }
3993 
3995  list tmp =NIL;
3996 
3997  FOREACH(ENTITY,e,sel)
3998  {
4000  tmp=CONS(ENTITY,e,tmp);
4001  }
4002  gen_free_list(sel);
4003  sel=gen_nreverse(tmp);
4004 
4005  ifdebug(8) {
4006  pips_debug(8, "End: ");
4007  print_entities(sel);
4008  fprintf(stderr, "\n\n");
4009  }
4010 
4011  return sel;
4012 }
4013 
4015 {
4016  set vt = set_make(set_pointer);
4017 
4019 
4020  set_free(vt);
4021 
4022  return sel;
4023 }
4024 
4026 {
4027  type t = entity_type(e);
4028  list ml = type_enum(t);
4029  list cm = list_undefined;
4030 
4031  pips_assert("type is of enum kind", type_enum_p(t));
4032 
4033  ifdebug(8) {
4034  pips_debug(8, "Begin: ");
4035  print_entities(sel);
4036  fprintf(stderr, "\n\n");
4037  }
4038 
4039  for(cm = ml; !ENDP(cm); POP(cm)) {
4040  entity m = ENTITY(CAR(cm));
4041  value v = entity_initial(m);
4042  symbolic s = value_symbolic(v);
4043 
4044  pips_assert("m is an enum member", value_symbolic_p(v));
4045 
4047  }
4048 
4049  ifdebug(8) {
4050  pips_debug(8, "End: ");
4051  print_entities(sel);
4052  fprintf(stderr, "\n\n");
4053  }
4054 
4055  return sel;
4056 }
4057 
4059 {
4060  syntax s = expression_syntax(e);
4061 
4062  ifdebug(8) {
4063  pips_debug(8, "Begin: ");
4064  print_entities(sel);
4065  fprintf(stderr, "\n\n");
4066  }
4067 
4068  if(syntax_call_p(s)) {
4069  call c = syntax_call(s);
4070  entity f = call_function(c);
4071 
4073  if(language_c_p) {
4074  /* In C, f cannot be declared directly, we need its enum */
4075  entity e_of_f = find_enum_of_member(f);
4076  //sel = CONS(ENTITY, e_of_f, sel);
4077  sel = enum_supporting_entities(sel, vt, e_of_f);
4078  sel = gen_nconc(sel, CONS(ENTITY, e_of_f, NIL));
4079  }
4080  else {
4081  /* In Fortran, symbolic constant are declared directly, but
4082  the may depend on other symbolic constants */
4083  value v = entity_initial(f);
4084  symbolic s = value_symbolic(v);
4085 
4086  //sel = CONS(ENTITY, f, sel);
4088  sel = gen_nconc(sel, CONS(ENTITY, f, NIL));
4089  }
4090  }
4091 
4092  FOREACH(EXPRESSION, se, call_arguments(c)) {
4094  }
4095  }
4096  else if(syntax_reference_p(s)) {
4097  reference r = syntax_reference(s);
4098  entity v = reference_variable(r);
4099  list inds = reference_indices(r);
4100  /* Could be guarded so as not to be added twice. Guard might be
4101  useless with because types are visited only once. */
4102  //sel = gen_nconc(sel, CONS(ENTITY, v, NIL));
4103  FOREACH(EXPRESSION, se, inds) {
4105  }
4106  sel = gen_nconc(sel, CONS(ENTITY, v, NIL));
4107  }
4108  else if(syntax_range_p(s)) {
4109  range r = syntax_range(s);
4110  expression l = range_lower(r);
4111  expression u = range_upper(r);
4112  expression i = range_increment(r);
4116  }
4117  else if(syntax_cast_p(s)) {
4118  cast c = syntax_cast(s);
4119  type t = cast_type(c);
4120  expression e = cast_expression(c);
4121  sel = recursive_type_supporting_entities(sel, vt, t);
4123  }
4124  else if(syntax_sizeofexpression_p(s)) {
4126  if(sizeofexpression_type_p(soe)) {
4127  type t = sizeofexpression_type(soe);
4128  sel = recursive_type_supporting_entities(sel, vt, t);
4129  }
4130  else {
4133  }
4134  }
4135  else if(syntax_subscript_p(s)) {
4136  subscript ss = syntax_subscript(s);
4137  expression a = subscript_array(ss);
4138  list inds = subscript_indices(ss);
4139  FOREACH(EXPRESSION, se, inds) {
4141  }
4143  }
4144  else if(syntax_application_p(s)) {
4147  list inds = application_arguments(as);
4148  FOREACH(EXPRESSION, se, inds) {
4150  }
4152  }
4153  else if(syntax_va_arg_p(s)) {
4154  list soel = syntax_va_arg(s);
4155  FOREACH(SIZEOFEXPRESSION, soe, soel) {
4156  if(sizeofexpression_type_p(soe)) {
4157  type t = sizeofexpression_type(soe);
4158  sel = recursive_type_supporting_entities(sel, vt, t);
4159  }
4160  else {
4163  }
4164  }
4165  }
4166  else {
4167  /* do nothing */
4168  ;
4169  }
4170 
4171  ifdebug(8) {
4172  pips_debug(8, "End: ");
4173  print_entities(sel);
4174  fprintf(stderr, "\n\n");
4175  }
4176 
4177  return sel;
4178 }
4179 
4180 /* C version */
4182 {
4183  return generic_constant_expression_supporting_entities(sel, vt, e, true);
4184 }
4185 
4186 /* Fortran version */
4188 {
4189  set vt = set_make(set_pointer);
4190 
4191  sel = generic_constant_expression_supporting_entities(sel, vt, e, false);
4192 
4193  set_free(vt);
4194 
4195  return sel;
4196 }
4197 
4199 {
4202  return sel;
4203 }
4204 
4205 /* C version */
4207 {
4208  return generic_symbolic_supporting_entities(sel, vt, s, true);
4209 }
4210 
4212 {
4213 
4214  ifdebug(8) {
4215  pips_debug(8, "Begin: ");
4216  print_entities(sel);
4217  fprintf(stderr, "\n\n");
4218  }
4219 
4220  if(basic_int_p(b) ||
4221  basic_float_p(b) ||
4222  basic_logical_p(b) ||
4223  basic_overloaded_p(b) ||
4224  basic_complex_p(b) ||
4225  basic_string_p(b))
4226  ;
4227  else if(basic_bit_p(b))
4228  sel = symbolic_supporting_entities(sel, vt, basic_bit(b));
4229  else if(basic_pointer_p(b))
4231  else if(basic_derived_p(b)) {
4232  //sel = CONS(ENTITY, basic_derived(b), sel);
4234  sel = gen_nconc(sel, CONS(ENTITY, basic_derived(b), NIL));
4235  }
4236  else if(basic_typedef_p(b)) {
4237  entity se = basic_typedef(b);
4238  //sel = CONS(ENTITY, se, sel);
4239  sel = recursive_type_supporting_entities(sel, vt, entity_type(se));
4240  sel = gen_nconc(sel, CONS(ENTITY, se, NIL));
4241  }
4242  else
4243  pips_internal_error("Unrecognized basic tag %d", basic_tag(b));
4244 
4245  ifdebug(8) {
4246  pips_debug(8, "End: ");
4247  print_entities(sel);
4248  fprintf(stderr, "\n\n");
4249  }
4250 
4251  return sel;
4252 }
4253 
4255 {
4256  basic b = variable_basic(v);
4257  list dims = variable_dimensions(v);
4258 
4259  ifdebug(8) {
4260  pips_debug(8, "Begin: ");
4261  print_entities(sel);
4262  fprintf(stderr, "\n");
4263  }
4264 
4265  FOREACH(DIMENSION, d, dims) {
4266  expression l = dimension_lower(d);
4267  expression u = dimension_upper(d);
4268  sel = constant_expression_supporting_entities(sel, vt, l);
4269  sel = constant_expression_supporting_entities(sel, vt, u);
4270  }
4271 
4272  sel = basic_supporting_entities(sel, vt, b);
4273 
4274  ifdebug(8) {
4275  pips_debug(8, "End: ");
4276  print_entities(sel);
4277  fprintf(stderr, "\n\n");
4278  }
4279 
4280  return sel;
4281 }
4282 
4284 {
4285 
4286  ifdebug(8) {
4287  pips_debug(8, "Begin: ");
4288  print_entities(sel);
4289  fprintf(stderr, "\n\n");
4290  }
4291 
4292  if(!set_belong_p(vt, t)) {
4293  vt = set_add_element(vt, vt, t);
4294  if(type_functional_p(t))
4296  else if(type_variable_p(t))
4298  else if(type_varargs_p(t)) {
4299  /* varargs do not depend on any other entities */
4300  //pips_user_warning("varargs case not implemented yet\n"); /* do nothing? */
4301  type vart = type_varargs(t);
4302  sel = recursive_type_supporting_entities(sel, vt, vart);
4303  ;
4304  }
4305  else if(type_void_p(t))
4306  ;
4307  else if(type_struct_p(t)) {
4308  list sse = type_struct(t);
4309 
4310  FOREACH(ENTITY, se, sse) {
4311  sel = recursive_type_supporting_entities(sel, vt, entity_type(se));
4312  }
4313  }
4314  else if(type_union_p(t)) {
4315  list use = type_union(t);
4316 
4317  FOREACH(ENTITY, se, use) {
4318  sel = recursive_type_supporting_entities(sel, vt, entity_type(se));
4319  }
4320  }
4321  else if(type_enum_p(t)) {
4322  list ese = type_enum(t);
4323 
4324  FOREACH(ENTITY, se, ese) {
4325  sel = recursive_type_supporting_entities(sel, vt, entity_type(se));
4326  }
4327  }
4328  else if(type_unknown_p(t))
4329  /* This could be considered a pips_internal_error(), at least when
4330  the internal representation is built. */
4331  ;
4332  else if(type_statement_p(t))
4333  /* This is weird, but labels also are declared*/
4334  ;
4335  else
4336  pips_internal_error("Unexpected type with tag %d", type_tag(t));
4337  }
4338  ifdebug(8) {
4339  pips_debug(8, "End: ");
4340  print_entities(sel);
4341  fprintf(stderr, "\n\n");
4342  }
4343 
4344  return sel;
4345 }
4346 
4348 {
4349  /* keep track of already visited types */
4350  set vt = set_make(set_pointer);
4351  sel = recursive_type_supporting_entities(sel, vt, t);
4352  set_free(vt);
4353  return sel;
4354 }
4355 
4356 /* Are all types necessary to define fully type "t" listed in list "pdl"?
4357  *
4358  * This function is used by the prettyprinter to decide if a derived
4359  * type can be fully defined or if its definition should wait.
4360  */
4362 {
4363  list stl = type_supporting_entities(NIL, t);
4364  bool declarable_p = true;
4365 
4366  FOREACH(ENTITY, e, stl) {
4367  if(typedef_entity_p(e)) {
4368  if(!gen_in_list_p(e, pdl)) {
4369  declarable_p = false;
4370  break;
4371  }
4372  }
4373  }
4374  return declarable_p;
4375 }
4376 ␌
4377 /* Compute the list of references implied in the definition of a
4378  type. This list is empty for basic types such as int or char. But
4379  it increases rapidly with typedef, struct, union, bit and
4380  dimensions which can use enum elements in sizing expressions.
4381 
4382  The supporting entities are gathered in an updated list, sel,
4383  supporting reference list.
4384 
4385  gen_recurse() does not follow thru entities because they are
4386  tabulated and persistant.
4387 */
4389 
4391 {
4392  // FI: to avoid cycles betwen librairies ri-util and prettyprint
4393  /* ifdebug(9) { */
4394  /* pips_debug(8, "Begin: "); */
4395  /* print_references(srl); */
4396  /* fprintf(stderr, "\n"); */
4397  /* } */
4398 
4399  MAP(PARAMETER, p,
4402 
4404 
4405  // FI: to avoid cycles betwen librairies ri-util and prettyprint
4406  /* ifdebug(9) { */
4407  /* pips_debug(8, "End: "); */
4408  /* print_references(srl); */
4409  /* fprintf(stderr, "\n"); */
4410  /* } */
4411 
4412  return srl;
4413 }
4414 
4416 {
4417  type t = entity_type(e);
4418  list ml = type_enum(t);
4419  list cm = list_undefined;
4420 
4421  pips_assert("type is of enum kind", type_enum_p(t));
4422 
4423  // FI: to avoid cycles betwen librairies ri-util and prettyprint
4424  /* ifdebug(9) { */
4425  /* pips_debug(8, "Begin: "); */
4426  /* print_references(srl); */
4427  /* fprintf(stderr, "\n"); */
4428  /* } */
4429 
4430  for(cm = ml; !ENDP(cm); POP(cm)) {
4431  entity m = ENTITY(CAR(cm));
4432  value v = entity_initial(m);
4433  symbolic s = value_symbolic(v);
4434 
4435  pips_assert("m is an enum member", value_symbolic_p(v));
4436 
4438  }
4439 
4440  // FI: to avoid cycles betwen librairies ri-util and prettyprint
4441  /* ifdebug(9) { */
4442  /* pips_debug(8, "End: "); */
4443  /* print_references(srl); */
4444  /* fprintf(stderr, "\n"); */
4445  /* } */
4446 
4447  return srl;
4448 }
4449 
4450 /* Only applicable to C expressions */
4452 {
4453  syntax s = expression_syntax(e);
4454 
4455  // FI: to avoid cycles betwen librairies ri-util and prettyprint
4456  /* ifdebug(9) { */
4457  /* pips_debug(8, "Begin: "); */
4458  /* print_references(srl); */
4459  /* fprintf(stderr, "\n"); */
4460  /* } */
4461 
4462  if(syntax_call_p(s)) {
4463  call c = syntax_call(s);
4464  entity f = call_function(c);
4465 
4467  /* We need to know if we are dealing with C or Fortran code. */
4468  /* In C, f cannot be declared directly, we need its enum */
4469  /* But in Fortran, we are done */
4470  /* FI: suggested kludge: use a Fortran incompatible type for
4471  enum member. But currently they are four byte signed integer (c89)
4472  and this Fortran INTEGER type :-( */
4473 
4474  entity e_of_f = find_enum_of_member(f);
4475  //srl = CONS(ENTITY, e_of_f, srl);
4476  srl = enum_supporting_references(srl, e_of_f);
4477  }
4478 
4479  MAP(EXPRESSION, se, {
4481  }, call_arguments(c));
4482  }
4483  else if(syntax_reference_p(s)) {
4484  reference r = syntax_reference(s);
4485  list inds = reference_indices(r);
4486  /* Could be guarded so as not to be added twice. Guard might be
4487  useless with because types are visited only once. */
4488  srl = gen_nconc(srl, CONS(REFERENCE, r, NIL));
4489  MAP(EXPRESSION, se, {
4491  }, inds);
4492  }
4493  else if(syntax_cast_p(s)) {
4494  /* Forward the inner expression */
4497  } else {
4498  /* do nothing for the time being... */
4499  ;
4500  }
4501 
4502  // FI: to avoid cycles betwen librairies ri-util and prettyprint
4503  /* ifdebug(9) { */
4504  /* pips_debug(8, "End: "); */
4505  /* print_references(srl); */
4506  /* fprintf(stderr, "\n"); */
4507  /* } */
4508 
4509  return srl;
4510 }
4511 
4513 {
4516  return srl;
4517 }
4518 
4520 {
4521 
4522  // FI: to avoid cycles betwen librairies ri-util and prettyprint
4523  /* ifdebug(9) { */
4524  /* pips_debug(8, "Begin: "); */
4525  /* print_references(srl); */
4526  /* fprintf(stderr, "\n"); */
4527  /* } */
4528 
4529  if(basic_int_p(b) ||
4530  basic_float_p(b) ||
4531  basic_logical_p(b) ||
4532  basic_overloaded_p(b) ||
4533  basic_complex_p(b) ||
4534  basic_string_p(b))
4535  ;
4536  else if(basic_bit_p(b))
4538  else if(basic_pointer_p(b))
4540  else if(basic_derived_p(b)) {
4541  //srl = CONS(ENTITY, basic_derived(b), srl);
4543  }
4544  else if(basic_typedef_p(b)) {
4545  entity se = basic_typedef(b);
4546  //srl = CONS(ENTITY, se, srl);
4548  }
4549  else
4550  pips_internal_error("Unrecognized basic tag %d", basic_tag(b));
4551 
4552  // FI: to avoid cycles betwen librairies ri-util and prettyprint
4553  /* ifdebug(9) { */
4554  /* pips_debug(8, "End: "); */
4555  /* print_references(srl); */
4556  /* fprintf(stderr, "\n"); */
4557  /* } */
4558 
4559  return srl;
4560 }
4561 
4563 {
4564  basic b = variable_basic(v);
4565  list dims = variable_dimensions(v);
4566 
4567  // FI: to avoid cycles betwen librairies ri-util and prettyprint
4568  /* ifdebug(9) { */
4569  /* pips_debug(8, "Begin: "); */
4570  /* print_references(srl); */
4571  /* fprintf(stderr, "\n"); */
4572  /* } */
4573 
4574  MAP(DIMENSION, d, {
4575  expression l = dimension_lower(d);
4576  expression u = dimension_upper(d);
4579  }, dims);
4580 
4581  srl = basic_supporting_references(srl, b);
4582 
4583  // FI: to avoid cycles betwen librairies ri-util and prettyprint
4584  /* ifdebug(9) { */
4585  /* pips_debug(8, "End: "); */
4586  /* print_references(srl); */
4587  /* fprintf(stderr, "\n"); */
4588  /* } */
4589 
4590  return srl;
4591 }
4592 
4594 {
4595  // FI: to avoid cycles betwen librairies ri-util and prettyprint
4596  /* ifdebug(9) { */
4597  /* pips_debug(8, "Begin: "); */
4598  /* print_references(srl); */
4599  /* fprintf(stderr, "\n"); */
4600  /* } */
4601 
4602  if(type_functional_p(t))
4603  ;
4604  else if(type_variable_p(t)) {
4605  /* In Fortran, dependencies are due to the dimension expressions.*/
4606  variable v = type_variable(t);
4607  list dims = variable_dimensions(v);
4608 
4609  FOREACH(DIMENSION, d, dims) {
4610  expression l = dimension_lower(d);
4611  expression u = dimension_upper(d);
4614  }
4615  }
4616  else if(type_void_p(t))
4617  ;
4618  else
4619  pips_internal_error("Unexpected Fortran type with tag %d", type_tag(t));
4620 
4621  // FI: to avoid cycles betwen librairies ri-util and prettyprint
4622  /* ifdebug(9) { */
4623  /* pips_debug(8, "End: "); */
4624  /* print_references(srl); */
4625  /* fprintf(stderr, "\n"); */
4626  /* } */
4627 
4628  return srl;
4629 }
4630 
4631 /* This is not Fortran compatible as enum members and symbolic
4632  constant appear the same but cannot be dealt with in the same
4633  way.
4634 
4635  What should be done with the tyoe unknown? Return a empty list or
4636  generate a pips_internal_error()?
4637  */
4639 {
4640  /* Do not recurse if this type has already been visited. */
4641  if(!set_belong_p(supporting_types, t)) {
4643  // FI: to avoid cycles betwen librairies ri-util and prettyprint
4644  /* ifdebug(9) { */
4645  /* pips_debug(8, "Begin: "); */
4646  /* print_references(srl); */
4647  /* fprintf(stderr, "\n"); */
4648  /* } */
4649 
4650  if(type_functional_p(t))
4652  else if(type_variable_p(t))
4654  else if(type_varargs_p(t)) {
4655  /* No references are involved in C... */
4656  //pips_user_warning("varargs case not implemented yet\n");
4657  type vt = type_varargs(t);
4658  srl = recursive_type_supporting_references(srl, vt);
4659  }
4660  else if(type_void_p(t))
4661  ;
4662  else if(type_struct_p(t)) {
4663  list sse = type_struct(t);
4664 
4665  MAP(ENTITY, se, {
4667  }, sse);
4668  }
4669  else if(type_union_p(t)) {
4670  list use = type_union(t);
4671 
4672  MAP(ENTITY, se, {
4674  }, use);
4675  }
4676  else if(type_enum_p(t)) {
4677  list ese = type_enum(t);
4678 
4679  MAP(ENTITY, se, {
4681  }, ese);
4682  }
4683  else if(type_unknown_p(t)) {
4684  pips_internal_error("unknown type left in a declaration");
4685  }
4686  else
4687  pips_internal_error("Unexpected type with tag %d", type_tag(t));
4688 
4689  // FI: to avoid cycles betwen librairies ri-util and prettyprint
4690  /* ifdebug(9) { */
4691  /* pips_debug(8, "End: "); */
4692  /* print_references(srl); */
4693  /* fprintf(stderr, "\n"); */
4694  /* } */
4695  }
4696 
4697  return srl;
4698 }
4699 
4701 {
4702  /* To avoid multiple recursion through the same type */
4706  return srl;
4707 }
4708 
4709 ␌
4710 
4711 /* Check that an effective parameter list is compatible with a
4712  function type. Or improve the function type when it is not precise
4713  as with "extern int f()". This is (a bit/partially) redundant with
4714  undeclared function detection since undeclared functions are
4715  declared "extern int f()". */
4717 {
4718  bool ok = true;
4719  type t = entity_type(f);
4720  type ct = call_compatible_type(t);
4722 
4723  pips_assert("f can be used to generate a call", call_compatible_type_p(t));
4724 
4725  if(ENDP(parms)) {
4726  if(ENDP(args))
4727  ;
4728  else {
4729  if(type_functional_p(t)) {
4730  /* Use parms to improve the type of f, probably declared f()
4731  with no type information. */
4732  /* Should be very similar to call_to_functional_type(). */
4733  list pl = NIL;
4734  MAP(EXPRESSION, e, {
4735  type et = expression_to_user_type(e);
4737  pl = gen_nconc(pl, CONS(PARAMETER, p, NIL));
4738  },
4739  args);
4741 
4745  }
4746 
4747  pips_user_warning("Type updated for function \"%s\"\n", entity_user_name(f));
4748  // FI: to avoid cycles betwen librairies ri-util and prettyprint
4749  /* ifdebug(8) { */
4750  /* text txt = c_text_entity(get_current_module_entity(), f, 0, NIL); */
4751  /* print_text(stderr, txt); */
4752  /* } */
4753  }
4754  else {
4755  /* Must be a typedef or a pointer to a function. No need to refine the type*/
4756  // FI: to avoid cycles betwen librairies ri-util and prettyprint
4757  /* ifdebug(8) { */
4758  /* text txt = c_text_entity(get_current_module_entity(), f, 0, NIL); */
4759  /* pips_debug(8, "Type not updated for function \"%s\"\n", entity_user_name(f)); */
4760  /* print_text(stderr, txt); */
4761  /* } */
4762  }
4763  }
4764  }
4765  else if(gen_length(args)!=gen_length(parms)) {
4766  /* Take care of the void case */
4767  if(gen_length(args)==0 && gen_length(parms)==1) {
4768  parameter p = PARAMETER(CAR(parms));
4769  type pt = parameter_type(p);
4770  ok = type_void_p(pt);
4771  }
4772  /* Take care of the varargs case*/
4773  else if(gen_length(parms) >= 2 && gen_length(args) > gen_length(parms)) {
4774  parameter lp = PARAMETER(CAR(gen_last(parms)));
4775  type pt = parameter_type(lp);
4776  ok = type_varargs_p(pt);
4777  }
4778  else
4779  ok = false;
4780  }
4781  else {
4782  /* Check type compatibility: find function in flint?
4783  type_equal_p() requires lots of extensions to handle C
4784  types. And you would probably need type conversion to concrete
4785  type.*/
4786  ;
4787  }
4788 
4789  return ok;
4790 }
4791 ␌
4792 static size_t generic_basic_depth(basic b, set vt);
4793 
4794 static size_t generic_type_depth(type t, set vt)
4795 {
4796  size_t d = 0;
4797  bool finished_p = false;
4798 
4799  if(!set_undefined_p(vt)) {
4800  if(set_belong_p(vt, t))
4801  finished_p = true;
4802  else
4803  set_add_element(vt, vt, t);
4804  }
4805 
4806  if(!finished_p) {
4807  if(type_variable_p(t)) {
4808  variable v = type_variable(t);
4809 
4811  }
4812  else if(type_void_p(t))
4813  d = 0;
4814  else if(type_varargs_p(t))
4815  d = 0;
4816  else if(type_struct_p(t)) {
4817  list fl = type_struct(t);
4818  d = 0;
4819  FOREACH(ENTITY, e, fl) {
4820  size_t i = generic_type_depth(entity_type(e), vt);
4821  d = d>i?d:i;
4822  }
4823  d++;
4824  }
4825  else if(type_union_p(t)) {
4826  list fl = type_union(t);
4827  d = 0;
4828  FOREACH(ENTITY, e, fl) {
4829  size_t i = generic_type_depth(entity_type(e), vt);
4830  d = d>i?d:i;
4831  }
4832  d++;
4833  }
4834  else if(type_enum_p(t))
4835  d = 0;
4836  }
4837 
4838  return d;
4839 }
4840 
4841 /* Number of steps to access the lowest leave of type t without a
4842  * recursive test. Number of dimensions for an array. One for a
4843  * struct or an union field, plus its own dimension(s). Recursive data
4844  * structures do not end up with MAX_INT as type depth. So
4845  *
4846  * A pointer to a scalar may be a pointer to an array, unless property
4847  * POINTS_TO_STRICT_POINTER_TYPES is set to true.
4848  *
4849  * The name of the function should be
4850  * non_recursive_maximal_type_depth(). It returns the maximum number
4851  * of subscript expressions usable in a points-to cell reference.
4852  *
4853  * Concrete types are not used. The depth of named types is supposedly
4854  * calculated.
4855  */
4857 {
4858  set vt = set_make(set_pointer);
4859  int depth = generic_type_depth(t, vt);
4860  set_free(vt);
4861  return depth;
4862 }
4863 
4864 /* Number of steps to access the lowest leave of type t without
4865  * dereferencing. Number of dimensions for an array. One for a struct
4866  * or an union field, plus its own dimension(s). This does not take
4867  * into account longer memory access paths due to pointers. Hence,
4868  * recursive data structures do not end up with MAX_INT as type depth.
4869  *
4870  * A pointer to a scalar may be a pointer to an array, unless property
4871  * POINTS_TO_STRICT_POINTER_TYPES is set to true.
4872  *
4873  * Concrete types are not used. The depth of named types is supposedly
4874  * calculated.
4875  *
4876  * This is the maximum number of subscripts used in a store
4877  * independent reference, a.k.a. a constant memory access path, with a
4878  * variable of type t.
4879  */
4880 size_t type_depth(type t)
4881 {
4883  return depth;
4884 }
4885 
4886 static size_t generic_basic_depth(basic b, set vt)
4887 {
4888  int d = 0;
4889 
4890  switch(basic_tag(b)) {
4891  case is_basic_int:
4892  case is_basic_float:
4893  case is_basic_logical:
4894  case is_basic_overloaded:
4895  case is_basic_complex:
4896  case is_basic_string:
4897  case is_basic_bit:
4898  break;
4899  case is_basic_pointer: {
4900  if(!set_undefined_p(vt)) {
4901  type pt = basic_pointer(b);
4902  d = generic_type_depth(pt, vt)+1;
4903  // FI: Add an implicit array dimension ?
4904  // if(!get_bool_property("POINTS_TO_STRICT_POINTER_TYPES")) d++;
4905  }
4906  else
4907  d = 0;
4908 
4909  // FI: if it is needed to add a zero subscript, this feature
4910  // should be carefully documented. It generates results in between
4911  // type_depth() and maximal_type_depth(). It may be properly
4912  // handled by the caller. It is meaningless here and damaging when
4913  // points-to references must be kept store-independent.
4914 
4915  }
4916  break;
4917  case is_basic_derived:
4918  {
4919  entity e = basic_derived(b);
4920  type t = entity_type(e);
4921  d = generic_type_depth(t, vt);
4922  break;
4923  }
4924  case is_basic_typedef:
4925  {
4926  entity e = basic_typedef(b);
4927  type t = entity_type(e);
4928 
4929  d = generic_type_depth(t, vt);
4930  break;
4931  }
4932  default:
4933  pips_internal_error("Unexpected basic tag %d", basic_tag(b));
4934  }
4935 
4936  return d;
4937 }
4938 
4939 /* Number of steps to access the lowest leave of type t. Number of
4940  * dimensions for an array. One for a struct or an union field, plus its
4941  * dimension. The difference with type_depth is that it does not stop
4942  * recursing when encountering a pointer, and that a pointer is considered
4943  * as having dimension 1. (BC)
4944  *
4945  * This is equivalent to type_depth when property
4946  * POINTS_TO_STRICT_POINTER_TYPES is set to false (FI).
4947  */
4949 {
4950  int d = 0;
4951 
4952  if(type_variable_p(t)) {
4953  variable v = type_variable(t);
4954 
4956  }
4957  else if(type_void_p(t))
4958  d = 0;
4959  else if(type_varargs_p(t))
4960  d = 0;
4961  else if(type_struct_p(t)) {
4962  list fl = type_struct(t);
4963  d = 0;
4964  FOREACH(ENTITY, e, fl) {
4965  int i = type_depth(entity_type(e));
4966  d = d>i?d:i;
4967  }
4968  d++;
4969  }
4970  else if(type_union_p(t)) {
4971  list fl = type_union(t);
4972  d = 0;
4973  FOREACH(ENTITY, e, fl) {
4974  int i = type_depth(entity_type(e));
4975  d = d>i?d:i;
4976  }
4977  d++;
4978  }
4979  else if(type_enum_p(t))
4980  d = 0;
4981 
4982  return d;
4983 }
4984 
4986 {
4987  int d = 0;
4988 
4989  switch(basic_tag(b)) {
4990  case is_basic_int:
4991  case is_basic_float:
4992  case is_basic_logical:
4993  case is_basic_overloaded:
4994  case is_basic_complex:
4995  case is_basic_string:
4996  case is_basic_bit:
4997  break;
4998  case is_basic_pointer:
4999  {
5000  d = effect_type_depth(basic_pointer(b))+1;
5001  break;
5002  }
5003  case is_basic_derived:
5004  {
5005  entity e = basic_derived(b);
5006  type t = entity_type(e);
5007  d = type_depth(t);
5008  break;
5009  }
5010  case is_basic_typedef:
5011  {
5012  entity e = basic_typedef(b);
5013  type t = entity_type(e);
5014 
5015  d = type_depth(t);
5016  break;
5017  }
5018  default:
5019  pips_internal_error("Unexpected basic tag %d", basic_tag(b));
5020  }
5021 
5022  return d;
5023 }
5024 ␌
5025 /* Compute the list of types implied in the definition of a
5026  type. This list is empty for basic types such as int or char. But
5027  it increases rapidly with typedef, struct and union. We assume that
5028  expressions in enum, bit and dimensions are not relevant.
5029 
5030  The relationship between stl, the supporting type list, and the set
5031  vt, already visited types, herited from type_supporting_entities()
5032  is not clear. It might be better to simply return vt...
5033 */
5034 static list recursive_type_supporting_types(list stl, set vt, type t);
5035 
5037 {
5038  ifdebug(8) {
5039  pips_debug(8, "Begin: ");
5040  print_entities(stl);
5041  fprintf(stderr, "\n");
5042  }
5043 
5046 
5048 
5049  ifdebug(8) {
5050  pips_debug(8, "End: ");
5051  print_entities(stl);
5052  fprintf(stderr, "\n");
5053  }
5054 
5055  return stl;
5056 }
5057 
5058 /* FI: I'm not sure this function is of any use */
5060 {
5061  set vt = set_make(set_pointer);
5062  list stl = NIL;
5063 
5065 
5066  set_free(vt);
5067 
5068  return stl;
5069 }
5070 
5072 {
5073 
5074  ifdebug(8) {
5075  pips_debug(8, "Begin: ");
5076  print_entities(stl);
5077  fprintf(stderr, "\n");
5078  }
5079 
5080  if(basic_int_p(b) ||
5081  basic_float_p(b) ||
5082  basic_logical_p(b) ||
5083  basic_overloaded_p(b) ||
5084  basic_complex_p(b) ||
5085  basic_string_p(b))
5086  ;
5087  else if(basic_bit_p(b))
5088  ;
5089  else if(basic_pointer_p(b))
5091  else if(basic_derived_p(b)) {
5092  entity de = basic_derived(b);
5093  type dt = entity_type(de);
5094  stl = CONS(ENTITY, de, stl);
5095  stl = recursive_type_supporting_types(stl, vt, dt);
5096  }
5097  else if(basic_typedef_p(b)) {
5098  entity se = basic_typedef(b);
5099  type st = entity_type(se);
5100  stl = CONS(ENTITY, se, stl);
5101  stl = recursive_type_supporting_entities(stl, vt, st);
5102  }
5103  else
5104  pips_internal_error("Unrecognized basic tag %d", basic_tag(b));
5105 
5106  ifdebug(8) {
5107  pips_debug(8, "End: ");
5108  print_entities(stl);
5109  fprintf(stderr, "\n");
5110  }
5111 
5112  return stl;
5113 }
5114 
5116 {
5117  /* The dimensions cannot contain a type declaration */
5118  basic b = variable_basic(v);
5119 
5120  ifdebug(8) {
5121  pips_debug(8, "Begin: ");
5122  print_entities(stl);
5123  fprintf(stderr, "\n");
5124  }
5125 
5126  stl = basic_supporting_types(stl, vt, b);
5127 
5128  ifdebug(8) {
5129  pips_debug(8, "End: ");
5130  print_entities(stl);
5131  fprintf(stderr, "\n");
5132  }
5133 
5134  return stl;
5135 }
5136 
5138 {
5139 
5140  ifdebug(8) {
5141  pips_debug(8, "Begin: ");
5142  print_entities(stl);
5143  fprintf(stderr, "\n");
5144  }
5145 
5146  if(!set_belong_p(vt, t)) {
5147  vt = set_add_element(vt, vt, t);
5148  if(type_functional_p(t))
5150  else if(type_variable_p(t))
5151  stl = variable_type_supporting_types(stl, vt, type_variable(t));
5152  else if(type_varargs_p(t)) {
5153  /* varargs case is self contained: no supporting type is
5154  required. */
5155  //pips_user_warning("varargs case not implemented yet\n"); /* do nothing? */
5156  type vart = type_varargs(t);
5157  stl = recursive_type_supporting_types(stl, vt, vart);
5158  ;
5159  }
5160  else if(type_void_p(t))
5161  ;
5162  else if(type_struct_p(t)) {
5163  list sse = type_struct(t);
5164 
5165  FOREACH(ENTITY, se, sse) {
5166  stl = recursive_type_supporting_types(stl, vt, entity_type(se));
5167  }
5168  }
5169  else if(type_union_p(t)) {
5170  list use = type_union(t);
5171 
5172  FOREACH(ENTITY, se, use) {
5173  stl = recursive_type_supporting_types(stl, vt, entity_type(se));
5174  }
5175  }
5176  else if(type_enum_p(t))
5177  /* Hopefully, a dummy type declaration cannot be put among enum
5178  members declarations. */
5179  ;
5180  else if(type_unknown_p(t))
5181  /* This could be considered a pips_internal_error(), at least when
5182  the internal representation is built. */
5183  ;
5184  else if(type_statement_p(t))
5185  /* This is weird, but labels also are declared*/
5186  ;
5187  else
5188  pips_internal_error("Unexpected type with tag %d", type_tag(t));
5189  }
5190  ifdebug(8) {
5191  pips_debug(8, "End: ");
5192  print_entities(stl);
5193  fprintf(stderr, "\n");
5194  }
5195 
5196  return stl;
5197 }
5198 
5199 /* Return the list of types used to define type t. The goal is to find
5200  out if a dummy data structure (struct, union or enum) is used
5201  within another one and hence does not need to be printed out by the
5202  prettyprinter. */
5204 {
5205  /* keep track of already visited types */
5206  set vt = set_make(set_pointer);
5207  list stl = NIL;
5208  stl = recursive_type_supporting_types(stl, vt, t);
5209  set_free(vt);
5210  return stl;
5211 }
5212 ␌
5214 {
5215  /* Two options: a string of n characters or an array of n char,
5216  i.e. int. */
5217  constant c = make_constant_int(n);
5218  value val = make_value_constant(c);
5219  basic b = make_basic_string(val);
5220  variable var = make_variable(b, NIL, NIL);
5221  type t = make_type_variable(var);
5222 
5223  return t;
5224 }
5225 
5226 /* Allocate a char * pointer type */
5228 {
5230  basic b = make_basic_pointer(pt);
5231  variable v = make_variable(b, NIL, NIL);
5232  type t = make_type_variable(v);
5233  return t;
5234 }
5235 
5237 {
5238  bool overloaded_p = true;
5239 
5240  FOREACH(PARAMETER, p, lparams) {
5241  type pt = parameter_type(p);
5242 
5243  if(!overloaded_type_p(pt)) {
5244  overloaded_p = false;
5245  break;
5246  }
5247  }
5248 
5249  return overloaded_p;
5250 }
5251 
5252 /* allocate a new type "pt" which includes directly "t". */
5254 {
5256 
5257  pips_assert("pt is consistent", type_consistent_p(pt));
5258 
5259  return pt;
5260 }
5261 
5262 /* returns t if t is not a pointer type, and the pointed type if t is
5263  a pointer type. Type definitions are replaced. If t is undefined,
5264  returns a type_undefined. */
5266 {
5267  type upt = type_undefined;
5268 
5269  if(!type_undefined_p(t)) {
5270  type ut = ultimate_type(t);
5271  type pt = ut;
5272 
5273  if(pointer_type_p(ut))
5275 
5276  if(!type_undefined_p(pt))
5277  upt = ultimate_type(pt);
5278  }
5279  return upt;
5280 }
5281 
5282 /* returns a copy of t if t is not a pointer type, and the pointed type if t is
5283  * a pointer type or. Type definitions are replaced. If t is undefined,
5284  * returns a type_undefined.
5285  *
5286  * A new type is always allocated.
5287  */
5289 {
5290  type upt = type_undefined;
5291 
5292  if(!type_undefined_p(t)) {
5293  type ut = ultimate_type(t);
5294  type pt = ut;
5295 
5296  if(pointer_type_p(ut))
5298  else if(array_type_p(ut)) {
5299  variable v = type_variable(t);
5300  list dl = variable_dimensions(v);
5301  basic b = variable_basic(v);
5302  if((int)gen_length(dl)==1 && unbounded_dimension_p(DIMENSION(CAR(dl)))) {
5304  }
5305  }
5306 
5307  if(!type_undefined_p(pt))
5308  upt = ultimate_type(pt);
5309  }
5310  return upt;
5311 }
5312 
5313 /* returns t if t is not a functoional type, and the returned type if t is
5314  a functional type. Type definitions are replaced. If t is undefined,
5315  returns a type_undefined. */
5317 {
5318  type urt = type_undefined;
5319 
5320  if(!type_undefined_p(t)) {
5321  type ut = ultimate_type(t);
5322  type rt = ut;
5323 
5324  if(type_functional_p(ut))
5326 
5327  if(!type_undefined_p(rt))
5328  urt = ultimate_type(rt);
5329  }
5330  return urt;
5331 }
5332 
5333 /* returns t if t is not a pointer type, and the first indirectly
5334  pointed type that is not a pointer if t is
5335  a pointer type. Type definitions are replaced. */
5337 {
5338  type ut = type_undefined;
5339 
5340  if(!type_undefined_p(t)) {
5341  ut = ultimate_type(t);
5342 
5343  while(!type_undefined_p(ut) && pointer_type_p(ut)) {
5344  ut = type_to_pointed_type(ut);
5345  }
5346  }
5347  return ut;
5348 }
5349 
5350 /**
5351  @param t is the entity_type of a basic_derived
5352  @return the list of fields of the input type
5353  */
5355 {
5356  list l=NIL;
5357 
5358  switch (type_tag(t))
5359  {
5360  case is_type_struct:
5361  l = type_struct(t);
5362  break;
5363  case is_type_union:
5364  l = type_union(t);
5365  break;
5366  case is_type_enum:
5367  l = type_enum(t);
5368  break;
5369  default:
5370  pips_assert("input type is a struct union, or enum\n",
5371  type_struct_p(t) || type_union_p(t) || type_enum_p(t) );
5372  }
5373  return l;
5374 }
5375 
5376 
5377 /**
5378  @param t is a type of kind "variable" with a basic of kind "derived"
5379  @return the list of fields of the input type
5380  */
5382 {
5383  list l = NIL;
5384  variable v = type_variable(t);
5385  basic b = variable_basic(v);
5386  if(basic_derived_p(b)) {
5387  entity est = basic_derived(b);
5388  type st = entity_type(est);
5389  l = derived_type_fields(st);
5390  }
5391  else
5392  pips_internal_error("Called with an improper argument.\n");
5393  return l;
5394 }
5395 
5396 /* To deal with fields declared in different C files.
5397  *
5398  * It is assumed that f and fl belong to the same derived type, be it
5399  * a struct, a union or an enum.
5400  */
5402 {
5403  entity nf = entity_undefined;
5404  if(entity_is_argument_p(f, fl))
5405  nf = f;
5406  else {
5407  string fn = (string) entity_user_name(f);
5408  FOREACH(ENTITY, of, fl) {
5409  string ofn = (string) entity_user_name(of);
5410  if(same_string_p(fn, ofn)) {
5411  nf = of;
5412  break;
5413  }
5414  }
5415  }
5416  return nf;
5417 }
5418 
5419 ␌
5421 {
5422  bool equal_p = qualifier_tag(q1)==qualifier_tag(q2);
5423 
5424  return equal_p;
5425 }
5426 
5428 {
5429  string s = string_undefined;
5430  switch (qualifier_tag(q)) {
5431  case is_qualifier_register:
5432  s = "register";
5433  break;
5434  case is_qualifier_const:
5435  s = "const";
5436  break;
5437  case is_qualifier_restrict:
5438  s = "restrict";
5439  break;
5440  case is_qualifier_volatile:
5441  s = "volatile";
5442  break;
5443  case is_qualifier_auto:
5444  s = "auto";
5445  break;
5446  default :
5447  pips_internal_error("unexpected tag %d", qualifier_tag(q));
5448  }
5449  return s;
5450 }
5451 
5452 /* Check that a qualifier list contains the const qualifier */
5454 {
5455  bool const_p = false;
5456  FOREACH(QUALIFIER, q, ql) {
5457  if(qualifier_const_p(q)) {
5458  const_p = true;
5459  break;
5460  }
5461  }
5462  return const_p;
5463 }
5464 
5465 /* Check that a qualifier list contains the restrict qualifier */
5467 {
5468  bool restrict_p = false;
5469  FOREACH(QUALIFIER, q, ql) {
5470  if(qualifier_restrict_p(q)) {
5471  restrict_p = true;
5472  break;
5473  }
5474  }
5475  return restrict_p;
5476 }
5477 
5478 /* Is there a const qualifier associated to type t
5479  *
5480  * FI: this should be extended in case const can be carried by a
5481  * typedef, but this first version should be enough for Molka.
5482  */
5484 {
5485  bool qualifier_p = false;
5486 
5487  if(type_variable_p(t)) {
5488  variable v = type_variable(t);
5489  list ql = variable_qualifiers(v);
5490  qualifier_p = qualifiers_const_p(ql);
5491  }
5492 
5493  return qualifier_p;
5494 }
5495 
5496 ␌
5497 /* returns the type associated to se. If se can be evaluated as n,
5498  returns the type of the nth field in the field list. If se is a
5499  reference to a field f in fl, returns the type of f.
5500 
5501  if se is an not a statically evaluable integer expression and not a
5502  field reference, returns type_undefined.
5503 
5504  If n is greater then the number of elements in fl, returns
5505  type_undefined.
5506 
5507  If f is not in fl, returns type_undefined.
5508 
5509  It might be easier for callers to raise a pips_internal_error()
5510  when the result is undefined...
5511 
5512  Does not allocate a new type.
5513 */
5515 {
5516  type ft = type_undefined;
5517 
5518  if(expression_reference_p(se)) {
5519  /* Must be a reference to a field */
5521 
5522  if(gen_in_list_p(f, fl)) {
5523  ft = entity_type(f);
5524  }
5525  else {
5526  pips_internal_error("Field f is not in field list fl.");
5527  }
5528  }
5529  else {
5530  /* Must be an integer expression */
5531  intptr_t n = 0;
5532  bool ok = expression_integer_value(se, &n);
5533 
5534  if(ok) {
5535  entity f = ENTITY(CAR(gen_nthcdr(n-1, fl)));
5536  ft = entity_type(f);
5537  }
5538  else {
5539  pips_internal_error("Unusable subscript expression for a derived type.");
5540  }
5541  }
5542 
5543  if(type_undefined_p(ft))
5544  pips_internal_error("Ill. arguments");
5545 
5546  return ft;
5547 }
5548 
5549 /* Returns the type of an object of type t subscripted by expression
5550  se.
5551 
5552  For instance if t is a struct, the type returned is the type
5553  corresponding to the se field.
5554 
5555  It is much more difficult for arrays...
5556 
5557  Do we assume that t is a ultimate type?
5558 
5559  A new type is allocated.
5560 
5561 */
5563 {
5564  type st = type_undefined;
5565 
5566  if(type_variable_p(t)) {
5567  variable v = type_variable(t);
5568  list dl = variable_dimensions(v);
5569 
5570  if(ENDP(dl)) {
5571  /* scalar case */
5572  basic b = variable_basic(v);
5573 
5574  if(basic_pointer_p(b)) {
5576  }
5577  else if(basic_derived_p(b)) {
5578  entity de = basic_derived(b);
5579  type det = entity_type(de);
5580  list fl = list_undefined;
5581 
5582  if(type_struct_p(det)) {
5583  fl = type_struct(det); // field list
5584  }
5585  else if(type_union_p(det)) {
5586  fl = type_union(det); // field list
5587  }
5588  else if(type_enum_p(det)) {
5589  /* enum cannot be subscripted */
5590  pips_internal_error("enum type cannot be subscripted.");
5591  }
5592  else {
5593  pips_internal_error("This type cannot be subscripted.");
5594  }
5596  }
5597  else {
5598  /* Other basics are incompatible with subscripts */
5599  pips_internal_error("This type cannot be subscripted");
5600  }
5601  }
5602  else {
5603  /* array case */
5604  type et = copy_type(t);
5605  variable etv = type_variable(et);
5606  // FI: skip the first dimension, which could be implemented more
5607  // efficiently by destroying only the first dimension
5608  list dl = variable_dimensions(etv);
5609  variable_dimensions(etv) =
5611  gen_full_free_list(dl);
5612  st = type_to_pointer_type(et);
5613  }
5614  }
5615  else {
5616  pips_internal_error("Type t is not a variable type.");
5617  }
5618  return st;
5619 }
5620 /* This function returns the ith dimension of a list of dimensions */
5622 {
5623  int i;
5624  pips_assert("find_ith_dimension", n > 0);
5625  for(i=1; i<n && !ENDP(dims); i++, POP(dims))
5626  ;
5627  if(i==n && !ENDP(dims))
5628  return DIMENSION(CAR(dims));
5629  return dimension_undefined;
5630 }
5631 
5633 {
5634  int d = 0;
5635 
5637  d++;
5638 
5639  return d;
5640 }
5641 
5642 /* convert a type "t" into a newly allocated array type "at" whose
5643  * elements are of type "t", unless "t" is void. Then an array of
5644  * overloaded elements is generated. The new dimension is unbounded.
5645  *
5646  * This useful when dealing with pointers that are not precisely
5647  * typed. In C you have often to assume they point towards an array
5648  * since pointer arithmetic is OK by default.
5649  *
5650  * The behavior of this function is not well defined when typedef are
5651  * used... t should be a concrete type.
5652  */
5654 {
5655  type at = type_undefined;
5656 
5657  if(type_void_p(t)) {
5658  at = MakeTypeOverloaded();
5659  }
5660  else
5661  at = copy_type(t);
5662 
5663  variable vt = type_variable(at);
5664 
5665  /* You cannot added a second unbounded dimension in C... */
5666  /* So you should change the element type... */
5667  /* But this is not compatible with points-to references. We can
5668  add 0 subscripts as much as we want for unbounded dimensions,
5669  but we cannot change *p into p[0]... This is linked to
5670  effects-util and points-to analysis, and should probably not be
5671  here in library ri-util */
5672 
5673  //list ld = variable_dimensions(vt);
5674  //dimension fd = DIMENSION(CAR(ld));
5675  //if(false && unbounded_dimension_p(fd)) {
5676  //type et = array_type_to_element_type(at);
5677  // type net = type_to_pointer_type(et);
5678  //free_basic(variable_basic(vt));
5679  //variable_basic(vt) = make_basic_pointer(et);
5680  //}
5681  //else {
5684  NIL);
5685  // Add the new dimension as first dimension... be cause an
5686  // unbounded dimension must be the first dimension.
5688  // }
5689 
5690  return at;
5691 }
5692 
5693 /* returns the type of the elements of an array type, as a newly allocated type.
5694  *
5695  * It is not clear if it should fail when the argument is not an array
5696  * type, or if an undefined type should be returned.
5697  *
5698  * The qualifiers are dropped.
5699  */
5701 {
5702  type et = type_undefined;
5703  if(type_variable_p(t)) {
5704  variable v = type_variable(t);
5705  //list dl = variable_dimensions(v);
5706  basic b = variable_basic(v);
5708  }
5709  else
5710  pips_internal_error("Ill. arg.\n");
5711  return et;
5712 }
5713 /* Allocate a new type, the sub-array type of "t". It "t" is
5714  * "int[10][20][30]", the sub-array type is "int[20][30]".
5715  *
5716  * No sharing is created between argument "t" and result "et"
5717  */
5719 {
5720  type et = type_undefined;
5721  if(array_type_p(t)) {
5722  variable v = type_variable(t);
5723  list dl = variable_dimensions(v);
5724  basic b = variable_basic(v);
5725  POP(dl);
5727  gen_full_copy_list(dl),
5728  NIL));
5729  }
5730  else
5731  pips_internal_error("Ill. arg.\n");
5732  return et;
5733 }
5734 
5735 /* Allocate a new type that is the type of an array constant. For
5736  * instance, int t[10] gives type int * to t, int t[10][20] gives type
5737  * int (*)[20]
5738  */
5740 {
5741  type et = type_undefined;
5742  if(array_type_p(t)) {
5744  et = type_to_pointer_type(sat);
5745  }
5746  else
5747  pips_internal_error("Ill. arg.\n");
5748  return et;
5749 }
5750 
5751 /* Minimal information to build a d-dimensional array type. */
5753 {
5754  list dl = NIL;
5755  int i;
5756  for(i=0; i<d;i++) {
5759  NIL);
5760  dl = CONS(DIMENSION, d, dl);
5761  }
5762  return dl;
5763 }
5764 
5766 {
5767  bool void_star_p = false;
5768  if(pointer_type_p(t))
5769  void_star_p = type_void_p(type_to_pointed_type(t));
5770  return void_star_p;
5771 }
5772 
5773 /* Beware of typedefs. */
5775 {
5776  bool char_star_p = false;
5777  if(pointer_type_p(t)) {
5778  type pt = type_to_pointed_type(t);
5779  char_star_p = char_type_p(pt);
5780  }
5781  return char_star_p;
5782 }
5783 
5784 /* Beware of typedefs. Beware of string_type_p()... Strictly
5785  * speaking, string_type_p() should not be taken into acount.
5786  */
5788 {
5789  bool char_star_p = false;
5790  if(type_functional_p(t)) {
5792  type rt = functional_result(f);
5793  char_star_p = char_star_type_p(rt) || string_type_p(rt);
5794  }
5795  return char_star_p;
5796 }
5797 
5799 {
5800  pips_assert("lt is the type of a struct", type_variable_p(lt)
5803  type st = entity_type(ste); // structure type
5804  list fl = type_struct(st); // field list
5805  return fl;
5806 }
5807 
5808 static bool dependent_basic_p(basic b);
5809 
5810 /* A type is dependent in many ways according to definitions given in
5811  * Wikipedia. Dependent types lead to many issues both theoretical and
5812  * practical. The semantics of predicate type_equal_p() should be
5813  * precised.
5814  *
5815  * Here, for practical purposes, we need to know if the storage space
5816  * required to store a value of a C type is constant and known at
5817  * compile-time, or if it depends on the environment and the store and
5818  * must be computed at run-time.
5819  *
5820  * By this definition, functional types are always constant because
5821  * functions are stored as pointer to functions in C. So in C as in
5822  * Fortran, only varying dimensions can lead to dependent types. Such
5823  * variables are called variable-length array (VLA). So this function
5824  * might be called vla_type_p().
5825  *
5826  * Some VLA are easy to implement and very convenient for the
5827  * programmer. They have been included very early in Fortran
5828  * extensions. Hence they have been handled in PIPS for a very long
5829  * time and are allocated in the STACK_AREA, the DYNAMIC_AREA and
5830  * Fortran commons being reserved for non variable-length variables.
5831  *
5832  * They were introduced in C99 but relegated to conditional feature in
5833  * C11 (I kind of remember, due to Microsoft lobbying). Because
5834  * declarations can be placed anywhere in post C99 code, the
5835  * implementation of VLA maybe costly. The dimensions must be
5836  * evaluated and then alignment and packing are performed in situ by
5837  * the gcc implementation, as well as stack management. For non-VLA
5838  * variables, gcc seems to perform a pass similar to the flatten code
5839  * pass or to the clone_statement() function and move all declarations
5840  * at the begining of the current function (alpha-renaming). So the
5841  * frame allocation is performed statically, apparently using more
5842  * space than necessary because variables with disjoint scopes are
5843  * allocated simultaneously. These implementation issues have been
5844  * explored by Nelson Lossing.
5845  *
5846  * This predicate is used by passes to check that declarations can be
5847  * moved/rescheduled (flatten_code, loop_unroll, full_loop_unroll...).
5848  */
5850 {
5851  bool dependent_p = false;
5852  if(type_variable_p(t)) {
5853  variable v = type_variable(t);
5854  list dl = variable_dimensions(v);
5855  FOREACH(DIMENSION, d, dl) {
5856  expression l = dimension_lower(d);
5857  expression u = dimension_upper(d);
5860  dependent_p = true;
5861  break;
5862  }
5863  }
5864  if(!dependent_p) {
5865  basic b = variable_basic(v);
5866  dependent_p = dependent_basic_p(b);
5867  }
5868  }
5869  return dependent_p;
5870 }
5871 
5872 static bool dependent_basic_p(basic b)
5873 {
5874  bool dependent_p = false;
5875  if(basic_typedef_p(b)) {
5876  entity te = basic_typedef(b);
5877  type t = entity_type(te);
5878  dependent_p = dependent_type_p(t);
5879  }
5880  else if(basic_derived_p(b)) {
5881  entity de = basic_derived(b);
5882  type dt = entity_type(de);
5883  list fl = NIL; // field list
5884  if(type_struct_p(dt))
5885  fl = type_struct(dt);
5886  else if(type_union_p(dt))
5887  fl = type_union(dt);
5888  FOREACH(ENTITY, fe, fl) {
5889  type ft = entity_type(fe);
5890  dependent_p = dependent_type_p(ft);
5891  if(dependent_p)
5892  break;
5893  }
5894  }
5895  return dependent_p;
5896 }
5897 
5899  entity var = reference_variable(ref);
5900  if (!const_variable_p(var)) {
5901  /* Add the dependence reference only if not already here: */
5903  *dependence_list = CONS(REFERENCE, copy_reference(ref), *dependence_list);
5904  }
5905 }
5906 
5908 {
5909  list dep = NIL;
5910  if(basic_typedef_p(b)) {
5911  entity te = basic_typedef(b);
5912  type t = entity_type(te);
5914  }
5915  else if(basic_derived_p(b)) {
5916  entity de = basic_derived(b);
5917  type dt = entity_type(de);
5918  list fl = NIL; // field list
5919  if(type_struct_p(dt))
5920  fl = type_struct(dt);
5921  else if(type_union_p(dt))
5922  fl = type_union(dt);
5923  FOREACH(ENTITY, fe, fl) {
5924  type ft = entity_type(fe);
5925  dep = dependence_of_dependent_type(ft);
5926  }
5927  }
5928  return dep;
5929 }
5930 
5931 /**
5932  * similar to dependent_type_p but return a list of reference on which
5933  * the type depend.
5934  * /param t type to analyze
5935  * /return list of reference on which the type t depend
5936  * so this list only contains elements as:
5937  * i,x,n, a[0], a[1], ...
5938  * and not n+m, 2*n, ...
5939  * the reference present in this list as to be freed by the caller
5940  * with gen_full_free_list for instance
5941  */
5943 {
5944  list dep = NIL;
5945  if(type_variable_p(t)) {
5946  variable v = type_variable(t);
5947  list dl = variable_dimensions(v);
5948 
5949  FOREACH(DIMENSION, d, dl) {
5950  expression l = dimension_lower(d);
5951  expression u = dimension_upper(d);
5952  //The test is redundant with the gen_recurse
5953  //if(!extended_expression_constant_p(l))
5955 
5956  //The test is redundant with the gen_recurse
5957  //if(!extended_expression_constant_p(u))
5959  }
5960 
5961  basic b = variable_basic(v);
5963  dep = gen_append(dep, ldb);
5964  gen_free_list(ldb);
5965  ldb=NIL;
5966  }
5967 
5968  return dep;
5969 }
5970 
5971 /*
5972  * that is all
5973  */
constant make_constant(enum constant_utype tag, void *val)
Definition: ri.c:406
basic make_basic_derived(entity _field_)
Definition: ri.c:182
parameter make_parameter(type a1, mode a2, dummy a3)
Definition: ri.c:1495
mode make_mode(enum mode_utype tag, void *val)
Definition: ri.c:1350
type make_type_variable(variable _field_)
Definition: ri.c:2715
basic make_basic(enum basic_utype tag, void *val)
Definition: ri.c:155
value make_value_constant(constant _field_)
Definition: ri.c:2841
mode make_mode_reference(void)
Definition: ri.c:1356
type copy_type(type p)
TYPE.
Definition: ri.c:2655
basic copy_basic(basic p)
BASIC.
Definition: ri.c:104
basic make_basic_overloaded(void)
Definition: ri.c:167
basic make_basic_int(intptr_t _field_)
Definition: ri.c:158
type make_type_void(list _field_)
Definition: ri.c:2727
basic make_basic_pointer(type _field_)
Definition: ri.c:179
expression copy_expression(expression p)
EXPRESSION.
Definition: ri.c:850
value make_value(enum value_utype tag, void *val)
Definition: ri.c:2832
constant make_constant_int(intptr_t _field_)
Definition: ri.c:409
dimension make_dimension(expression a1, expression a2, list a3)
Definition: ri.c:565
variable make_variable(basic a1, list a2, list a3)
Definition: ri.c:2895
basic make_basic_string(value _field_)
Definition: ri.c:173
reference copy_reference(reference p)
REFERENCE.
Definition: ri.c:2047
void free_type(type p)
Definition: ri.c:2658
dummy make_dummy_unknown(void)
Definition: ri.c:617
void free_basic(basic p)
Definition: ri.c:107
mode make_mode_value(void)
Definition: ri.c:1353
bool type_consistent_p(type p)
Definition: ri.c:2664
string type_tag_as_string(enum type_utype tag)
Definition: ri.c:2691
type make_type(enum type_utype tag, void *val)
Definition: ri.c:2706
struct paramStruct params
static reference ref
Current stmt (an integer)
Definition: adg_read_paf.c:163
static FILE * out
Definition: alias_check.c:128
bool entity_is_argument_p(entity e, cons *args)
Definition: arguments.c:150
void const char const char const int
struct _newgen_struct_type_ * type
int dummy
A dummy file, to prevent empty libraries from breaking builds.
Definition: dummy.c:41
#define gen_chunk_undefined_p(c)
Definition: genC.h:75
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
void gen_full_free_list(list l)
Definition: genClib.c:1023
void * gen_chunk_identity(gen_chunk x)
Definition: genClib.c:2812
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
Definition: genClib.c:2785
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
size_t gen_length(const list l)
Definition: list.c:150
void gen_list_and_not(list *a, const list b)
Compute A = A inter non B:
Definition: list.c:963
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
list gen_last(list l)
Return the last element of a list.
Definition: list.c:578
bool gen_in_list_p(const void *vo, const list lx)
tell whether vo belongs to lx
Definition: list.c:734
#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 CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
list gen_nthcdr(int n, const list lx)
caution: the first item is 0! was: return( (n<=0) ? l : gen_nthcdr( n-1, CDR( l ))) ; if n>gen_length...
Definition: list.c:700
#define MAPL(_map_list_cp, _code, _l)
Apply some code on the addresses of all the elements of a list.
Definition: newgen_list.h:203
void * gen_find(const void *item, const list seq, gen_filter2_func_t test, gen_extract_func_t extract)
Definition: list.c:398
list gen_append(list l1, const list l2)
Definition: list.c:471
gen_chunk gen_nth(int n, const list l)
to be used as ENTITY(gen_nth(3, l))...
Definition: list.c:710
#define list_undefined
Undefined list definition :-)
Definition: newgen_list.h:69
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
Definition: newgen_list.h:226
list gen_full_copy_list(list l)
Copy a list structure with element copy.
Definition: list.c:535
bool gen_equals(const list l0, const list l1, gen_eq_func_t equals)
compares two lists using the functor given in parameters returns true if for all n,...
Definition: list.c:192
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
void * hash_get(const hash_table htp, const void *key)
this function retrieves in the hash table pointed to by htp the couple whose key is equal to key.
Definition: hash.c:449
void hash_put(hash_table htp, const void *key, const void *val)
This functions stores a couple (key,val) in the hash table pointed to by htp.
Definition: hash.c:364
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
static list indices
Definition: icm.c:204
#define debug_on(env)
Definition: misc-local.h:157
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define pips_user_warning
Definition: misc-local.h:146
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define pips_internal_error
Definition: misc-local.h:149
#define debug_off()
Definition: misc-local.h:160
#define user_warning(fn,...)
Definition: misc-local.h:262
#define abort()
Definition: misc-local.h:53
#define pips_user_error
Definition: misc-local.h:147
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
string bool_to_string(bool)
Definition: string.c:243
@ hash_pointer
Definition: newgen_hash.h:32
#define HASH_FOREACH(key_type, k, value_type, v, ht)
Definition: newgen_hash.h:71
#define hash_table_undefined_p(h)
Definition: newgen_hash.h:50
#define hash_table_undefined
Value of an undefined hash_table.
Definition: newgen_hash.h:49
#define same_string_p(s1, s2)
#define set_undefined
Definition: newgen_set.h:48
void set_free(set)
Definition: set.c:332
bool set_belong_p(const set, const void *)
Definition: set.c:194
@ set_pointer
Definition: newgen_set.h:44
@ set_string
Definition: newgen_set.h:42
#define set_undefined_p(s)
Definition: newgen_set.h:49
set set_make(set_type)
Create an empty set of any type but hash_private.
Definition: set.c:102
set set_add_element(set, const set, const void *)
Definition: set.c:152
bool(* gen_filter2_func_t)(const void *, const void *)
Definition: newgen_types.h:110
int tag
TAG.
Definition: newgen_types.h:92
#define string_undefined
Definition: newgen_types.h:40
#define UUINT(i)
Definition: newgen_types.h:99
char * string
STRING.
Definition: newgen_types.h:39
intptr_t _int
_INT
Definition: newgen_types.h:53
#define UU
Definition: newgen_types.h:98
bool(* gen_eq_func_t)(const void *, const void *)
Definition: newgen_types.h:115
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
int f2(int off1, int off2, int w, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:1
static hash_table pl
properties are stored in this hash table (string -> property) for fast accesses.
Definition: properties.c:783
list lparams
Array bounds.
Definition: reindexing.c:111
#define DEFAULT_LOGICAL_TYPE_SIZE
#define DEFAULT_SIGNED_TYPE_SIZE
#define DBLE_GENERIC_CONVERSION_NAME
#define DEFAULT_LONG_LONG_INTEGER_TYPE_SIZE
#define ENTITY_ASSIGN_P(e)
#define DCMPLX_GENERIC_CONVERSION_NAME
#define ENTITY_COMMA_P(e)
#define ENTITY_DEREFERENCING_P(e)
#define DEFAULT_LONGDOUBLECOMPLEX_TYPE_SIZE
#define DEFAULT_INTEGER_TYPE_SIZE
#define DEFAULT_REAL_TYPE_SIZE
The standard C integer types are represented as follow char = 1 short_int = 2 int = 4 long_int = 6 lo...
#define ENTITY_POINT_TO_P(e)
#define DEFAULT_COMPLEX_TYPE_SIZE
#define ENTITY_BRACE_INTRINSIC_P(e)
C initialization expression.
#define DEFAULT_DOUBLECOMPLEX_TYPE_SIZE
#define DEFAULT_UNSIGNED_TYPE_SIZE
#define ENTITY_CONDITIONAL_P(e)
#define DEFAULT_LONG_INTEGER_TYPE_SIZE
#define DEFAULT_QUADPRECISION_TYPE_SIZE
#define DEFAULT_CHARACTER_TYPE_SIZE
Default type sizes.
#define CMPLX_GENERIC_CONVERSION_NAME
#define ENTITY_FIELD_P(e)
C data structure and pointer management.
#define ENTITY_MINUS_C_P(e)
#define INT_GENERIC_CONVERSION_NAME
generic conversion names.
#define DEFAULT_POINTER_TYPE_SIZE
#define ENTITY_ADDRESS_OF_P(e)
#define REAL_GENERIC_CONVERSION_NAME
#define DEFAULT_DOUBLEPRECISION_TYPE_SIZE
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487
bool entity_struct_p(entity e)
Is entity e the entity corresponding to a struct declaration?
Definition: entity.c:1002
bool same_entity_p(entity e1, entity e2)
predicates on entities
Definition: entity.c:1321
bool arithmetic_intrinsic_p(entity e)
true if e is an arithmetic instrinsic
Definition: entity.c:1702
bool entity_enum_p(entity e)
Definition: entity.c:968
bool typedef_entity_p(entity e)
Definition: entity.c:1902
basic entity_basic(entity e)
return the basic associated to entity e if it's a function/variable/constant basic_undefined otherwis...
Definition: entity.c:1380
void print_entities(list l)
Definition: entity.c:167
entity find_enum_of_member(entity m)
Definition: entity.c:2713
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
Definition: entity.c:1292
bool entity_union_p(entity e)
Is entity e an entity representing the union declaration?
Definition: entity.c:1038
value EvalExpression(expression e)
Evaluate statically an expression.
Definition: eval.c:108
bool expression_integer_value(expression e, intptr_t *pval)
Definition: eval.c:792
expression normalize_integer_constant_expression(expression e)
Allocate a new expression equivalent to e, but constant expressions are evaluated.
Definition: eval.c:1112
expression make_unbounded_expression()
Definition: expression.c:4339
bool expression_equal_p(expression e1, expression e2)
Syntactic equality e1==e2.
Definition: expression.c:1347
expression int_to_expression(_int i)
transform an int into an expression and generate the corresponding entity if necessary; it is not cle...
Definition: expression.c:1188
bool reference_equal_p(reference r1, reference r2)
Definition: expression.c:1500
bool unbounded_dimension_p(dimension dim)
bool unbounded_dimension_p(dim) input : a dimension of an array entity.
Definition: expression.c:1130
bool expression_reference_p(expression e)
Test if an expression is a reference.
Definition: expression.c:528
reference expression_reference(expression e)
Short cut, meaningful only if expression_reference_p(e) holds.
Definition: expression.c:1832
bool extended_expression_constant_p(expression exp)
Returns true if the value of the expression does not depend syntactically on the current store.
Definition: expression.c:2461
type ultimate_array_type(type t)
Definition: type.c:3471
basic basic_of_expressions(list expressions, bool skip_overloaded)
Definition: type.c:2040
bool array_pointer_string_type_equal_p(type t1, type t2)
Assume that a pointer to type x is equal to a 1-D array of x.
Definition: type.c:658
bool type_void_star_p(type t)
Definition: type.c:5765
basic simple_basic_dup(basic b)
Definition: type.c:2735
list type_fields(type t)
Definition: type.c:3073
int number_of_items(type t)
Same as above, but arrays in struct are taken into account.
Definition: type.c:3925
bool array_type_p(type t)
Definition: type.c:2942
type make_standard_long_integer_type(type t)
Definition: type.c:3309
bool type_fundamental_basic_p(type t)
Definition: type.c:2930
list derived_type_fields(type t)
Definition: type.c:5354
size_t maximal_type_depth(type t)
Number of steps to access the lowest leave of type t without a recursive test.
Definition: type.c:4856
static list recursive_type_supporting_references(list srl, type t)
Compute the list of references implied in the definition of a type.
Definition: type.c:4638
bool qualifiers_const_p(list ql)
Check that a qualifier list contains the const qualifier.
Definition: type.c:5453
bool qualifiers_equal_p(list dims1, list dims2)
Definition: type.c:758
bool qualifiers_restrict_p(list ql)
Check that a qualifier list contains the restrict qualifier.
Definition: type.c:5466
list symbolic_supporting_references(list srl, symbolic s)
Definition: type.c:4512
bool type_with_const_qualifier_p(type t)
Is there a const qualifier associated to type t.
Definition: type.c:5483
type MakeIntegerResult()
Definition: type.c:276
bool type_union_variable_p(type t)
Definition: type.c:3877
basic MakeBasicOverloaded()
bool same_type_name_p(const type t0, const type t1) {
Definition: type.c:77
static bool generic_type_equal_p(type t1, type t2, bool strict_p, bool qualifier_p, hash_table structural_table)
Warning: the lengths of string basics are not checked!!! string_type_size() could be used but it is p...
Definition: type.c:483
parameter MakeDoubleprecisionParameter()
Definition: type.c:209
basic expression_basic(expression expr)
Definition: type.c:1115
int string_type_size(basic b)
Definition: type.c:1047
static basic basic_and_indices_to_basic(basic b, list indices, bool ultimate_p)
BEGIN_EOLE.
Definition: type.c:1209
list derived_type_to_fields(type t)
Definition: type.c:5381
bool generic_parameter_equal_p(parameter p1, parameter p2, bool strict_p, bool qualifier_p, hash_table structural_table)
Definition: type.c:1016
type call_to_type(call c)
Definition: type.c:2313
list constant_expression_supporting_references(list srl, expression e)
Only applicable to C expressions.
Definition: type.c:4451
parameter MakeOverloadedParameter()
Definition: type.c:167
type expression_to_type(expression exp)
For an array declared as int a[10][20], the type returned for a[i] is int [20].
Definition: type.c:2486
type make_scalar_overloaded_type()
Definition: type.c:726
basic basic_of_any_expression(expression exp, bool apply_p)
Definition: type.c:1364
list dimensions_to_normalized_dimensions(list dl)
evaluate constant expressions appearing in dimensions of list dl
Definition: type.c:3528
static size_t generic_basic_depth(basic b, set vt)
Definition: type.c:4886
bool signed_type_p(type t)
Definition: type.c:2800
static list recursive_type_supporting_types(list stl, set vt, type t)
Compute the list of types implied in the definition of a type.
Definition: type.c:5137
bool char_star_constant_function_type_p(type t)
Beware of typedefs.
Definition: type.c:5787
type array_type_to_pointer_type(type t)
Allocate a new type that is the type of an array constant.
Definition: type.c:5739
dimension FindIthDimension(entity e, int i)
Definition: type.c:1180
type MakeTypeOverloaded()
Definition: type.c:107
int variable_dimension_number(variable v)
Definition: type.c:5632
bool type_pointer_on_struct_variable_p(type t)
Definition: type.c:2960
list ldimensions_dup(list l)
Definition: type.c:1166
bool unsigned_type_p(type t)
Predicates on types.
Definition: type.c:2821
type subscripted_type_to_type(type t, expression se)
Returns the type of an object of type t subscripted by expression se.
Definition: type.c:5562
parameter MakeDoublecomplexParameter()
Definition: type.c:229
entity find_field_in_field_list(entity f, list fl)
To deal with fields declared in different C files.
Definition: type.c:5401
parameter MakeRealParameter()
Definition: type.c:204
list recursive_functional_type_supporting_entities(list sel, set vt, functional f)
Definition: type.c:3977
bool basic_equal_p(basic b1, basic b2)
Definition: type.c:927
int effect_basic_depth(basic b)
Definition: type.c:4985
type expression_to_uncasted_type(expression exp)
If the expression is casted, return its type before cast.
Definition: type.c:2620
list fortran_type_supporting_entities(list srl, type t)
Definition: type.c:4593
bool concrete_array_pointer_type_equal_p(type t1, type t2)
Same as above, but resolve typedefs first.
Definition: type.c:700
type intrinsic_call_to_type(call c)
END_EOLE.
Definition: type.c:2080
type type_to_array_type(type t)
convert a type "t" into a newly allocated array type "at" whose elements are of type "t",...
Definition: type.c:5653
parameter MakeUnsignedIntegerParameter()
Definition: type.c:194
bool dependent_type_p(type t)
A type is dependent in many ways according to definitions given in Wikipedia.
Definition: type.c:5849
void entity_basic_concrete_types_init()
Definition: type.c:3507
bool derived_type_p(type t)
Returns true if t is of type struct, union or enum.
Definition: type.c:3104
type MakeDoubleprecisionResult()
Definition: type.c:296
bool area_equal_p(area a1, area a2)
Definition: type.c:733
basic basic_of_reference(reference r)
Retrieves the basic of a reference in a newly allocated basic object.
Definition: type.c:1459
bool standard_long_integer_type_p(type t)
Used to encode the long keyword in the parser.
Definition: type.c:3227
type MakeVoidPointerResult()
Definition: type.c:271
type MakeUnsignedIntegerResult()
Definition: type.c:265
bool long_type_p(type t)
Definition: type.c:2831
list dependence_of_dependent_type(type t)
similar to dependent_type_p but return a list of reference on which the type depend.
Definition: type.c:5942
type MakeAnyScalarResult(tag t, _int size)
Definition: type.c:337
dimension find_ith_dimension(list dims, int n)
This function returns the ith dimension of a list of dimensions.
Definition: type.c:5621
list struct_type_to_fields(type lt)
Definition: type.c:5798
bool qualifier_equal_p(qualifier q1, qualifier q2)
Definition: type.c:5420
type MakeRealResult()
Definition: type.c:291
bool logical_type_p(type t)
Definition: type.c:2865
static type private_ultimate_type(type t, bool arrays_only)
FI: there are different notions of "ultimate" types in C.
Definition: type.c:3370
type expression_to_concrete_type(expression e)
A new type is allocated.
Definition: type.c:3751
parameter MakeLongIntegerParameter()
Definition: type.c:189
bool generic_basic_equal_p(basic b1, basic b2, bool strict_p, bool qualifier_p, hash_table structural_table)
Definition: type.c:824
bool same_basic_p(basic b1, basic b2)
check if two basics are similar.
Definition: type.c:969
list make_unbounded_dimensions(int d)
Minimal information to build a d-dimensional array type.
Definition: type.c:5752
bool basic_type_p(type t)
Safer than the other implementation? bool pointer_type_p(type t) { bool is_pointer = false;.
Definition: type.c:2912
static list recursive_functional_type_supporting_types(list stl, set vt, functional f)
Definition: type.c:5036
bool typedef_type_p(type t)
Returns true if t is a typedefED type.
Definition: type.c:3189
bool type_equal_up_to_qualifiers_p(type t1, type t2)
Definition: type.c:552
bool char_type_p(type t)
return true whether ‘t’ is a char or an unsigned char
Definition: type.c:2877
bool type_equal_p(type t1, type t2)
Definition: type.c:547
bool variable_equal_p(variable v1, variable v2)
Definition: type.c:819
parameter MakeCharacterParameter()
Definition: type.c:239
type make_standard_integer_type(type t, int size)
Definition: type.c:3196
basic basic_of_external(call c)
basic basic_of_external(call c): returns the basic of the result given by the call to an external fun...
Definition: type.c:1509
type reference_to_type(reference ref)
Definition: type.c:2354
parameter MakeLongDoublecomplexParameter()
MB.
Definition: type.c:234
parameter MakeAnyScalarParameter(tag t, _int size)
For Fortran.
Definition: type.c:251
bool ultimate_type_equal_p(type t1, type t2)
Definition: type.c:563
list generic_constant_expression_supporting_entities(list sel, set vt, expression e, bool language_c_p)
Definition: type.c:4058
bool same_type_p(type t1, type t2)
Type equality and equivalence.
Definition: type.c:409
type MakeTypeStatement()
Definition: type.c:92
#define BCTYPES_TABLE_INIT_SIZE
basic_concrete_types
Definition: type.c:3495
bool type_equal_up_to_typedefs_and_qualifiers_p(type t1, type t2)
Definition: type.c:557
bool string_type_p(type t)
Definition: type.c:2854
bool dimension_equal_p(dimension d1, dimension d2)
Definition: type.c:747
bool generic_variable_equal_p(variable v1, variable v2, bool strict_p, bool qualifier_p, hash_table structural_table)
Definition: type.c:762
type call_to_functional_type(call c, bool ultimate_p)
The function called can have a functional type, or a typedef type or a pointer type to a functional t...
Definition: type.c:3824
bool scalar_integer_type_p(type t)
Definition: type.c:3276
bool array_of_derived_type_p(type t)
Definition: type.c:3109
string safe_type_to_string(const type t)
Definition: type.c:59
bool declarable_type_p(type t, list pdl)
Are all types necessary to define fully type "t" listed in list "pdl"?
Definition: type.c:4361
list constant_expression_supporting_entities(list sel, set vt, expression e)
C version.
Definition: type.c:4181
type type_to_pointed_type(type t)
returns t if t is not a pointer type, and the pointed type if t is a pointer type.
Definition: type.c:5265
basic some_basic_of_any_expression(expression exp, bool apply_p, bool ultimate_p)
basic basic_of_any_expression(expression exp, bool apply_p): Makes a basic of the same basic as the e...
Definition: type.c:1258
parameter MakeIntegerParameter()
Definition: type.c:184
type MakeCharacterResult()
Definition: type.c:328
static set supporting_types
Compute the list of entities implied in the definition of a type.
Definition: type.c:3975
void entity_basic_concrete_types_reset()
Definition: type.c:3513
parameter MakeLogicalParameter()
Definition: type.c:219
static type subscripted_field_list_to_type(list fl, expression se)
returns the type associated to se.
Definition: type.c:5514
list enum_supporting_entities(list sel, set vt, entity e)
Definition: type.c:4025
list basic_supporting_entities(list sel, set vt, basic b)
Definition: type.c:4211
bool functional_equal_p(functional f1, functional f2)
Definition: type.c:1011
type array_type_to_sub_array_type(type t)
Allocate a new type, the sub-array type of "t".
Definition: type.c:5718
type call_compatible_type(type t)
returns the type necessary to generate or check a call to an object of type t.
Definition: type.c:3791
type pointed_type(type t)
returns the type pointed by the input type if it is a pointer or an array of pointers
Definition: type.c:3035
type make_scalar_char_pointer_type()
Allocate a char * pointer type.
Definition: type.c:5227
basic basic_union(expression exp1, expression exp2)
basic basic_union(expression exp1 exp2): returns the basic of the expression which has the most globa...
Definition: type.c:1792
type array_type_projection(type t)
T is assumed to be an array type.
Definition: type.c:596
type type_to_returned_type(type t)
returns t if t is not a functoional type, and the returned type if t is a functional type.
Definition: type.c:5316
parameter MakeLongLongIntegerParameter()
MB.
Definition: type.c:199
bool char_star_type_p(type t)
Beware of typedefs.
Definition: type.c:5774
type type_to_final_pointed_type(type t)
returns t if t is not a pointer type, and the first indirectly pointed type that is not a pointer if ...
Definition: type.c:5336
bool is_inferior_basic(basic b1, basic b2)
bool is_inferior_basic(basic1, basic2) return true if basic1 is less complex than basic2 ex: int is l...
Definition: type.c:2687
type entity_basic_concrete_type(entity e)
retrieves or computes and then returns the basic concrete type of an entity
Definition: type.c:3677
basic basic_of_any_reference(reference r, bool apply_p, bool ultimate_p)
Retrieves the basic of a reference in a newly allocated basic object.
Definition: type.c:1395
string type_to_string(const type t)
type.c
Definition: type.c:51
mode MakeModeReference()
Definition: type.c:82
bool fixed_length_array_type_p(type t)
Definition: type.c:2987
list generic_symbolic_supporting_entities(list sel, set vt, symbolic s, bool language_c_p)
Definition: type.c:4198
int number_of_fields(type t)
Recursive number of fields in a data structure...
Definition: type.c:3893
type MakeLogicalResult()
Definition: type.c:306
list symbolic_supporting_entities(list sel, set vt, symbolic s)
C version.
Definition: type.c:4206
type make_char_array_type(int n)
Definition: type.c:5213
type array_type_to_element_type(type t)
returns the type of the elements of an array type, as a newly allocated type.
Definition: type.c:5700
string qualifier_to_string(qualifier q)
Definition: type.c:5427
bool variable_length_array_type_p(type t)
Is this equivalent to dependent_type_p()?
Definition: type.c:2972
type MakeTypeArray(basic b, cons *ld)
functions on types
Definition: type.c:162
bool dimensions_equal_p(list dims1, list dims2)
Definition: type.c:754
static list dependence_of_dependent_basic(basic b)
Definition: type.c:5907
bool pointer_type_p(type t)
Check for scalar pointers.
Definition: type.c:2993
list enum_supporting_references(list srl, entity e)
Definition: type.c:4415
bool concrete_type_equal_p(type t1, type t2)
Expand typedefs before the type comparison.
Definition: type.c:571
type MakeLongDoublecomplexResult()
MB.
Definition: type.c:322
static bool generic_field_list_equal_p(list fl1, list fl2, bool strict_p, bool qualifier_p, hash_table structural_table)
This function is only used for structural type equality.
Definition: type.c:419
basic basic_of_constant(call c)
basic basic_of_constant(call c): returns the basic of the call to a constant.
Definition: type.c:1763
bool mode_equal_p(mode m1, mode m2)
Definition: type.c:1035
type MakeQuadprecisionResult()
MB.
Definition: type.c:301
bool basic_concrete_type_leads_to_pointer_p(type bct)
returns true when the input type successors may be pointers
Definition: type.c:3699
list type_supporting_types(type t)
Return the list of types used to define type t.
Definition: type.c:5203
type ultimate_type(type t)
Definition: type.c:3466
bool union_type_p(type t)
Returns true if t is of type derived and if the derived type is a union.
Definition: type.c:3151
int basic_type_size(basic b)
See also SizeOfElements()
Definition: type.c:1074
static bool generic_field_list_names_equal_p(list fl1, list fl2)
In case you are not protected against recursivity, check field names only.
Definition: type.c:435
bool array_element_type_p(type at, type et)
is "et" the type of an element of an array of type "at"?
Definition: type.c:684
parameter MakeVoidPointerParameter()
Definition: type.c:178
type MakeOverloadedResult()
this function creates a default fortran operator result, i.e.
Definition: type.c:261
bool enum_type_p(type t)
Returns true if t is of type derived and if the derived type is a enum.
Definition: type.c:3172
bool integer_type_p(type t)
Definition: type.c:3298
list recursive_type_supporting_entities(list sel, set vt, type t)
Definition: type.c:4283
list type_supporting_references(list srl, type t)
Definition: type.c:4700
bool check_C_function_type(entity f, list args)
Check that an effective parameter list is compatible with a function type.
Definition: type.c:4716
list functional_type_supporting_references(list srl, functional f)
Definition: type.c:4390
type C_type_to_pointed_type(type t)
returns a copy of t if t is not a pointer type, and the pointed type if t is a pointer type or.
Definition: type.c:5288
bool generic_functional_equal_p(functional f1, functional f2, bool strict_p, bool qualifier_p, hash_table structural_table)
Definition: type.c:983
bool default_complex_type_p(type t)
Definition: type.c:3246
bool float_type_p(type t)
Definition: type.c:3263
bool bit_type_p(type t)
Definition: type.c:2843
type make_scalar_integer_type(_int n)
Definition: type.c:712
mode MakeModeValue()
Definition: type.c:87
bool scalar_type_p(type t)
Definition: type.c:2955
bool overloaded_type_p(type t)
Returns true if t is a variable type with a basic overloaded.
Definition: type.c:2666
type MakeLongIntegerResult()
MB.
Definition: type.c:281
list variable_type_supporting_entities(list sel, set vt, variable v)
Definition: type.c:4254
type MakeDoublecomplexResult()
Definition: type.c:316
basic basic_maximum(basic fb1, basic fb2)
Definition: type.c:1816
bool type_structurally_equal_p(type t1, type t2)
Type t1 and t2 are equal if their basic concrete components are equal.
Definition: type.c:586
list basic_supporting_references(list srl, basic b)
Definition: type.c:4519
unsigned int array_type_dimension(type t)
Definition: type.c:2947
parameter MakePointerParameter()
Definition: type.c:173
bool compatible_basic_p(basic b1, basic b2)
check if two basics are similar.
Definition: type.c:978
type MakeComplexResult()
Definition: type.c:311
list functional_type_supporting_types(functional f)
FI: I'm not sure this function is of any use.
Definition: type.c:5059
type MakeTypeVoid()
Definition: type.c:102
basic basic_of_expression(expression exp)
basic basic_of_expression(expression exp): Makes a basic of the same basic as the expression "exp".
Definition: type.c:1383
list fortran_constant_expression_supporting_entities(list sel, expression e)
Fortran version.
Definition: type.c:4187
bool FILE_star_type_p(type t)
Definition: type.c:3046
basic basic_of_intrinsic(call c, bool apply_p, bool ultimate_p)
basic basic_of_intrinsic(call c): returns the basic of the result given by call to an intrinsic funct...
Definition: type.c:1555
bool type_struct_variable_p(type t)
Definition: type.c:3867
bool C_pointer_type_p(type t)
Returns OK for "char[]" as well as for "char *".
Definition: type.c:3011
type MakeTypeUnknown()
Definition: type.c:97
static list basic_supporting_types(list stl, set vt, basic b)
Definition: type.c:5071
parameter MakeComplexParameter()
Definition: type.c:224
bool struct_type_p(type t)
Returns true if t is of type derived and if the derived type is a struct.
Definition: type.c:3121
basic basic_of_call(call c, bool apply_p, bool ultimate_p)
basic basic_of_call(call c): returns the basic of the result given by the call "c".
Definition: type.c:1469
size_t type_depth(type t)
Number of steps to access the lowest leave of type t without dereferencing.
Definition: type.c:4880
list type_supporting_entities(list sel, type t)
Definition: type.c:4347
int effect_type_depth(type t)
Number of steps to access the lowest leave of type t.
Definition: type.c:4948
bool array_pointer_type_equal_p(type t1, type t2)
assume that a pointer to type x is equal to a 1-D array of x
Definition: type.c:609
static bool compare_basic_p(basic b1, basic b2, bool same_p)
Used to implement the next two functions.
Definition: type.c:933
bool array_of_struct_type_p(type t)
Definition: type.c:3133
type MakeLongLongIntegerResult()
MB.
Definition: type.c:286
list variable_type_supporting_references(list srl, variable v)
Definition: type.c:4562
static bool dependent_basic_p(basic b)
Definition: type.c:5872
type make_scalar_complex_type(_int n)
Definition: type.c:719
type type_to_pointer_type(type t)
allocate a new type "pt" which includes directly "t".
Definition: type.c:5253
basic basic_ultimate(basic b)
get the ultimate basic from a basic typedef
Definition: type.c:1806
static size_t generic_type_depth(type t, set vt)
Definition: type.c:4794
bool parameter_equal_p(parameter p1, parameter p2)
Definition: type.c:1030
type MakeTypeVariable(basic b, cons *ld)
BEGIN_EOLE.
Definition: type.c:116
static list variable_type_supporting_types(list stl, set vt, variable v)
Definition: type.c:5115
bool overloaded_parameters_p(list lparams)
Definition: type.c:5236
dimension dimension_dup(dimension d)
Definition: type.c:1159
entity basic_to_generic_conversion(basic b)
returns the corresponding generic conversion entity, if any.
Definition: type.c:2758
list functional_type_supporting_entities(list sel, functional f)
Definition: type.c:4014
static hash_table entity_types_to_bctypes
Definition: type.c:3496
basic MakeBasic(int the_tag)
END_EOLE.
Definition: type.c:128
bool call_compatible_type_p(type t)
end of basic_concrete_types
Definition: type.c:3764
type expression_to_user_type(expression e)
Preserve typedef'ed types when possible.
Definition: type.c:2645
type compute_basic_concrete_type(type t)
computes a new type which is the basic concrete type of the input type (this new type is not stored i...
Definition: type.c:3556
static void reference_dependence_variable_check_and_add(reference ref, list *dependence_list)
Definition: type.c:5898
parameter MakeQuadprecisionParameter()
MB.
Definition: type.c:214
bool unsigned_basic_p(basic b)
Definition: type.c:2812
bool array_of_pointers_type_p(type t)
Definition: type.c:3025
bool const_variable_p(entity)
Definition: variable.c:1687
bool NumberOfElements(basic, list, int *)
Definition: size.c:403
_int SizeOfElements(basic)
This function returns the length in bytes of the Fortran or C type represented by a basic,...
Definition: size.c:297
bool symbolic_constant_entity_p(entity)
BEGIN_EOLE.
Definition: variable.c:83
#define type_functional_p(x)
Definition: ri.h:2950
#define value_tag(x)
Definition: ri.h:3064
#define type_enum_p(x)
Definition: ri.h:2968
#define dummy_identifier(x)
Definition: ri.h:1033
@ is_basic_derived
Definition: ri.h:579
@ is_basic_string
Definition: ri.h:576
@ is_basic_float
Definition: ri.h:572
@ is_basic_bit
Definition: ri.h:577
@ is_basic_pointer
Definition: ri.h:578
@ is_basic_overloaded
Definition: ri.h:574
@ is_basic_int
Definition: ri.h:571
@ is_basic_logical
Definition: ri.h:573
@ is_basic_typedef
Definition: ri.h:580
@ is_basic_complex
Definition: ri.h:575
#define type_struct(x)
Definition: ri.h:2964
#define basic_pointer(x)
Definition: ri.h:637
#define qualifier_tag(x)
Definition: ri.h:2175
#define syntax_reference_p(x)
Definition: ri.h:2728
#define qualifier_const_p(x)
Definition: ri.h:2176
#define type_struct_p(x)
Definition: ri.h:2962
#define functional_result(x)
Definition: ri.h:1444
#define REFERENCE(x)
REFERENCE.
Definition: ri.h:2296
#define parameter_dummy(x)
Definition: ri.h:1823
#define basic_complex_p(x)
Definition: ri.h:626
#define parameter_type(x)
Definition: ri.h:1819
#define area_size(x)
Definition: ri.h:544
#define value_constant(x)
Definition: ri.h:3073
#define basic_int_p(x)
Definition: ri.h:614
#define syntax_reference(x)
Definition: ri.h:2730
#define type_unknown_p(x)
Definition: ri.h:2956
#define syntax_tag(x)
Definition: ri.h:2727
#define call_function(x)
Definition: ri.h:709
#define QUALIFIER(x)
QUALIFIER.
Definition: ri.h:2106
#define reference_variable(x)
Definition: ri.h:2326
#define basic_derived(x)
Definition: ri.h:640
#define basic_typedef_p(x)
Definition: ri.h:641
#define SIZEOFEXPRESSION(x)
SIZEOFEXPRESSION.
Definition: ri.h:2364
#define basic_int(x)
Definition: ri.h:616
#define sizeofexpression_type(x)
Definition: ri.h:2406
#define range_upper(x)
Definition: ri.h:2290
#define type_tag(x)
Definition: ri.h:2940
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define constant_int(x)
Definition: ri.h:850
#define syntax_call_p(x)
Definition: ri.h:2734
#define sizeofexpression_expression(x)
Definition: ri.h:2409
#define syntax_cast(x)
Definition: ri.h:2739
#define type_functional(x)
Definition: ri.h:2952
#define syntax_application(x)
Definition: ri.h:2748
#define parameter_undefined
Definition: ri.h:1794
@ is_mode_reference
Definition: ri.h:1676
@ is_mode_value
Definition: ri.h:1675
#define dimension_lower(x)
Definition: ri.h:980
#define syntax_va_arg(x)
Definition: ri.h:2751
#define basic_tag(x)
Definition: ri.h:613
#define parameter_mode(x)
Definition: ri.h:1821
@ is_constant_int
Definition: ri.h:817
#define type_variable(x)
Definition: ri.h:2949
#define basic_pointer_p(x)
Definition: ri.h:635
#define basic_derived_p(x)
Definition: ri.h:638
#define syntax_va_arg_p(x)
Definition: ri.h:2749
#define type_statement_p(x)
Definition: ri.h:2941
#define type_union_p(x)
Definition: ri.h:2965
@ is_value_intrinsic
Definition: ri.h:3034
@ is_value_unknown
Definition: ri.h:3035
@ is_value_constant
Definition: ri.h:3033
@ is_value_code
Definition: ri.h:3031
@ is_value_symbolic
Definition: ri.h:3032
#define syntax_sizeofexpression_p(x)
Definition: ri.h:2740
#define syntax_range(x)
Definition: ri.h:2733
@ is_syntax_range
Definition: ri.h:2692
@ is_syntax_application
Definition: ri.h:2697
@ is_syntax_cast
Definition: ri.h:2694
@ is_syntax_call
Definition: ri.h:2693
@ is_syntax_va_arg
Definition: ri.h:2698
@ is_syntax_reference
Definition: ri.h:2691
@ is_syntax_sizeofexpression
Definition: ri.h:2695
@ is_syntax_subscript
Definition: ri.h:2696
#define range_increment(x)
Definition: ri.h:2292
#define value_constant_p(x)
Definition: ri.h:3071
#define basic_overloaded_p(x)
Definition: ri.h:623
#define value_symbolic(x)
Definition: ri.h:3070
#define qualifier_restrict_p(x)
Definition: ri.h:2179
#define basic_undefined_p(x)
Definition: ri.h:557
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define cast_expression(x)
Definition: ri.h:747
#define basic_typedef(x)
Definition: ri.h:643
#define application_arguments(x)
Definition: ri.h:510
#define subscript_indices(x)
Definition: ri.h:2563
#define type_undefined_p(x)
Definition: ri.h:2884
#define basic_undefined
Definition: ri.h:556
#define type_enum(x)
Definition: ri.h:2970
#define language_c_p(x)
Definition: ri.h:1594
#define reference_domain
newgen_range_domain_defined
Definition: ri.h:338
#define entity_undefined
Definition: ri.h:2761
#define constant_int_p(x)
Definition: ri.h:848
#define mode_undefined
Definition: ri.h:1660
#define basic_logical(x)
Definition: ri.h:622
#define value_symbolic_p(x)
Definition: ri.h:3068
#define type_void_p(x)
Definition: ri.h:2959
#define entity_name(x)
Definition: ri.h:2790
#define type_varargs(x)
Definition: ri.h:2955
#define functional_parameters(x)
Definition: ri.h:1442
#define variable_undefined
Definition: ri.h:3095
#define PARAMETER(x)
PARAMETER.
Definition: ri.h:1788
#define dimension_upper(x)
Definition: ri.h:982
#define reference_indices(x)
Definition: ri.h:2328
#define syntax_sizeofexpression(x)
Definition: ri.h:2742
#define sizeofexpression_type_p(x)
Definition: ri.h:2404
#define syntax_call(x)
Definition: ri.h:2736
#define dimension_undefined
Definition: ri.h:955
#define cast_type(x)
Definition: ri.h:745
#define variable_qualifiers(x)
Definition: ri.h:3124
#define type_area(x)
Definition: ri.h:2946
#define basic_float(x)
Definition: ri.h:619
#define basic_bit(x)
Definition: ri.h:634
#define syntax_application_p(x)
Definition: ri.h:2746
#define mode_tag(x)
Definition: ri.h:1693
#define type_varargs_p(x)
Definition: ri.h:2953
#define subscript_array(x)
Definition: ri.h:2561
#define application_function(x)
Definition: ri.h:508
#define range_lower(x)
Definition: ri.h:2288
#define variable_dimensions(x)
Definition: ri.h:3122
#define type_undefined
Definition: ri.h:2883
#define syntax_subscript(x)
Definition: ri.h:2745
#define basic_complex(x)
Definition: ri.h:628
#define call_arguments(x)
Definition: ri.h:711
#define syntax_cast_p(x)
Definition: ri.h:2737
@ is_qualifier_volatile
Definition: ri.h:2129
@ is_qualifier_register
Definition: ri.h:2130
@ is_qualifier_restrict
Definition: ri.h:2128
@ is_qualifier_const
Definition: ri.h:2127
@ is_qualifier_auto
Definition: ri.h:2131
@ is_type_void
Definition: ri.h:2904
@ is_type_enum
Definition: ri.h:2907
@ is_type_statement
Definition: ri.h:2898
@ is_type_functional
Definition: ri.h:2901
@ is_type_variable
Definition: ri.h:2900
@ is_type_union
Definition: ri.h:2906
@ is_type_area
Definition: ri.h:2899
@ is_type_unknown
Definition: ri.h:2903
@ is_type_struct
Definition: ri.h:2905
#define syntax_range_p(x)
Definition: ri.h:2731
#define dimension_qualifiers(x)
Definition: ri.h:984
#define basic_string_p(x)
Definition: ri.h:629
#define entity_type(x)
Definition: ri.h:2792
#define expression_syntax(x)
Definition: ri.h:1247
#define dummy_identifier_p(x)
Definition: ri.h:1031
#define type_variable_p(x)
Definition: ri.h:2947
#define basic_bit_p(x)
Definition: ri.h:632
#define symbolic_expression(x)
Definition: ri.h:2597
#define functional_undefined
Definition: ri.h:1418
#define constant_undefined
Definition: ri.h:802
#define type_union(x)
Definition: ri.h:2967
#define variable_basic(x)
Definition: ri.h:3120
#define basic_logical_p(x)
Definition: ri.h:620
#define basic_string(x)
Definition: ri.h:631
#define basic_float_p(x)
Definition: ri.h:617
#define entity_initial(x)
Definition: ri.h:2796
#define area_undefined
Definition: ri.h:520
#define syntax_subscript_p(x)
Definition: ri.h:2743
Value b2
Definition: sc_gram.c:105
Value b1
booleen indiquant quel membre est en cours d'analyse
Definition: sc_gram.c:105
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
s1
Definition: set.c:247
#define ifdebug(n)
Definition: sg.c:47
static bool ok
#define intptr_t
Definition: stdint.in.h:294
FI: I do not understand why the type is duplicated at the set level.
Definition: set.c:59
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
struct cons * cdr
The pointer to the next element.
Definition: newgen_list.h:43
static int depth
la sequence de nids
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207