PIPS
naming.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "linear.h"
#include "genC.h"
#include "misc.h"
#include "ri.h"
#include "properties.h"
#include "ri-util.h"
#include "workspace-util.h"
+ Include dependency graph for naming.c:

Go to the source code of this file.

Functions

const char * entity_module_unambiguous_user_name (entity e, entity m)
 Functions using simultaneously pipsdbm, which is based on strings, and ri-util, which contains basic methods for the objects of the internal representation. More...
 
const char * entity_unambiguous_user_name (entity e)
 
static const char * entity_more_or_less_minimal_name (entity e, bool strict_p)
 In interprocedural context, returns the shortest non-ambiguous name for a variable. More...
 
const char * entity_minimal_name (entity e)
 Do preserve scope informations. More...
 
const char * entity_minimal_user_name (entity e)
 Do not preserve scope information. More...
 
void print_arguments (list args)
 
entity string_to_entity (const char *s, entity module)
 very simple conversion from string to expression only handles entities and numeric values at the time being More...
 
list string_to_entities (const char *str, const char *seed, entity module)
 split a string using seed as separator and call string_to_entity on each chunk More...
 

Function Documentation

◆ entity_minimal_name()

const char* entity_minimal_name ( entity  e)

Do preserve scope informations.

This function does not allocate a new string, which implies to keep the scope information in the name of extraprocedural variables and functions.

Definition at line 214 of file naming.c.

215 {
216  return entity_more_or_less_minimal_name(e, true);
217 }
static const char * entity_more_or_less_minimal_name(entity e, bool strict_p)
In interprocedural context, returns the shortest non-ambiguous name for a variable.
Definition: naming.c:107

References entity_more_or_less_minimal_name().

Referenced by DisplayDad(), effect_words_reference(), flint_check_uninitialized_variables_in_statement(), flint_initialize_statement_def_use_variables(), generic_value_name(), pips_region_user_name(), pips_user_value_name(), print_arguments(), print_value_mappings(), region_translation(), text_transformer(), and variable_local_name().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ entity_minimal_user_name()

const char* entity_minimal_user_name ( entity  e)

Do not preserve scope information.

A new string is allocated.

Definition at line 223 of file naming.c.

224 {
225  return entity_more_or_less_minimal_name(e, false);
226 }

References entity_more_or_less_minimal_name().

Referenced by equal_must_vreference(), is_entity_in_list(), opkill_may_vreference(), opkill_must_vreference(), points_to_compare_cell(), points_to_compare_cells(), points_to_compare_location(), points_to_compare_ptr_cell(), points_to_words_reference(), remove_from_effective_parameters(), and remove_from_formal_parameters().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ entity_module_unambiguous_user_name()

const char* entity_module_unambiguous_user_name ( entity  e,
entity  m 
)

Functions using simultaneously pipsdbm, which is based on strings, and ri-util, which contains basic methods for the objects of the internal representation.

Warning! Do not modify this file that is automatically generated!

Based on entity_user_name, but preserves scoping information when needed to avoid ambiguity between two or more variables with the same name.

A variable or function name can be used for an external or static entity in the compilation unit, it can be used as function parameter, and then declared within the function at any scope level.

This function cannot directly be used in an interprocedural setting as it is only related to one module.

It is assumed that no new string is allocated, but a pointer to an existing string is returned.

The current implementation is extremely ineffective, especially for a very unlikely, although mystifying, problem.

FI: this function does not seem to be used in Libs or Passes. Its implementation is based on module_entities(), which is not in ri-util...

No problem in Fortran

Definition at line 68 of file naming.c.

69 {
70  const char* uan = entity_user_name(e);
71 
72  /* No problem in Fortran */
73  if(c_module_p(m)) {
74  list conflicts = module_entities(m);
75 
76  FOREACH(ENTITY, v, conflicts){
77  if(v!=e) {
78  const char* vn = entity_user_name(v);
79  if(same_string_p(uan,vn)) {
80  uan = entity_local_name(e);
81  break;
82  }
83  }
84  }
85  gen_free_list(conflicts);
86  }
87 
88  return (uan);
89 }
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
#define same_string_p(s1, s2)
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
Definition: entity.c:453
bool c_module_p(entity m)
Test if a module "m" is written in C.
Definition: entity.c:2777
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
list module_entities(entity m)
Return a list of all variables and functions accessible somewhere in a module.
Definition: module.c:85

References c_module_p(), ENTITY, entity_local_name(), entity_user_name(), FOREACH, gen_free_list(), module_entities(), and same_string_p.

Referenced by entity_unambiguous_user_name().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ entity_more_or_less_minimal_name()

static const char* entity_more_or_less_minimal_name ( entity  e,
bool  strict_p 
)
static

In interprocedural context, returns the shortest non-ambiguous name for a variable.

If it is local to the current module, use the user name. If not return entity_name(), which is not fully satisfying for C variables because it includes scope information.

Note also that this function assumes the existence of a current module.

FI: why is this function in preprocessor and not in ri-util?

in pipsmake library...

gen_in_list_p() would/should be sufficient...

The variable is declared in the current module

The variable is declared in the compilation unit of the current module

The variable is a union or struct field. No need to disambiguate.

Formal parameters should always be unambiguous?

The variable is a dummy parameter entity, used in a function declaration

In analysis results, let's know when dummy parameters are used...

The variable is a ???

The variable is a PHI entity

The variable is a stub entity for formal and global pointers

must be used to prettyprint interprocedural information...

Definition at line 107 of file naming.c.

108 {
110  const char* mln = module_local_name(m);
111  const char* emn = string_undefined;
112  string cun = string_undefined; // compilation unit name
113  entity cu = entity_undefined; // compilation unit
114  list cudl = list_undefined; // compilation unit declaration list
116 
117  if(c_module_p(m) && !compilation_unit_p(mln)) {
118  /* in pipsmake library...*/
119  string compilation_unit_of_module(const char*);
120  cun = compilation_unit_of_module(mln);
123  free(cun);
124  }
125 
126  pips_assert("some current entity", !entity_undefined_p(m));
127 
128  /* gen_in_list_p() would/should be sufficient... */
129  if (strcmp(mln, entity_module_name(e)) == 0
130  || gen_in_list_p(e, mdl)) {
131  /* The variable is declared in the current module */
132  //return global_name_to_user_name(entity_name(e));
133  if(strict_p)
135  else
136  emn = entity_user_name(e);
137  }
138  else if (!list_undefined_p(cudl) && gen_in_list_p(e, cudl)) {
139  /* The variable is declared in the compilation unit of the current
140  module */
141  //return global_name_to_user_name(entity_name(e));
142  if(strict_p)
144  else
145  emn = entity_user_name(e);
146  }
147  else if (entity_field_p(e)) {
148  /* The variable is a union or struct field. No need to
149  disambiguate. */
150  if(strict_p)
152  else
153  emn = entity_user_name(e);
154  }
155  else if (entity_formal_p(e)) {
156  /* Formal parameters should always be unambiguous? */
157  if(strict_p)
159  else
160  emn = entity_user_name(e);
161  }
162  else if (strstr(entity_module_name(e), DUMMY_PARAMETER_PREFIX)) {
163  /* The variable is a dummy parameter entity, used in a function
164  declaration */
165  if(strict_p)
166  emn = entity_local_name(e);
167  else {
168  /* In analysis results, let's know when dummy parameters are
169  used... */
170  //emn = strdup(entity_local_name(e));
171  emn = strdup(entity_name(e));
172  }
173  }
174  else if (strcmp(TOP_LEVEL_MODULE_NAME, entity_module_name(e)) == 0) {
175  /* The variable is a ??? */
176  if(strict_p)
177  emn = entity_local_name(e);
178  else
179  emn = strdup(entity_local_name(e));
180  }
181  else if (strcmp(REGIONS_MODULE_NAME, entity_module_name(e)) == 0) {
182  /* The variable is a PHI entity */
183  if(strict_p)
184  emn = entity_local_name(e);
185  else
186  emn = strdup(entity_local_name(e));
187  }
188  else if (strcmp(POINTS_TO_MODULE_NAME, entity_module_name(e)) == 0) {
189  /* The variable is a stub entity for formal and global pointers */
190  if(strict_p)
191  emn = entity_local_name(e);
192  else
193  emn = strdup(entity_local_name(e));
194  }
195  else {
196  /* must be used to prettyprint interprocedural information... */
197  //entity om = local_name_to_top_level_entity(mln);
198  //emn = entity_interprocedural_unambiguous_user_name(e, om);
199  if(strict_p)
200  emn = entity_name(e);
201  else
202  emn = strdup(entity_name(e));
203  }
204 
205  return emn;
206 }
string compilation_unit_of_module(const char *)
The output is undefined if the module is referenced but not defined in the workspace,...
Definition: module.c:350
bool compilation_unit_p(const char *module_name)
The names of PIPS entities carry information about their nature.
Definition: entity_names.c:56
void free(void *)
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
#define list_undefined_p(c)
Return if a list is undefined.
Definition: newgen_list.h:75
bool gen_in_list_p(const void *vo, const list lx)
tell whether vo belongs to lx
Definition: list.c:734
#define list_undefined
Undefined list definition :-)
Definition: newgen_list.h:69
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define DUMMY_PARAMETER_PREFIX
For dmmmy parameters in functions declarations.
Definition: naming-local.h:93
#define TOP_LEVEL_MODULE_NAME
Module containing the global variables in Fortran and C.
Definition: naming-local.h:101
#define POINTS_TO_MODULE_NAME
Module containing stub variables used to initialize intraprocedural points-to in C.
Definition: naming-local.h:104
const char * entity_unambiguous_user_name(entity e)
Definition: naming.c:91
#define string_undefined
Definition: newgen_types.h:40
#define REGIONS_MODULE_NAME
Already defined.
entity FindEntity(const char *package, const char *name)
Retrieve an entity from its package/module name and its local name.
Definition: entity.c:1503
bool entity_formal_p(entity p)
is p a formal parameter?
Definition: entity.c:1935
bool entity_field_p(entity e)
e is the field of a structure
Definition: entity.c:857
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
const char * entity_module_name(entity e)
See comments about module_name().
Definition: entity.c:1092
#define code_declarations(x)
Definition: ri.h:784
#define entity_undefined_p(x)
Definition: ri.h:2762
#define entity_undefined
Definition: ri.h:2761
#define entity_name(x)
Definition: ri.h:2790
#define value_code(x)
Definition: ri.h:3067
#define entity_initial(x)
Definition: ri.h:2796
char * strdup()

References c_module_p(), code_declarations, compilation_unit_of_module(), compilation_unit_p(), DUMMY_PARAMETER_PREFIX, entity_field_p(), entity_formal_p(), entity_initial, entity_local_name(), entity_module_name(), entity_name, entity_unambiguous_user_name(), entity_undefined, entity_undefined_p, entity_user_name(), FindEntity(), free(), gen_in_list_p(), get_current_module_entity(), list_undefined, list_undefined_p, module_local_name(), pips_assert, POINTS_TO_MODULE_NAME, REGIONS_MODULE_NAME, strdup(), string_undefined, TOP_LEVEL_MODULE_NAME, and value_code.

Referenced by entity_minimal_name(), and entity_minimal_user_name().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ entity_unambiguous_user_name()

const char* entity_unambiguous_user_name ( entity  e)

Definition at line 91 of file naming.c.

92 {
94 
96 }
const char * entity_module_unambiguous_user_name(entity e, entity m)
Functions using simultaneously pipsdbm, which is based on strings, and ri-util, which contains basic ...
Definition: naming.c:68

References entity_module_unambiguous_user_name(), and get_current_module_entity().

Referenced by entity_more_or_less_minimal_name().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print_arguments()

void print_arguments ( list  args)
Parameters
argsrgs

Definition at line 228 of file naming.c.

229 {
231 }
void print_homogeneous_arguments(list args, const char *variable_name(entity))
Functions dealing with entity lists.
Definition: arguments.c:54
const char * entity_minimal_name(entity e)
Do preserve scope informations.
Definition: naming.c:214

References entity_minimal_name(), and print_homogeneous_arguments().

Referenced by ComputeAddresses(), fuse_sequences_in_unstructured(), MakeEntryCommon(), recompute_loop_transformer(), TestDependence(), and update_common_layout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ string_to_entities()

list string_to_entities ( const char *  str,
const char *  seed,
entity  module 
)

split a string using seed as separator and call string_to_entity on each chunk

Parameters
strtr
seedeed
moduleodule

Definition at line 276 of file naming.c.

276  {
277  list strings = strsplit(str,seed);
278  list entities = NIL;
279  FOREACH(STRING,s,strings) {
281  if(!entity_undefined_p(e)) {
282  entities = CONS(ENTITY,
283  e,
284  entities);
285  }
286  }
287  gen_map(free,strings);
288  gen_free_list(strings);
289  return gen_nreverse(entities);
290 
291 }
#define STRING(x)
Definition: genC.h:87
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
void gen_map(gen_iter_func_t fp, const list l)
Definition: list.c:172
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
entity string_to_entity(const char *s, entity module)
very simple conversion from string to expression only handles entities and numeric values at the time...
Definition: naming.c:237
list strsplit(const char *, const char *)
Definition: string.c:318
static char * module
Definition: pips.c:74

References CONS, ENTITY, entity_undefined_p, FOREACH, free(), gen_free_list(), gen_map(), gen_nreverse(), module, NIL, STRING, string_to_entity(), and strsplit().

+ Here is the call graph for this function:

◆ string_to_entity()

entity string_to_entity ( const char *  s,
entity  module 
)

very simple conversion from string to expression only handles entities and numeric values at the time being

try float conversion

no negative integer entity in pips

first find all relevant entities

this an heuristic to find the one with a suiting scope error prone

try at the compilation unit level

try at top level

Parameters
moduleodule

Definition at line 237 of file naming.c.

238 {
239  if(empty_string_p(s)) return entity_undefined;
240 
241  /* try float conversion */
242  string endptr;
243  const char *module_name=module_local_name(module);
244  long int l = strtol(s,&endptr,10);
245  if(!*endptr) {
246  if(l>=0)
247  return int_to_entity(l);
248  else /* no negative integer entity in pips */
249  return entity_undefined;
250  }
251  float f = strtof(s,&endptr);
252  if(!*endptr) return float_to_entity(f);
253 
254  entity candidate = entity_undefined;
255  /* first find all relevant entities */
257  {
258  /* this an heuristic to find the one with a suiting scope
259  * error prone*/
261  if(entity_undefined_p(candidate) ||
262  strlen(entity_name(candidate)) > strlen(entity_name(e)))
263  candidate=e;
264  }
265  /* try at the compilation unit level */
266  if(entity_undefined_p(candidate))
268  /* try at top level */
269  if(entity_undefined_p(candidate))
270  candidate=FindEntity(TOP_LEVEL_MODULE_NAME,s);
271  return candidate;
272 }
entity float_to_entity(float c)
Definition: constant.c:430
entity int_to_entity(_int c)
Definition: constant.c:453
bool empty_string_p(const char *s)
Definition: entity_names.c:239
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
#define entity_declarations(e)
MISC: newgen shorthands.

References compilation_unit_of_module(), empty_string_p(), ENTITY, entity_declarations, entity_name, entity_undefined, entity_undefined_p, entity_user_name(), f(), FindEntity(), float_to_entity(), FOREACH, int_to_entity(), module, module_local_name(), module_name(), same_string_p, and TOP_LEVEL_MODULE_NAME.

Referenced by do_solve_hardware_constraints(), string_to_entities(), and string_to_expression().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: