type.c File Reference

#include <stdio.h>
#include "linear.h"
#include "genC.h"
#include "ri.h"
#include "misc.h"
#include "ri-util.h"

Include dependency graph for type.c:

Go to the source code of this file.

Functions

basic MakeBasicOverloaded ()
 generation of types
mode MakeModeReference ()
mode MakeModeValue ()
type MakeTypeStatement ()
type MakeTypeUnknown ()
type MakeTypeVoid ()
type MakeTypeVariable (basic b, cons *ld)
 BEGIN_EOLE.
basic MakeBasic (int the_tag)
 END_EOLE.
type MakeTypeArray (basic b, cons *ld)
 functions on types
parameter MakeOverloadedParameter ()
parameter MakeIntegerParameter ()
parameter MakeRealParameter ()
parameter MakeDoubleprecisionParameter ()
parameter MakeLogicalParameter ()
parameter MakeComplexParameter ()
parameter MakeDoublecomplexParameter ()
parameter MakeCharacterParameter ()
parameter MakeAnyScalarParameter (tag t, _int size)
 For Fortran.
type MakeOverloadedResult ()
 this function creates a default fortran operator result, i.e.
type MakeIntegerResult ()
type MakeRealResult ()
type MakeDoubleprecisionResult ()
type MakeLogicalResult ()
type MakeComplexResult ()
type MakeDoublecomplexResult ()
type MakeCharacterResult ()
type MakeAnyScalarResult (tag t, _int size)
bool type_equal_p (type t1, type t2)
 Warning: the lengths of string basics are not checked!!! string_type_size() could be used but it is probably not very robust.
type make_scalar_integer_type (_int n)
bool area_equal_p (area a1, area a2)
bool dimension_equal_p (dimension d1, dimension d2)
bool variable_equal_p (variable v1, variable v2)
bool basic_equal_p (basic b1, basic b2)
bool functional_equal_p (functional f1, functional f2)
bool parameter_equal_p (parameter p1, parameter p2)
bool mode_equal_p (mode m1, mode m2)
int string_type_size (basic b)
int basic_type_size (basic b)
 See also SizeOfElements().
basic expression_basic (expression expr)
basic please_give_me_a_basic_for_an_expression (expression e)
 returns an allocated basic.
dimension dimension_dup (dimension d)
list ldimensions_dup (list l)
dimension FindIthDimension (entity e, int i)
string type_to_string (type t)
string safe_type_to_string (type t)
string basic_to_string (basic b)
 BEGIN_EOLE.
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 expression "exp" if "apply_p" is FALSE.
basic basic_of_any_expression (expression exp, bool apply_p)
basic basic_of_expression (expression exp)
 basic basic_of_expression(expression exp): Makes a basic of the same basic as the expression "exp".
type expression_to_type (expression e)
 Replace typedef'ed types by combinations of basic types.
type expression_to_user_type (expression e)
 Preserve typedef'ed types when possible.
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".
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 function.
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 function.
basic basic_of_constant (call c)
 basic basic_of_constant(call c): returns the basic of the call to a constant.
basic basic_union (expression exp1, expression exp2)
 basic basic_union(expression exp1 exp2): returns the basic of the expression which has the most global basic.
basic basic_ultimate (basic b)
 get the ultimate basic from a basic typedef
basic basic_maximum (basic fb1, basic fb2)
bool overloaded_type_p (type t)
 END_EOLE.
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 less complex than float*4, float*4 is less complex than float*8, .
basic simple_basic_dup (basic b)
entity basic_to_generic_conversion (basic b)
 returns the corresponding generic conversion entity, if any.
bool signed_type_p (type t)
bool unsigned_type_p (type t)
bool long_type_p (type t)
bool bit_type_p (type t)
bool char_type_p (type t)
bool basic_type_p (type t)
 Safer than the other implementation? bool pointer_type_p(type t) { bool is_pointer = FALSE;.
bool array_type_p (type t)
bool pointer_type_p (type t)
bool derived_type_p (type t)
 Returns TRUE if t is of type struct, union or enum.
bool typedef_type_p (type t)
 Returns TRUE if t is a typedefED type.
type make_standard_integer_type (type t, int size)
type make_standard_long_integer_type (type t)
type ultimate_type (type t)
 FI: there are different notions of "ultimate" types in C.
bool call_compatible_type_p (type t)
 Is an object of type t compatible with a call?
type call_compatible_type (type t)
 returns the type necessary to generate or check a call to an object of type t.
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 type.
int number_of_fields (type t)
list functional_type_supporting_entities (list sel, functional f)
list enum_supporting_entities (list sel, entity e)
list generic_constant_expression_supporting_entities (list sel, expression e, bool language_c_p)
list constant_expression_supporting_entities (list sel, expression e)
 C version.
list fortran_constant_expression_supporting_entities (list sel, expression e)
 Fortran version.
list generic_symbolic_supporting_entities (list sel, symbolic s, bool language_c_p)
list symbolic_supporting_entities (list sel, symbolic s)
 C version.
list basic_supporting_entities (list sel, basic b)
list variable_type_supporting_entities (list sel, variable v)
list type_supporting_entities (list sel, type t)
static list recursive_type_supporting_references (list srl, type t)
 Compute the list of references implied in the definition of a type.
list functional_type_supporting_references (list srl, functional f)
list enum_supporting_references (list srl, entity e)
list constant_expression_supporting_references (list srl, expression e)
 Only applicable to C expressions.
list symbolic_supporting_references (list srl, symbolic s)
list basic_supporting_references (list srl, basic b)
list variable_type_supporting_references (list srl, variable v)
list fortran_type_supporting_entities (list srl, type t)
list type_supporting_references (list srl, type t)
bool check_C_function_type (entity f, list args)
 Check that an effective parameter list is compatible with a function type.
int type_depth (type t)
 Number of steps to access the lowest leave of type t.
int basic_depth (basic b)
int effect_type_depth (type t)
 Number of steps to access the lowest leave of type t.
int effect_basic_depth (basic b)

Variables

static set supporting_types = set_undefined
 Compute the list of entities implied in the definition of a type.


Function Documentation

bool area_equal_p ( area  a1,
area  a2 
)

layouts are independent ?

Parameters:
a1 1
a2 2

Definition at line 336 of file type.c.

References area_size, area_undefined, FALSE, and TRUE.

Referenced by type_equal_p().

00339 {
00340     if(a1 == a2)
00341         return TRUE;
00342     else if (a1 == area_undefined && a2 != area_undefined)
00343         return FALSE;
00344     else if (a1 != area_undefined && a2 == area_undefined)
00345         return FALSE;
00346     else
00347         /* layouts are independent ? */
00348         return (area_size(a1) == area_size(a2));
00349 }

Here is the caller graph for this function:

bool array_type_p ( type  t  ) 

Definition at line 1643 of file type.c.

References NIL, type_variable, type_variable_p, and variable_dimensions.

Referenced by generic_c_words_entity().

01644 {
01645   return (type_variable_p(t) && (variable_dimensions(type_variable(t)) != NIL));
01646 }

Here is the caller graph for this function:

int basic_depth ( basic  b  ) 

Definition at line 2631 of file type.c.

References basic_derived, basic_tag, basic_typedef, entity_type, is_basic_bit, is_basic_complex, is_basic_derived, is_basic_float, is_basic_int, is_basic_logical, is_basic_overloaded, is_basic_pointer, is_basic_string, is_basic_typedef, pips_internal_error, and type_depth().

Referenced by type_depth().

02632 {
02633   int d = 0;
02634 
02635   switch(basic_tag(b)) {
02636   case is_basic_int:
02637   case is_basic_float:
02638   case is_basic_logical:
02639   case is_basic_overloaded:
02640   case is_basic_complex:
02641   case is_basic_string:
02642   case is_basic_bit:
02643   case is_basic_pointer:
02644     break;
02645   case is_basic_derived:
02646     {
02647       entity e = basic_derived(b);
02648       type t = entity_type(e);
02649       d = type_depth(t);
02650       break;
02651     }
02652   case is_basic_typedef:
02653     {
02654       entity e = basic_typedef(b);
02655       type t = entity_type(e);
02656 
02657       d = type_depth(t);
02658       break;
02659     }
02660   default:
02661     pips_internal_error("Unexpected basic tag %d\n", basic_tag(b));
02662   }
02663 
02664   return d;
02665 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool basic_equal_p ( basic  b1,
basic  b2 
)

assertion: b1 and b2 are defined and have the same tag (see previous tests)

Do we want string types to be equal only if lengths are equal? I do not think so

could be a star or an expression; a value_equal_p() is needed!

just to avoid a warning

Parameters:
b1 1
b2 2

Definition at line 407 of file type.c.

References basic_complex, basic_float, basic_int, basic_logical, basic_tag, basic_typedef, basic_typedef_p, basic_undefined, entity_type, FALSE, is_basic_complex, is_basic_float, is_basic_int, is_basic_logical, is_basic_overloaded, is_basic_string, pips_error(), TRUE, type_variable, ultimate_type(), and variable_basic.

Referenced by add_formal_to_actual_bindings(), convert_constant(), declaration_to_transformer(), fortran_user_call_to_transformer(), is_constant_of_basic(), is_varibale_array_element_specifier(), make_substitution(), same_basic_and_scalar_p(), simd_check_argType(), simplification_conversion(), store_initial_value(), type_loop_range(), type_this_entity_if_needed(), typing_arguments(), typing_arguments_of_user_function(), typing_of_assign(), typing_power_operator(), user_fortran_function_call_to_transformer(), and variable_equal_p().

00408 {
00409     if( basic_typedef_p(b1) )
00410     {
00411         type t1 = ultimate_type( entity_type(basic_typedef(b1)) );
00412         b1 = variable_basic(type_variable(t1));
00413         
00414     }
00415     if( basic_typedef_p(b2) )
00416     {
00417         type t2 = ultimate_type( entity_type(basic_typedef(b2)) );
00418         b2 = variable_basic(type_variable(t2));
00419         
00420     }
00421     if(b1 == b2)
00422         return TRUE;
00423     else if (b1 == basic_undefined && b2 != basic_undefined)
00424         return FALSE;
00425     else if (b1 != basic_undefined && b2 == basic_undefined)
00426         return FALSE;
00427     else if (basic_tag(b1) != basic_tag(b2))
00428         return FALSE;
00429 
00430     /* assertion: b1 and b2 are defined and have the same tag
00431        (see previous tests) */
00432 
00433     switch(basic_tag(b1)) {
00434     case is_basic_int:
00435         return basic_int(b1) == basic_int(b2);
00436     case is_basic_float:
00437         return basic_float(b1) == basic_float(b2);
00438     case is_basic_logical:
00439         return basic_logical(b1) == basic_logical(b2);
00440     case is_basic_overloaded:
00441         return TRUE;
00442     case is_basic_complex:
00443         return basic_complex(b1) == basic_complex(b2);
00444     case is_basic_string:
00445       /* Do we want string types to be equal only if lengths are equal?
00446        * I do not think so
00447        */
00448       /*
00449         pips_error("basic_equal_p",
00450                    "string type comparison not implemented\n");
00451                    */
00452         /* could be a star or an expression; a value_equal_p() is needed! */
00453         return TRUE;
00454     default: pips_error("basic_equal_p", "unexpected tag %d\n", basic_tag(b1));
00455     }
00456     return FALSE; /* just to avoid a warning */
00457 }

Here is the call graph for this function:

Here is the caller graph for this function:

basic basic_maximum ( basic  fb1,
basic  fb2 
)

FI: I do not believe this is correct for all intrinsics!

Type checking problem for ? : with gcc...

NN: More cases are added for C. To be refined

bit is a lesser type

Are they really comparable?

How can we compare two pointer types? Equality? Comparison of the pointed types?

pips_internal_error("Comparison of two pointer types not implemented\n");

FI: not convvincing. As in other palces, assuming this is meaning ful, it would be better to use a basic comparator, basic_greater_p(), which could return 1, -1 or 0 or ??? and deal with non comparable type.

How do you compare a structure or a union to another type? The only case which seems to make sense is equality.

Parameters:
fb1 b1
fb2 b2

Definition at line 1213 of file type.c.

References b, b1, b2, basic_bit, basic_bit_p, basic_complex_p, basic_derived, basic_derived_p, basic_float_p, basic_int_p, basic_logical, basic_logical_p, basic_maximum(), basic_overloaded_p, basic_pointer, basic_pointer_p, basic_string_p, basic_tag, basic_typedef_p, basic_ultimate(), basic_undefined, copy_basic(), entity_enum_p(), free_basic(), is_basic_bit, is_basic_complex, is_basic_derived, is_basic_float, is_basic_int, is_basic_logical, is_basic_overloaded, is_basic_pointer, is_basic_string, is_basic_typedef, make_basic(), pips_debug, pips_internal_error, s1, SizeOfElements(), type_variable, type_variable_p, UU, UUINT, and variable_basic.

Referenced by basic_maximum(), basic_of_intrinsic(), and basic_union().

01214 {
01215   basic b = basic_undefined;
01216   basic b1 = basic_ultimate(fb1);
01217   basic b2 = basic_ultimate(fb2);
01218 
01219 
01220   if(basic_derived_p(fb1)) {
01221     entity e1 = basic_derived(fb1);
01222 
01223     if(entity_enum_p(e1)) {
01224       b1 = make_basic(is_basic_int, (void *) 4);
01225       b = basic_maximum(b1, fb2);
01226       free_basic(b1);
01227       return b;
01228     }
01229     else
01230       pips_internal_error("Unanalyzed derived basic b1\n");
01231   }
01232 
01233   if(basic_derived_p(fb2)) {
01234     entity e2 = basic_derived(fb2);
01235 
01236     if(entity_enum_p(e2)) {
01237       b2 = make_basic(is_basic_int, (void *) 4);
01238       b = basic_maximum(fb1, b2);
01239       free_basic(b2);
01240       return b;
01241     }
01242     else
01243       pips_internal_error("Unanalyzed derived basic b2\n");
01244   }
01245 
01246   /* FI: I do not believe this is correct for all intrinsics! */
01247 
01248   pips_debug(7, "Tags: tag exp1 = %d, tag exp2 = %d\n",
01249              basic_tag(b1), basic_tag(b2));
01250 
01251 
01252   if(basic_overloaded_p(b2)) {
01253     b = copy_basic(b2);
01254   }
01255   else {
01256     switch(basic_tag(b1)) {
01257 
01258     case is_basic_overloaded:
01259       b = copy_basic(b1);
01260       break;
01261 
01262     case is_basic_string:
01263       if(basic_string_p(b2)) {
01264         int s1 = SizeOfElements(b1);
01265         int s2 = SizeOfElements(b2);
01266 
01267         /* Type checking problem for ? : with gcc... */
01268         if(s1>s2)
01269           b = copy_basic(b1);
01270         else
01271           b = copy_basic(b2);
01272       }
01273       else
01274         b = make_basic(is_basic_overloaded, UU);
01275       break;
01276 
01277     case is_basic_logical:
01278       if(basic_logical_p(b2)) {
01279         _int s1 = basic_logical(b1);
01280         _int s2 = basic_logical(b2);
01281 
01282         b = make_basic(is_basic_logical,UUINT(s1>s2?s1:s2));
01283       }
01284       else
01285         b = make_basic(is_basic_overloaded, UU);
01286       break;
01287 
01288     case is_basic_complex:
01289       if(basic_complex_p(b2) || basic_float_p(b2) || basic_int_p(b2)) {
01290         _int s1 = SizeOfElements(b1);
01291         _int s2 = SizeOfElements(b2);
01292 
01293         b = make_basic(is_basic_complex, UUINT(s1>s2?s1:s2));
01294       }
01295       else
01296         b = make_basic(is_basic_overloaded, UU);
01297       break;
01298 
01299     case is_basic_float:
01300       if(basic_complex_p(b2)) {
01301         _int s1 = SizeOfElements(b1);
01302         _int s2 = SizeOfElements(b2);
01303 
01304         b = make_basic(is_basic_complex, UUINT(s1>s2?s1:s2));
01305       }
01306       else if(basic_float_p(b2) || basic_int_p(b2)) {
01307         _int s1 = SizeOfElements(b1);
01308         _int s2 = SizeOfElements(b2);
01309 
01310         b = make_basic(is_basic_float, UUINT(s1>s2?s1:s2));
01311       }
01312       else
01313         b = make_basic(is_basic_overloaded, UU);
01314       break;
01315 
01316     case is_basic_int:
01317       if(basic_complex_p(b2) || basic_float_p(b2)) {
01318         _int s1 = SizeOfElements(b1);
01319         _int s2 = SizeOfElements(b2);
01320         
01321         b = make_basic(basic_tag(b2), UUINT(s1>s2?s1:s2));
01322       }
01323       else if(basic_int_p(b2)) {
01324         _int s1 = SizeOfElements(b1);
01325         _int s2 = SizeOfElements(b2);
01326 
01327         b = make_basic(is_basic_int, UUINT(s1>s2?s1:s2));
01328       }
01329       else
01330         b = make_basic(is_basic_overloaded, UU);
01331       break;
01332       /* NN: More cases are added for C. To be refined  */
01333     case is_basic_bit:
01334       if(basic_bit_p(b2)) {
01335         if(basic_bit(b1)>=basic_bit(b2))
01336           b = copy_basic(b1);
01337         else
01338           b = copy_basic(b2);
01339       }
01340       else
01341         /* bit is a lesser type */
01342         b = copy_basic(b2);
01343       break;
01344     case is_basic_pointer:
01345       {
01346         if(basic_int_p(b2) || basic_bit_p(b2))
01347           b = copy_basic(b1);
01348         else if(basic_float_p(b2) || basic_logical_p(b2) || basic_complex_p(b2)) {
01349           /* Are they really comparable? */
01350           b = copy_basic(b1);
01351         }
01352         else if(basic_overloaded_p(b2))
01353           b = copy_basic(b1);
01354         else if(basic_pointer_p(b2)) {
01355           /* How can we compare two pointer types? Equality? Comparison of the pointed types? */
01356           /* pips_internal_error("Comparison of two pointer types not implemented\n"); */
01357           type t1 = basic_pointer(b1);
01358           type t2 = basic_pointer(b2);
01359 
01360           if(type_variable_p(t1) && type_variable_p(t2)) {
01361             basic nb1 = variable_basic(type_variable(t1));
01362             basic nb2 = variable_basic(type_variable(t2));
01363 
01364             /* FI: not convvincing. As in other palces, assuming this
01365                is meaning ful, it would be better to use a basic
01366                comparator, basic_greater_p(), which could return 1, -1
01367                or 0 or ??? and deal with non comparable type. */
01368             b = basic_maximum(nb1, nb2);
01369           }
01370           else
01371             pips_internal_error("Comparison of two pointer types not meaningful\n");
01372         }
01373         else if(basic_derived_p(b2))
01374           pips_internal_error("Comparison between pointer and struct/union not implemented\n");
01375         else if(basic_typedef_p(b2))
01376           pips_internal_error("b2 cannot be a typedef basic\n");
01377         else
01378           pips_internal_error("unknown tag %d for basic b2\n", basic_tag(b2));
01379       break;
01380        }
01381      case is_basic_derived:
01382       /* How do you compare a structure or a union to another type?
01383          The only case which seems to make sense is equality. */
01384       pips_internal_error("Derived basic b1 it not comparable to another basic\n");
01385       break;
01386     case is_basic_typedef:
01387       pips_internal_error("b1 cannot be a typedef basic\n");
01388       break;
01389     default: pips_internal_error("Ill. basic tag %d\n", basic_tag(b1));
01390     }
01391   }
01392 
01393   return b;
01394 
01395   /*
01396     if( (t1 != is_basic_complex) && (t1 != is_basic_float) &&
01397     (t1 != is_basic_int) && (t2 != is_basic_complex) &&
01398     (t2 != is_basic_float) && (t2 != is_basic_int) )
01399     pips_error("basic_union",
01400     "Bad basic tag for expression in numerical function");
01401 
01402     if(t1 == is_basic_complex)
01403     return(b1);
01404     if(t2 == is_basic_complex)
01405     return(b2);
01406     if(t1 == is_basic_float) {
01407     if( (t2 != is_basic_float) ||
01408     (basic_float(b1) == DOUBLE_PRECISION_SIZE) )
01409     return(b1);
01410     return(b2);
01411     }
01412     if(t2 == is_basic_float)
01413     return(b2);
01414     return(b1);
01415   */
01416 }

Here is the call graph for this function:

Here is the caller graph for this function:

basic basic_of_any_expression ( expression  exp,
bool  apply_p 
)

Parameters:
exp xp
apply_p pply_p

Definition at line 894 of file type.c.

References some_basic_of_any_expression(), and TRUE.

Referenced by basic_of_expression(), and some_basic_of_any_expression().

00895 {
00896   return some_basic_of_any_expression(exp, apply_p, TRUE);
00897 }

Here is the call graph for this function:

Here is the caller graph for this function:

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".

If ultimate_p is true, replaced typdef'ed types by their definitions recursively. If not, preserve typedef'ed types.

WARNING: a new basic is allocated

b = make_basic(is_basic_overloaded, UU);

Never go there...

Parameters:
apply_p pply_p
ultimate_p ltimate_p

Definition at line 953 of file type.c.

References b, basic_of_constant(), basic_of_external(), basic_of_intrinsic(), basic_undefined, call_function, copy_basic(), entity_initial, entity_name, is_value_code, is_value_constant, is_value_intrinsic, is_value_symbolic, is_value_unknown, pips_debug, pips_internal_error, tag, and value_tag.

Referenced by some_basic_of_any_expression(), type_this_call(), and user_fortran_function_call_to_transformer().

00954 {
00955     entity e = call_function(c);
00956     tag t = value_tag(entity_initial(e));
00957     basic b = basic_undefined;
00958 
00959     switch (t)
00960     {
00961     case is_value_code:
00962         b = copy_basic(basic_of_external(c));
00963         break;
00964     case is_value_intrinsic: 
00965       b = basic_of_intrinsic(c, apply_p, ultimate_p);
00966         break;
00967     case is_value_symbolic: 
00968         /* b = make_basic(is_basic_overloaded, UU); */
00969         b = copy_basic(basic_of_constant(c));
00970         break;
00971     case is_value_constant:
00972         b = copy_basic(basic_of_constant(c));
00973         break;
00974     case is_value_unknown:
00975         pips_debug(1, "function %s has no initial value.\n"
00976               " Maybe it has not been parsed yet.\n",
00977               entity_name(e));
00978         b = copy_basic(basic_of_external(c));
00979         break;
00980     default: pips_internal_error("unknown tag %d\n", t);
00981         /* Never go there... */
00982     }
00983     return b;
00984 }

Here is the call graph for this function:

Here is the caller graph for this function:

basic basic_of_constant ( call  c  ) 

basic basic_of_constant(call c): returns the basic of the call to a constant.

WARNING: returns a pointer towards an existing data structure

Definition at line 1158 of file type.c.

References call_function, debug(), entity_type, functional_result, is_type_functional, is_type_variable, pips_error(), type_functional, type_tag, type_variable, and variable_basic.

Referenced by basic_of_call().

01159 {
01160     type call_type, return_type;
01161 
01162     debug(7, "basic_of_constant", "Constant call\n");
01163 
01164     call_type = entity_type(call_function(c));
01165 
01166     if (type_tag(call_type) != is_type_functional)
01167         pips_error("basic_of_constant", "Bad call type tag");
01168 
01169     return_type = functional_result(type_functional(call_type));
01170 
01171     if (type_tag(return_type) != is_type_variable)
01172         pips_error("basic_of_constant", "Bad return call type tag");
01173 
01174     return(variable_basic(type_variable(return_type)));
01175 }

Here is the call graph for this function:

Here is the caller graph for this function:

basic basic_of_expression ( expression  exp  ) 

basic basic_of_expression(expression exp): Makes a basic of the same basic as the expression "exp".

Indeed, "exp" will be assigned to a temporary variable, which will have the same declaration as "exp".

Does not work if the expression is a reference to a functional entity, as may be the case in a Fortran call.

WARNING: a new basic object is allocated

PREFER (???) expression_basic

Parameters:
exp xp

Definition at line 912 of file type.c.

References basic_of_any_expression(), and FALSE.

Referenced by add_formal_to_actual_bindings(), any_expression_to_transformer(), assign_tmp_to_exp(), atomizer_of_external(), basic_of_intrinsic(), basic_union(), c_user_call_to_transformer(), condition_to_transformer(), declaration_to_transformer(), expression_to_type(), fortran_user_call_to_transformer(), integer_expression_p(), logical_binary_function_to_transformer(), make_substitution(), MakeComplexConstantExpression(), MemberIdentifierToExpression(), please_give_me_a_basic_for_an_expression(), simd_atomize_this_expression(), SizeOfArray(), some_basic_of_any_expression(), store_initial_value(), transformer_add_any_relation_information(), update_functional_type_with_actual_arguments(), and words_infix_binary_op().

00913 {
00914   return basic_of_any_expression(exp, FALSE);
00915 }

Here is the call graph for this function:

Here is the caller graph for this function:

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 function.

WARNING: returns a pointer

Definition at line 994 of file type.c.

References b, basic_to_string(), basic_undefined, call_function, entity_name, entity_type, f, functional_result, is_type_functional, pips_debug, pips_error(), pips_internal_error, pips_user_error, type_functional, type_tag, type_to_string(), type_undefined, type_variable, type_variable_p, type_void_p, and variable_basic.

Referenced by basic_of_call().

00995 {
00996     type return_type = type_undefined;
00997     entity f = call_function(c);
00998     basic b = basic_undefined;
00999     type call_type = entity_type(f);
01000 
01001     pips_debug(7, "External call to %s\n", entity_name(f));
01002 
01003     if (type_tag(call_type) != is_type_functional)
01004         pips_error("basic_of_external", "Bad call type tag");
01005 
01006     return_type = functional_result(type_functional(call_type));
01007 
01008     if (!type_variable_p(return_type)) {
01009       if(type_void_p(return_type)) {
01010         pips_user_error("A subroutine or void returning function is used as an expression\n");
01011       }
01012       else {
01013         pips_internal_error("Bad return call type tag \"%s\"\n", type_to_string(return_type));
01014       }
01015     }
01016 
01017     b = (variable_basic(type_variable(return_type)));
01018 
01019     pips_debug(7, "Returned type is %s\n", basic_to_string(b));
01020 
01021     return b;
01022 }

Here is the call graph for this function:

Here is the caller graph for this function:

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 function.

This basic must be computed with the basic of the arguments of the intrinsic for overloaded operators. It should be able to accomodate more than two arguments as for generic min and max operators. ultimate_p controls the behavior when typedef'ed types are encountered: should they be replaced by their definitions or not?

WARNING: returns a newly allocated basic object

I don't know the type since there is no arguments ! Bug encountered with a FMT=* in a PRINT. RK, 21/02/1994 :

leave it overloaded

Too bad for "void"...

We should reconstruct a struct type or an array type...

returns the type of the left hand side

The value returned is the value of the last expression in the list.

Parameters:
apply_p pply_p
ultimate_p ltimate_p

Definition at line 1034 of file type.c.

References b, basic_maximum(), basic_of_expression(), basic_overloaded_p, basic_pointer, basic_pointer_p, basic_to_string(), call_arguments, call_function, CAR, CDR, copy_basic(), copy_type(), ENDP, ENTITY_ADDRESS_OF_P, ENTITY_ASSIGN_P, ENTITY_BRACE_INTRINSIC_P, ENTITY_COMMA_P, ENTITY_DEREFERENCING_P, ENTITY_FIELD_P, ENTITY_POINT_TO_P, entity_type, EXPRESSION, f, FALSE, free_basic(), functional_result, gen_last(), gen_length(), ifdebug, is_basic_pointer, is_type_variable, make_basic(), make_basic_overloaded(), make_type(), make_variable(), MAP, module_local_name(), NIL, pips_assert, pips_debug, pips_internal_error, print_expression(), rt, some_basic_of_any_expression(), type_consistent_p(), type_functional, type_functional_p, type_undefined, type_variable, type_variable_p, ultimate_type(), and variable_basic.

Referenced by basic_of_call().

01035 {
01036   entity f = call_function(c);
01037   type rt = functional_result(type_functional(entity_type(f)));
01038   basic rb = copy_basic(variable_basic(type_variable(rt)));
01039 
01040   pips_debug(7, "Intrinsic call to intrinsic \"%s\" with a priori result type \"%s\"\n",
01041              module_local_name(f),
01042              basic_to_string(rb));
01043 
01044   if(basic_overloaded_p(rb)) {
01045     list args = call_arguments(c);
01046 
01047     if (ENDP(args)) {
01048       /* I don't know the type since there is no arguments !
01049          Bug encountered with a FMT=* in a PRINT.
01050          RK, 21/02/1994 : */
01051       /* leave it overloaded */
01052       ;
01053     }
01054     else if(ENTITY_ADDRESS_OF_P(f)) {
01055       //string s = entity_user_name(f);
01056       //bool b = ENTITY_ADDRESS_OF_P(f);
01057       expression e = EXPRESSION(CAR(args));
01058       basic eb = some_basic_of_any_expression(e, FALSE, ultimate_p);
01059       // Forget multidimensional types
01060       type et = make_type(is_type_variable,
01061                           make_variable(eb, NIL, NIL));
01062 
01063       //fprintf(stderr, "b=%d, s=%s\n", b, s);
01064       free_basic(rb);
01065       rb = make_basic(is_basic_pointer, et);
01066     }
01067     else if(ENTITY_DEREFERENCING_P(f)) {
01068       expression e = EXPRESSION(CAR(args));
01069       free_basic(rb);
01070       rb = basic_of_expression(e);
01071       if(basic_pointer_p(rb)) {
01072         type pt = type_undefined;
01073 
01074         if(ultimate_p)
01075           pt = copy_type(ultimate_type(basic_pointer(rb)));
01076         else
01077           pt = copy_type(basic_pointer(rb));
01078 
01079         free_basic(rb);
01080         pips_assert("The pointed type is consistent", type_consistent_p(pt));
01081         if(type_variable_p(pt) && !apply_p)
01082           rb = copy_basic(variable_basic(type_variable(pt)));
01083         else if(type_functional_p(pt) && apply_p) {
01084           type rt = ultimate_type(functional_result(type_functional(pt)));
01085 
01086           if(type_variable_p(rt))
01087             rb = copy_basic(variable_basic(type_variable(rt)));
01088           else {
01089             /* Too bad for "void"... */
01090             pips_internal_error("result type of a functional type must be a variable type\n");
01091           }
01092         }
01093       }
01094       else
01095         pips_internal_error("Dereferencing of a non-pointer expression\n");
01096     }
01097     else if(ENTITY_POINT_TO_P(f)) {
01098       //pips_internal_error("Point to case not implemented yet\n");
01099       expression e1 = EXPRESSION(CAR(args));
01100       expression e2 = EXPRESSION(CAR(CDR(args)));
01101       free_basic(rb);
01102       pips_assert("Two arguments for ENTITY_POINT_TO", gen_length(args)==2);
01103       ifdebug(8) {
01104         pips_debug(8, "Point to case, e1 = ");
01105         print_expression(e1);
01106         pips_debug(8, " and e2 = ");
01107         print_expression(e1);
01108         pips_debug(8, "\n");
01109       }
01110       rb = basic_of_expression(e2);
01111     }
01112     else if(ENTITY_BRACE_INTRINSIC_P(f)) {
01113       /* We should reconstruct a struct type or an array type... */
01114       rb = make_basic_overloaded();
01115     }
01116     else if(ENTITY_ASSIGN_P(f)) {
01117       /* returns the type of the left hand side */
01118       rb = basic_of_expression(EXPRESSION(CAR(args)));
01119     }
01120     else if(ENTITY_FIELD_P(f)) {
01121       free_basic(rb);
01122       rb = basic_of_expression(EXPRESSION(CAR(CDR(args))));
01123     }
01124     else if(ENTITY_COMMA_P(f)) {
01125       /* The value returned is the value of the last expression in the list. */
01126       free_basic(rb);
01127       rb = basic_of_expression(EXPRESSION(CAR(gen_last(args))));
01128     }
01129     else {
01130       free_basic(rb);
01131       rb = basic_of_expression(EXPRESSION(CAR(args)));
01132 
01133       MAP(EXPRESSION, arg, {
01134         basic b = basic_of_expression(arg);
01135         basic new_rb = basic_maximum(rb, b);
01136 
01137         free_basic(rb);
01138         free_basic(b);
01139         rb = new_rb;
01140       }, CDR(args));
01141     }
01142 
01143   }
01144 
01145   pips_debug(7, "Intrinsic call to intrinsic \"%s\" with a posteriori result type \"%s\"\n",
01146              module_local_name(f),
01147              basic_to_string(rb));
01148 
01149   return rb;
01150 }

Here is the call graph for this function:

Here is the caller graph for this function:

list basic_supporting_entities ( list  sel,
basic  b 
)

Parameters:
sel el

Definition at line 2092 of file type.c.

References basic_bit, basic_bit_p, basic_complex_p, basic_derived, basic_derived_p, basic_float_p, basic_int_p, basic_logical_p, basic_overloaded_p, basic_pointer, basic_pointer_p, basic_string_p, basic_tag, basic_typedef, basic_typedef_p, CONS, ENTITY, entity_type, fprintf(), ifdebug, pips_debug, pips_internal_error, print_entities(), symbolic_supporting_entities(), and type_supporting_entities().

Referenced by variable_type_supporting_entities().

02093 {
02094 
02095   ifdebug(8) {
02096     pips_debug(8, "Begin: ");
02097     print_entities(sel);
02098     fprintf(stderr, "\n");
02099   }
02100 
02101   if(basic_int_p(b) ||
02102      basic_float_p(b) ||
02103      basic_logical_p(b) ||
02104      basic_overloaded_p(b) ||
02105      basic_complex_p(b) ||
02106      basic_string_p(b))
02107     ;
02108   else if(basic_bit_p(b))
02109     sel = symbolic_supporting_entities(sel, basic_bit(b));
02110   else if(basic_pointer_p(b))
02111     sel = type_supporting_entities(sel, basic_pointer(b));
02112   else if(basic_derived_p(b)) {
02113     sel = CONS(ENTITY, basic_derived(b), sel);
02114     sel = type_supporting_entities(sel, entity_type(basic_derived(b)));
02115   }
02116   else if(basic_typedef_p(b)) {
02117     entity se = basic_typedef(b);
02118     sel = CONS(ENTITY, se, sel);
02119     sel = type_supporting_entities(sel, entity_type(se));
02120   }
02121   else
02122     pips_internal_error("Unrecognized basic tag %d\n", basic_tag(b));
02123  
02124   ifdebug(8) {
02125     pips_debug(8, "End: ");
02126     print_entities(sel);
02127     fprintf(stderr, "\n");
02128   }
02129 
02130   return sel;
02131 }

Here is the call graph for this function:

Here is the caller graph for this function:

list basic_supporting_references ( list  srl,
basic  b 
)

Parameters:
srl rl

Definition at line 2345 of file type.c.

References basic_bit, basic_bit_p, basic_complex_p, basic_derived, basic_derived_p, basic_float_p, basic_int_p, basic_logical_p, basic_overloaded_p, basic_pointer, basic_pointer_p, basic_string_p, basic_tag, basic_typedef, basic_typedef_p, entity_type, fprintf(), ifdebug, pips_debug, pips_internal_error, print_references(), recursive_type_supporting_references(), and symbolic_supporting_references().

Referenced by variable_type_supporting_references().

02346 {
02347 
02348   ifdebug(9) {
02349     pips_debug(8, "Begin: ");
02350     print_references(srl);
02351     fprintf(stderr, "\n");
02352   }
02353 
02354   if(basic_int_p(b) ||
02355      basic_float_p(b) ||
02356      basic_logical_p(b) ||
02357      basic_overloaded_p(b) ||
02358      basic_complex_p(b) ||
02359      basic_string_p(b))
02360     ;
02361   else if(basic_bit_p(b))
02362     srl = symbolic_supporting_references(srl, basic_bit(b));
02363   else if(basic_pointer_p(b))
02364     srl = recursive_type_supporting_references(srl, basic_pointer(b));
02365   else if(basic_derived_p(b)) {
02366     //srl = CONS(ENTITY, basic_derived(b), srl);
02367     srl = recursive_type_supporting_references(srl, entity_type(basic_derived(b)));
02368   }
02369   else if(basic_typedef_p(b)) {
02370     entity se = basic_typedef(b);
02371     //srl = CONS(ENTITY, se, srl);
02372     srl = recursive_type_supporting_references(srl, entity_type(se));
02373   }
02374   else
02375     pips_internal_error("Unrecognized basic tag %d\n", basic_tag(b));
02376  
02377   ifdebug(9) {
02378     pips_debug(8, "End: ");
02379     print_references(srl);
02380     fprintf(stderr, "\n");
02381   }
02382 
02383   return srl;
02384 }

Here is the call graph for this function:

Here is the caller graph for this function:

entity basic_to_generic_conversion ( basic  b  ) 

returns the corresponding generic conversion entity, if any.

otherwise returns entity_undefined.

what about INTEGER*{2,4,8} ?

Definition at line 1510 of file type.c.

References basic_complex, basic_float, basic_tag, CMPLX_GENERIC_CONVERSION_NAME, DBLE_GENERIC_CONVERSION_NAME, DCMPLX_GENERIC_CONVERSION_NAME, entity_intrinsic(), entity_undefined, INT_GENERIC_CONVERSION_NAME, is_basic_complex, is_basic_float, is_basic_int, and REAL_GENERIC_CONVERSION_NAME.

Referenced by make_substitution().

01511 {
01512     entity result;
01513 
01514     switch (basic_tag(b))
01515     {
01516     case is_basic_int: 
01517         /* what about INTEGER*{2,4,8} ? 
01518          */
01519         result = entity_intrinsic(INT_GENERIC_CONVERSION_NAME);
01520         break;
01521     case is_basic_float:
01522     {
01523         if (basic_float(b)==4)
01524             result = entity_intrinsic(REAL_GENERIC_CONVERSION_NAME);
01525         else if (basic_float(b)==8)
01526             result = entity_intrinsic(DBLE_GENERIC_CONVERSION_NAME);
01527         else
01528             result = entity_undefined;
01529         break;
01530     }
01531     case is_basic_complex:
01532     {
01533         if (basic_complex(b)==8)
01534             result = entity_intrinsic(CMPLX_GENERIC_CONVERSION_NAME);
01535         else if (basic_complex(b)==16)
01536             result = entity_intrinsic(DCMPLX_GENERIC_CONVERSION_NAME);
01537         else
01538             result = entity_undefined;
01539         break;
01540     }
01541     default:
01542         result = entity_undefined;
01543     }
01544 
01545     return result;
01546 }

Here is the call graph for this function:

Here is the caller graph for this function:

string basic_to_string ( basic  b  ) 

BEGIN_EOLE.

  • please do not remove this lineLines between BEGIN_EOLE and END_EOLE tags are automatically included in the EOLE project (JZ - 11/98)

Nga Nguyen, 19/09/2003: To not rewrite the same thing, I use the words_basic() function

Definition at line 741 of file type.c.

References list_to_string(), and words_basic().

Referenced by add_formal_to_actual_bindings(), any_expression_to_transformer(), arguments_are_something(), basic_of_external(), basic_of_intrinsic(), DeclareVariable(), dump_functional(), fortran_user_call_to_transformer(), fprint_any_environment(), fprint_functional(), get_symbol_table(), is_varibale_array_element_specifier(), register_scalar_communications(), relation_to_transformer(), sentence_basic_declaration(), some_basic_of_any_expression(), string_expression_to_transformer(), stub_head(), stub_var_decl(), type_this_call(), type_this_entity_if_needed(), type_this_expression(), type_this_instruction(), TypeFunctionalEntity(), typing_arguments_of_user_function(), typing_function_argument_type_to_return_type(), ultimate_type(), and variable_to_string().

00743 {
00744   /* Nga Nguyen, 19/09/2003: To not rewrite the same thing, I use the words_basic() function*/
00745   return list_to_string(words_basic(b));
00746 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool basic_type_p ( type  t  ) 

Safer than the other implementation? bool pointer_type_p(type t) { bool is_pointer = FALSE;.

if (!type_undefined_p(t) && type_variable_p(t)) { basic b = variable_basic(type_variable(t)); if (!basic_undefined_p(b) && basic_pointer_p(b)) { is_pointer = TRUE; } } return is_pointer; }Here is the set of mapping functions, from the RI to C language typesReturns TRUE if t is one of the following types : void, char, short, int, long, float, double, signed, unsigned, and there is no array dimensions, of course

Definition at line 1630 of file type.c.

References b, basic_bit_p, basic_complex_p, basic_float_p, basic_int_p, basic_logical_p, basic_overloaded_p, basic_string_p, NIL, type_unknown_p, type_variable, type_variable_p, type_void_p, variable_basic, and variable_dimensions.

Referenced by generic_c_words_entity().

01631 {
01632   if (type_variable_p(t))
01633     {
01634       basic b = variable_basic(type_variable(t));
01635       return ((variable_dimensions(type_variable(t)) == NIL) &&
01636               (basic_int_p(b) || basic_float_p(b) || basic_logical_p(b)
01637                || basic_overloaded_p(b) || basic_complex_p(b) || basic_string_p(b)
01638                || basic_bit_p(b)));
01639     }
01640   return (type_void_p(t) || type_unknown_p(t)) ;
01641 }

Here is the caller graph for this function:

int basic_type_size ( basic  b  ) 

See also SizeOfElements().

pips_error("basic_type_size", "undefined for type string\n");

Definition at line 543 of file type.c.

References basic_complex, basic_float, basic_int, basic_logical, basic_tag, is_basic_complex, is_basic_float, is_basic_int, is_basic_logical, is_basic_overloaded, is_basic_string, pips_error(), and string_type_size().

Referenced by DeclareVariable(), MakeAtom(), MakeComplexConstant(), and MakeComplexConstantExpression().

00544 {
00545     int size = -1;
00546 
00547     switch(basic_tag(b)) {
00548     case is_basic_int: size = basic_int(b);
00549         break;
00550     case is_basic_float: size = basic_float(b);
00551         break;
00552     case is_basic_logical: size = basic_logical(b);
00553         break;
00554     case is_basic_overloaded: 
00555         pips_error("basic_type_size", "undefined for type overloaded\n");
00556         break;
00557     case is_basic_complex: size = basic_complex(b);
00558         break;
00559     case is_basic_string: 
00560       /* pips_error("basic_type_size", "undefined for type string\n"); */
00561       size = string_type_size(b);
00562         break;
00563     default: size = basic_int(b);
00564         pips_error("basic_type_size", "ill. tag %d\n", basic_tag(b));
00565         break;
00566     }
00567 
00568     return size;
00569 }

Here is the call graph for this function:

Here is the caller graph for this function:

basic basic_ultimate ( basic  b  ) 

get the ultimate basic from a basic typedef

Definition at line 1202 of file type.c.

References basic_typedef, basic_typedef_p, entity_type, pips_assert, type_variable, type_variable_p, ultimate_type(), and variable_basic.

Referenced by basic_maximum(), and make_new_scalar_variable_with_prefix().

01203 {
01204   if(basic_typedef_p(b)) {
01205     type t = ultimate_type(entity_type(basic_typedef(b)));
01206     pips_assert("typedef really has a variable type", type_variable_p(t) );
01207     b = variable_basic(type_variable(t));
01208   }
01209   return b;
01210 }

Here is the call graph for this function:

Here is the caller graph for this function:

basic basic_union ( expression  exp1,
expression  exp2 
)

basic basic_union(expression exp1 exp2): returns the basic of the expression which has the most global basic.

Then, between "int" and "float", the most global is "float".

Note: there are two different "float" : DOUBLE PRECISION and REAL.

WARNING: a new basic data structure is allocated (because you cannot always find a proper data structure to return simply a pointer

Parameters:
exp1 xp1
exp2 xp2

Definition at line 1188 of file type.c.

References b, b1, b2, basic_maximum(), basic_of_expression(), and free_basic().

01189 {
01190   basic b1 = basic_of_expression(exp1);
01191   basic b2 = basic_of_expression(exp2);
01192   basic b = basic_maximum(b1, b2);
01193 
01194   free_basic(b1);
01195   free_basic(b2);
01196   return b;
01197 }

Here is the call graph for this function:

bool bit_type_p ( type  t  ) 

Definition at line 1584 of file type.c.

References b, basic_bit_p, basic_undefined_p, FALSE, TRUE, type_undefined_p, type_variable, type_variable_p, and variable_basic.

Referenced by generic_c_words_entity(), make_standard_integer_type(), make_standard_long_integer_type(), and UpdateDerivedEntity().

01585 {
01586   if (!type_undefined_p(t) && type_variable_p(t))
01587     {
01588       basic b = variable_basic(type_variable(t));
01589       if (!basic_undefined_p(b) && basic_bit_p(b))
01590         return TRUE;
01591     }
01592   return FALSE;
01593 }

Here is the caller graph for this function:

type call_compatible_type ( type  t  ) 

returns the type necessary to generate or check a call to an object of type t.

Does not allocate a new type. Previous function could be implemented with this one.

Definition at line 1829 of file type.c.

References b, basic_pointer, basic_pointer_p, basic_typedef, basic_typedef_p, call_compatible_type(), entity_type, FALSE, pips_assert, type_consistent_p(), type_functional_p, type_variable, type_variable_p, and variable_basic.

Referenced by call_compatible_type(), check_C_function_type(), words_genuine_regular_call(), and words_regular_call().

01830 {
01831   type compatible = t;
01832 
01833   pips_assert("t is a consistent type", type_consistent_p(t));
01834 
01835   if(!type_functional_p(t)) {
01836     if(type_variable_p(t)) {
01837       basic b = variable_basic(type_variable(t));
01838 
01839       if(basic_pointer_p(b))
01840         compatible = call_compatible_type(basic_pointer(b));
01841       else if(basic_typedef_p(b)) {
01842         entity te = basic_typedef(b);
01843 
01844         compatible = call_compatible_type(entity_type(te));
01845       }
01846       else
01847         compatible = FALSE;
01848     }
01849     else
01850       compatible = FALSE;
01851   }
01852   pips_assert("compatible is a functional type", type_functional_p(compatible));
01853   pips_assert("compatible is a consistent type", type_consistent_p(compatible));
01854   return compatible;
01855 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool call_compatible_type_p ( type  t  ) 

Is an object of type t compatible with a call?

Definition at line 1802 of file type.c.

References b, basic_pointer, basic_pointer_p, basic_typedef, basic_typedef_p, call_compatible_type_p(), entity_type, FALSE, TRUE, type_functional_p, type_variable, type_variable_p, and variable_basic.

Referenced by call_compatible_type_p(), check_C_function_type(), and MakeFunctionExpression().

01803 {
01804   bool compatible_p = TRUE;
01805 
01806   if(!type_functional_p(t)) {
01807     if(type_variable_p(t)) {
01808       basic b = variable_basic(type_variable(t));
01809 
01810       if(basic_pointer_p(b))
01811         compatible_p = call_compatible_type_p(basic_pointer(b));
01812       else if(basic_typedef_p(b)) {
01813         entity te = basic_typedef(b);
01814 
01815         compatible_p = call_compatible_type_p(entity_type(te));
01816       }
01817       else
01818         compatible_p = FALSE;
01819     }
01820     else
01821       compatible_p = FALSE;
01822   }
01823   return compatible_p;
01824 }

Here is the call graph for this function:

Here is the caller graph for this function:

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 type.

FI: I'm not sure this is correctly implemented. I do not know if a new type is always allocated. I do not understand the semantics if ultimate is turned off.

assertion will fail anyway

must be a functional type

Parameters:
ultimate_p ltimate_p

Definition at line 1862 of file type.c.

References basic_pointer, basic_pointer_p, basic_typedef, basic_typedef_p, call_function, copy_type(), entity_type, f, free_type(), pips_assert, pips_internal_error, rt, type_functional_p, type_undefined, type_variable, type_variable_p, ultimate_type(), and variable_basic.

Referenced by MemberIdentifierToExpression(), and simplify_C_expression().

01863 {
01864   entity f = call_function(c);
01865   type ft = entity_type(f);
01866   type rt = type_undefined;
01867 
01868   if(type_functional_p(ft))
01869     rt = entity_type(f);
01870   else if(type_variable_p(ft)) {
01871     basic ftb = variable_basic(type_variable(ft));
01872     if(basic_pointer_p(ftb)) {
01873       type pt = basic_pointer(ftb);
01874       rt = ultimate_p? ultimate_type(pt) : copy_type(pt);
01875     }
01876     else if(basic_typedef_p(ftb)) {
01877       entity te = basic_typedef(ftb);
01878       type ut = ultimate_type(entity_type(te));
01879 
01880       if(type_variable_p(ut)) {
01881         basic utb = variable_basic(type_variable(ut));
01882         if(basic_pointer_p(utb)) {
01883           type pt = basic_pointer(utb);
01884           rt = ultimate_p? ultimate_type(pt): copy_type(pt);
01885         }
01886         else
01887           /* assertion will fail anyway */
01888           free_type(ut);
01889       }
01890       else /* must be a functional type */
01891         rt = ut;
01892     }
01893     else {
01894       pips_internal_error("Basic for called function unknown");
01895     }
01896   }
01897   else
01898     pips_internal_error("Type for called function unknown");
01899 
01900   pips_assert("The typedef type is functional", type_functional_p(rt));
01901 
01902   return rt;
01903 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool char_type_p ( type  t  ) 

see words_basic()

Definition at line 1595 of file type.c.

References b, basic_int, basic_int_p, basic_undefined_p, FALSE, i, type_undefined_p, type_variable, type_variable_p, and variable_basic.

Referenced by SizeOfArray().

01596 {
01597   bool is_char = FALSE;
01598 
01599   if (!type_undefined_p(t) && type_variable_p(t)) {
01600     basic b = variable_basic(type_variable(t));
01601     if (!basic_undefined_p(b) && basic_int_p(b)) {
01602       int i = basic_int(b);
01603     is_char = (i==1); /* see words_basic() */
01604     }
01605   }
01606   return is_char;
01607 }

Here is the caller graph for this function:

bool check_C_function_type ( entity  f,
list  args 
)

Check that an effective parameter list is compatible with a function type.

Or improve the function type when it is not precise as with "extern int f()". This is (a bit/partially) redundant with undeclared function detection since undeclared functions are declared "extern int f()".

FI: well, for debugging only...

Use parms to improve the type of f, probably declared f() with no type information.

Should be very similar to call_to_functional_type().

Must be a typedef or a pointer to a function. No need to refine the type

Check type compatibility: find function in flint? type_equal_p() requires lots of extensions to handle C types. And you would probably need type conversion to concrete type.

Parameters:
args rgs

Definition at line 2523 of file type.c.

References b, c_text_entity(), call_compatible_type(), call_compatible_type_p(), CAR, CONS, DEFAULT_INTEGER_TYPE_SIZE, ENDP, entity_type, entity_user_name(), EXPRESSION, expression_to_user_type(), FALSE, functional_parameters, functional_result, gen_length(), gen_nconc(), get_current_module_entity(), ifdebug, make_basic_int(), make_dummy_unknown(), make_mode_value(), make_parameter(), make_type_variable(), make_variable(), MAP, NIL, ok, PARAMETER, parameter_type, pips_assert, pips_debug, pips_user_warning, pl, print_text(), TRUE, type_functional, type_functional_p, type_unknown_p, and type_void_p.

Referenced by MakeFunctionExpression().

02524 {
02525   bool ok = TRUE;
02526   type t = entity_type(f);
02527   type ct = call_compatible_type(t);
02528   list parms = functional_parameters(type_functional(ct));
02529   extern void print_text(FILE *, text); /* FI: well, for debugging only... */
02530 
02531   pips_assert("f can be used to generate a call", call_compatible_type_p(t));
02532 
02533   if(ENDP(parms)) {
02534     if(ENDP(args))
02535       ;
02536     else {
02537       if(type_functional_p(t)) {
02538         /* Use parms to improve the type of f, probably declared f()
02539            with no type information. */
02540         /* Should be very similar to call_to_functional_type(). */
02541         list pl = NIL;
02542         MAP(EXPRESSION, e, {
02543             type et = expression_to_user_type(e);
02544             parameter p = make_parameter(et, make_mode_value(), make_dummy_unknown());
02545             pl = gen_nconc(pl, CONS(PARAMETER, p, NIL));
02546           },
02547           args);
02548         functional_parameters(type_functional(t)) = pl;
02549 
02550         if(type_unknown_p(functional_result(type_functional(t)))) {
02551           basic b = make_basic_int(DEFAULT_INTEGER_TYPE_SIZE);
02552           functional_result(type_functional(t)) = make_type_variable(make_variable(b, NIL, NIL));
02553         }
02554 
02555         pips_user_warning("Type updated for function \"%s\"\n", entity_user_name(f));
02556         ifdebug(8) {
02557           text txt = c_text_entity(get_current_module_entity(), f, 0);
02558           print_text(stderr, txt);
02559         }
02560       }
02561       else {
02562         /* Must be a typedef or a pointer to a function. No need to refine the type*/
02563         ifdebug(8) {
02564           text txt = c_text_entity(get_current_module_entity(), f, 0);
02565           pips_debug(8, "Type not updated for function \"%s\"\n", entity_user_name(f));
02566           print_text(stderr, txt);
02567         }
02568       }
02569     }
02570   }
02571   else if(gen_length(args)!=gen_length(parms)) {
02572     if(gen_length(args)==0 && gen_length(parms)==1) {
02573       parameter p = PARAMETER(CAR(parms));
02574       type pt = parameter_type(p);
02575       ok = type_void_p(pt);
02576     }
02577     else
02578       ok = FALSE;
02579   }
02580   else {
02581     /* Check type compatibility: find function in flint?
02582        type_equal_p() requires lots of extensions to handle C
02583        types. And you would probably need type conversion to concrete
02584        type.*/
02585     ;
02586   }
02587 
02588   return ok;
02589 }

Here is the call graph for this function:

Here is the caller graph for this function:

list constant_expression_supporting_entities ( list  sel,
expression  e 
)

C version.

Parameters:
sel el

Definition at line 2068 of file type.c.

References generic_constant_expression_supporting_entities(), and TRUE.

Referenced by enum_supporting_entities(), and variable_type_supporting_entities().

02069 {
02070   return generic_constant_expression_supporting_entities(sel, e, TRUE);
02071 }

Here is the call graph for this function:

Here is the caller graph for this function:

list constant_expression_supporting_references ( list  srl,
expression  e 
)

Only applicable to C expressions.

We need to know if we are dealing with C or Fortran code.

In C, f cannot be declared directly, we need its enum

But in Fortran, we are done

FI: suggested kludge: use a Fortran incompatible type for enum member. But currently they are four byte signed integer (c89) and this Fortran INTEGER type :-(

Could be guarded so as not to be added twice. Guard might be useless with because types are visited only once.

do nothing for the time being...

Parameters:
srl rl

Definition at line 2282 of file type.c.

References c, call_arguments, call_function, CONS, constant_expression_supporting_references(), enum_supporting_references(), EXPRESSION, expression_syntax, f, find_enum_of_member(), fprintf(), gen_nconc(), ifdebug, MAP, NIL, pips_debug, print_references(), REFERENCE, reference_indices, s, symbolic_constant_entity_p(), syntax_call, syntax_call_p, syntax_reference, and syntax_reference_p.

Referenced by constant_expression_supporting_references(), enum_supporting_references(), symbolic_supporting_references(), and variable_type_supporting_references().

02283 {
02284   syntax s = expression_syntax(e);
02285 
02286   ifdebug(9) {
02287     pips_debug(8, "Begin: ");
02288     print_references(srl);
02289     fprintf(stderr, "\n");
02290   }
02291 
02292   if(syntax_call_p(s)) {
02293     call c = syntax_call(s);
02294     entity f = call_function(c);
02295 
02296     if(symbolic_constant_entity_p(f)) {
02297       /* We need to know if we are dealing with C or Fortran code. */
02298       /* In C, f cannot be declared directly, we need its enum */
02299       /* But in Fortran, we are done */
02300       /* FI: suggested kludge: use a Fortran incompatible type for
02301          enum member. But currently they are four byte signed integer (c89)
02302          and this Fortran INTEGER type :-( */
02303 
02304       extern entity find_enum_of_member(entity);
02305       entity e_of_f = find_enum_of_member(f);
02306       //srl = CONS(ENTITY, e_of_f, srl);
02307       srl = enum_supporting_references(srl, e_of_f);
02308     }
02309 
02310     MAP(EXPRESSION, se, {
02311       srl = constant_expression_supporting_references(srl, se);
02312     }, call_arguments(c));
02313   }
02314   else if(syntax_reference_p(s)) {
02315     reference r = syntax_reference(s);
02316     list inds = reference_indices(r);
02317     /* Could be guarded so as not to be added twice. Guard might be
02318        useless with because types are visited only once. */
02319     srl = gen_nconc(srl, CONS(REFERENCE, r, NIL));
02320     MAP(EXPRESSION, se, {
02321         srl = constant_expression_supporting_references(srl, se);
02322       }, inds);
02323   }
02324   else {
02325     /* do nothing for the time being... */
02326     ;
02327   }
02328 
02329   ifdebug(9) {
02330     pips_debug(8, "End: ");
02331     print_references(srl);
02332     fprintf(stderr, "\n");
02333   }
02334 
02335   return srl;
02336 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool derived_type_p ( type  t  ) 

Returns TRUE if t is of type struct, union or enum.

Need to distinguish with the case struct/union/enum in type in RI, these are the definitions of the struct/union/enum themselve, not a variable of this type.

Example : struct foo var;

Definition at line 1660 of file type.c.

References basic_derived_p, NIL, type_variable, type_variable_p, variable_basic, and variable_dimensions.

Referenced by generic_c_words_entity().

01661 {
01662   return (type_variable_p(t) && basic_derived_p(variable_basic(type_variable(t))) 
01663           && (variable_dimensions(type_variable(t)) == NIL));
01664 }

Here is the caller graph for this function:

dimension dimension_dup ( dimension  d  ) 

Definition at line 643 of file type.c.

References dimension_lower, dimension_upper, expression_dup(), and make_dimension().

Referenced by ldimensions_dup().

00644 {
00645     return(make_dimension(expression_dup(dimension_lower(d)),
00646                           expression_dup(dimension_upper(d))));
00647 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool dimension_equal_p ( dimension  d1,
dimension  d2 
)

same values

and same names...

Parameters:
d1 1
d2 2

Definition at line 352 of file type.c.

References dimension_lower, dimension_upper, same_expression_name_p(), and same_expression_p().

Referenced by variable_equal_p().

00355 {
00356     return /* same values */
00357         same_expression_p(dimension_lower(d1), dimension_lower(d2)) &&
00358         same_expression_p(dimension_upper(d1), dimension_upper(d2)) &&
00359         /* and same names... */
00360         same_expression_name_p(dimension_lower(d1), dimension_lower(d2)) &&
00361         same_expression_name_p(dimension_upper(d1), dimension_upper(d2));
00362 }

Here is the call graph for this function:

Here is the caller graph for this function:

int effect_basic_depth ( basic  b  ) 

Definition at line 2709 of file type.c.

References basic_derived, basic_pointer, basic_tag, basic_typedef, effect_type_depth(), entity_type, is_basic_bit, is_basic_complex, is_basic_derived, is_basic_float, is_basic_int, is_basic_logical, is_basic_overloaded, is_basic_pointer, is_basic_string, is_basic_typedef, pips_internal_error, and type_depth().

Referenced by effect_type_depth().

02710 {
02711   int d = 0;
02712 
02713   switch(basic_tag(b)) {
02714   case is_basic_int:
02715   case is_basic_float:
02716   case is_basic_logical:
02717   case is_basic_overloaded:
02718   case is_basic_complex:
02719   case is_basic_string:
02720   case is_basic_bit:
02721     break;
02722   case is_basic_pointer:
02723     {
02724       d = effect_type_depth(basic_pointer(b))+1;
02725       break;
02726     }
02727   case is_basic_derived:
02728     {
02729       entity e = basic_derived(b);
02730       type t = entity_type(e);
02731       d = type_depth(t);
02732       break;
02733     }
02734   case is_basic_typedef:
02735     {
02736       entity e = basic_typedef(b);
02737       type t = entity_type(e);
02738 
02739       d = type_depth(t);
02740       break;
02741     }
02742   default:
02743     pips_internal_error("Unexpected basic tag %d\n", basic_tag(b));
02744   }
02745 
02746   return d;
02747 }

Here is the call graph for this function:

Here is the caller graph for this function:

int effect_type_depth ( type  t  ) 

Number of steps to access the lowest leave of type t.

Number of dimensions for an array. One for a struct or an union field, plus its dimension. The difference with type_depth is that it does not stop recursing when encountering a pointer, and that a pointer is considered as having dimension 1. (BC)

Definition at line 2672 of file type.c.

References effect_basic_depth(), ENTITY, entity_type, gen_length(), i, MAP, type_depth(), type_enum_p, type_struct, type_struct_p, type_union, type_union_p, type_varargs_p, type_variable, type_variable_p, type_void_p, v, variable_basic, and variable_dimensions.

Referenced by c_actual_argument_to_may_summary_effects(), and effect_basic_depth().

02673 {
02674   int d = 0;
02675 
02676   if(type_variable_p(t)) {
02677     variable v = type_variable(t);
02678 
02679     d = gen_length(variable_dimensions(v))+effect_basic_depth(variable_basic(v));
02680   }
02681   else if(type_void_p(t))
02682     d = 0;
02683   else if(type_varargs_p(t))
02684     d = 0;
02685   else if(type_struct_p(t)) {
02686     list fl = type_struct(t);
02687     d = 0;
02688     MAP(ENTITY, e, {
02689         int i = type_depth(entity_type(e));
02690         d = d>i?d:i;
02691       }, fl);
02692     d++;
02693   }
02694   else if(type_union_p(t)) {
02695     list fl = type_union(t);
02696     d = 0;
02697     MAP(ENTITY, e, {
02698         int i = type_depth(entity_type(e));
02699         d = d>i?d:i;
02700       }, fl);
02701     d++;
02702   }
02703   else if(type_enum_p(t))
02704     d = 0;
02705 
02706   return d;
02707 }

Here is the call graph for this function:

Here is the caller graph for this function:

list enum_supporting_entities ( list  sel,
entity  e 
)

Parameters:
sel el

Definition at line 1972 of file type.c.

References CAR, constant_expression_supporting_entities(), ENDP, ENTITY, entity_initial, entity_type, fprintf(), ifdebug, list_undefined, pips_assert, pips_debug, POP, print_entities(), s, symbolic_expression, type_enum, type_enum_p, v, value_symbolic, and value_symbolic_p.

Referenced by generic_constant_expression_supporting_entities().

01973 {
01974   type t = entity_type(e);
01975   list ml = type_enum(t);
01976   list cm = list_undefined;
01977 
01978   pips_assert("type is of enum kind", type_enum_p(t));
01979 
01980   ifdebug(8) {
01981     pips_debug(8, "Begin: ");
01982     print_entities(sel);
01983     fprintf(stderr, "\n");
01984   }
01985 
01986   for(cm = ml; !ENDP(cm); POP(cm)) {
01987     entity m = ENTITY(CAR(cm));
01988     value v = entity_initial(m);
01989     symbolic s = value_symbolic(v);
01990 
01991     pips_assert("m is an enum member", value_symbolic_p(v));
01992 
01993     sel = constant_expression_supporting_entities(sel, symbolic_expression(s));
01994   }
01995 
01996   ifdebug(8) {
01997     pips_debug(8, "End: ");
01998     print_entities(sel);
01999     fprintf(stderr, "\n");
02000   }
02001 
02002   return sel;
02003 }

Here is the call graph for this function:

Here is the caller graph for this function:

list enum_supporting_references ( list  srl,
entity  e 
)

Parameters:
srl rl

Definition at line 2248 of file type.c.

References CAR, constant_expression_supporting_references(), ENDP, ENTITY, entity_initial, entity_type, fprintf(), ifdebug, list_undefined, pips_assert, pips_debug, POP, print_references(), s, symbolic_expression, type_enum, type_enum_p, v, value_symbolic, and value_symbolic_p.

Referenced by constant_expression_supporting_references().

02249 {
02250   type t = entity_type(e);
02251   list ml = type_enum(t);
02252   list cm = list_undefined;
02253 
02254   pips_assert("type is of enum kind", type_enum_p(t));
02255 
02256   ifdebug(9) {
02257     pips_debug(8, "Begin: ");
02258     print_references(srl);
02259     fprintf(stderr, "\n");
02260   }
02261 
02262   for(cm = ml; !ENDP(cm); POP(cm)) {
02263     entity m = ENTITY(CAR(cm));
02264     value v = entity_initial(m);
02265     symbolic s = value_symbolic(v);
02266 
02267     pips_assert("m is an enum member", value_symbolic_p(v));
02268 
02269     srl = constant_expression_supporting_references(srl, symbolic_expression(s));
02270   }
02271 
02272   ifdebug(9) {
02273     pips_debug(8, "End: ");
02274     print_references(srl);
02275     fprintf(stderr, "\n");
02276   }
02277 
02278   return srl;
02279 }

Here is the call graph for this function:

Here is the caller graph for this function:

basic expression_basic ( expression  expr  ) 

should be int

How to void a memory leak? Where can we find a basic int? A static variable?

Parameters:
expr xpr

Definition at line 582 of file type.c.

References b, basic_undefined, c, call_function, cast_type, entity_basic(), expression_basic(), expression_syntax, is_basic_int, is_syntax_call, is_syntax_cast, is_syntax_range, is_syntax_reference, is_syntax_sizeofexpression, make_basic(), pips_assert, pips_internal_error, range_lower, reference_variable, syntax_call, syntax_cast, syntax_range, syntax_reference, syntax_tag, type_variable, type_variable_p, ultimate_type(), and variable_basic.

Referenced by change_basic_if_needed(), expression_basic(), please_give_me_a_basic_for_an_expression(), suggest_basic_for_expression(), and words_nullary_op_c().

00583 {
00584     syntax the_syntax=expression_syntax(expr);
00585     basic b = basic_undefined;
00586 
00587     switch(syntax_tag(the_syntax))
00588     {
00589     case is_syntax_reference:
00590         b = entity_basic(reference_variable(syntax_reference(the_syntax)));
00591         break;
00592     case is_syntax_range:
00593         /* should be int */
00594         b = expression_basic(range_lower(syntax_range(the_syntax)));
00595         break;
00596     case is_syntax_call:
00597         /*
00598          * here is a little problem with pips...
00599          * every intrinsics are overloaded, what is not 
00600          * exactly what is desired...
00601          */
00602         return(entity_basic(call_function(syntax_call(the_syntax))));
00603         break;
00604     case is_syntax_cast:
00605       {
00606         cast c = syntax_cast(the_syntax);
00607         type t = cast_type(c);
00608         type ut = ultimate_type(t);
00609         b = variable_basic(type_variable(ut));
00610         pips_assert("Type is \"variable\"", type_variable_p(ut));
00611       break;
00612       }
00613     case is_syntax_sizeofexpression:
00614       {
00615         /* How to void a memory leak? Where can we find a basic int? A static variable? */
00616         b = make_basic(is_basic_int, (void *) 4);
00617       break;
00618       }
00619     default:
00620         pips_internal_error("unexpected syntax tag\n");
00621         break;
00622     }
00623 
00624     return b;
00625 }

Here is the call graph for this function:

Here is the caller graph for this function:

type expression_to_type ( expression  e  ) 

Replace typedef'ed types by combinations of basic types.

does not cover references to functions ...

Could be more elaborated with array types for array expressions

Definition at line 918 of file type.c.

References b, basic_of_expression(), is_type_variable, make_type(), make_variable(), NIL, type_undefined, and v.

Referenced by c_actual_argument_to_may_summary_effects(), c_summary_effect_to_proper_effects(), c_user_call_to_transformer(), EvalSizeofexpression(), expression_to_transformer(), and integer_expression_and_precondition_to_integer_interval().

00919 {
00920   /* does not cover references to functions ...*/
00921   /* Could be more elaborated with array types for array expressions */
00922   type t =