PIPS
clean.c File Reference
#include <stdio.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "misc.h"
#include "ri-util.h"
+ Include dependency graph for clean.c:

Go to the source code of this file.

Functions

static void set_current_function (entity function)
 
static bool local_entity_of_current_function_p (entity e)
 
void GenericCleanEntities (list el, entity function, bool fortran_p)
 Useful when the user edit a source file and parse it again or when a program transformation is performed by prettyprinting and reparsing. More...
 
void GenericCleanLocalEntities (entity function, bool fortran_p)
 
void CleanLocalEntities (entity function)
 Fortran version. More...
 
void CCleanLocalEntities (entity function)
 C language version. More...
 
void RemoveLocalEntities (entity function)
 Useful for ParserError()? More...
 

Variables

static entity current_function = entity_undefined
 
static const char * current_function_local_name = NULL
 

Function Documentation

◆ CCleanLocalEntities()

void CCleanLocalEntities ( entity  function)

C language version.

Parameters
functionunction

Definition at line 146 of file clean.c.

147 {
148  GenericCleanLocalEntities(function, false);
149 }
void GenericCleanLocalEntities(entity function, bool fortran_p)
Definition: clean.c:123

References GenericCleanLocalEntities().

Referenced by MakeCurrentModule().

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

◆ CleanLocalEntities()

void CleanLocalEntities ( entity  function)

Fortran version.

Parameters
functionunction

Definition at line 140 of file clean.c.

141 {
142  GenericCleanLocalEntities(function, true);
143 }

References GenericCleanLocalEntities().

Referenced by AbortEntries(), c_parser_error(), MakeCurrentFunction(), and ParserError().

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

◆ GenericCleanEntities()

void GenericCleanEntities ( list  el,
entity  function,
bool  fortran_p 
)

Useful when the user edit a source file and parse it again or when a program transformation is performed by prettyprinting and reparsing.

clean.c

FI: A memory leak is better than a dangling pointer?

My explanation: CleanLocalEntities is called by MakeCurrentFunction when the begin_inst rule is reduced; by that time, the module entity and its formal parameters have already been parsed and allocated... but they are not yet fully initialized; thus the gen_full_free is a killer while the undefinitions are ok.

en_full_free_list(function_local_entities);

In C, parameter typing may have already occured and the return entity may be already defined. They must be preserved.

free_type(entity_type(e));

free_storage(entity_storage(e));

free_value(entity_initial(e));

In C, the entity must be removed from the declarations and from the symbol table

Parameters
ell
functionunction
fortran_portran_p

Definition at line 63 of file clean.c.

64 {
65  /* FI: A memory leak is better than a dangling pointer? */
66  /* My explanation: CleanLocalEntities is called by MakeCurrentFunction when
67  * the begin_inst rule is reduced; by that time, the module entity and its
68  * formal parameters have already been parsed and allocated... but they
69  * are not yet fully initialized; thus the gen_full_free is a killer while
70  * the undefinitions are ok.
71  */
72  /*gen_full_free_list(function_local_entities);*/
73 
74  list pe = list_undefined;
75 
76  for(pe=el; !ENDP(pe); POP(pe)) {
77  entity e = ENTITY(CAR(pe));
78  storage s = entity_storage(e);
79 
80  pips_debug(8, "Clean up %s?\n", entity_local_name(e));
81 
82  if(!storage_undefined_p(s) && storage_ram_p(s)) {
83  entity sec = ram_section(storage_ram(s));
84  type t = entity_type(sec);
85  if(!type_undefined_p(t)) {
86  pips_assert("t is an area", type_area_p(t));
88  }
89  }
90 
91  /* In C, parameter typing may have already occured and the return
92  entity may be already defined. They must be preserved. */
93  if(fortran_p
97  pips_debug(8, "Clean up %s? YES\n", entity_local_name(e));
98  if(!type_undefined_p(entity_type(e))) {
99  /* free_type(entity_type(e)); */
101  }
103  /* free_storage(entity_storage(e)); */
105  }
107  /* free_value(entity_initial(e)); */
109  }
110  if(!fortran_p) {
111  /* In C, the entity must be removed from the declarations and
112  from the symbol table */
114  free_entity(e);
115  }
116  }
117  else {
118  pips_debug(8, "Clean up %s? NO\n", entity_local_name(e));
119  }
120  }
121 }
void free_entity(entity p)
Definition: ri.c:2524
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
void gen_remove(list *cpp, const void *o)
remove all occurences of item o from list *cpp, which is thus modified.
Definition: list.c:685
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define list_undefined
Undefined list definition :-)
Definition: newgen_list.h:69
#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_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
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
#define value_undefined_p(x)
Definition: ri.h:3017
#define value_undefined
Definition: ri.h:3016
#define storage_formal_p(x)
Definition: ri.h:2522
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define entity_storage(x)
Definition: ri.h:2794
#define code_declarations(x)
Definition: ri.h:784
#define storage_ram_p(x)
Definition: ri.h:2519
#define ram_section(x)
Definition: ri.h:2249
#define type_undefined_p(x)
Definition: ri.h:2884
#define area_layout(x)
Definition: ri.h:546
#define value_code(x)
Definition: ri.h:3067
#define type_area(x)
Definition: ri.h:2946
#define storage_ram(x)
Definition: ri.h:2521
#define type_undefined
Definition: ri.h:2883
#define type_area_p(x)
Definition: ri.h:2944
#define entity_type(x)
Definition: ri.h:2792
#define storage_return_p(x)
Definition: ri.h:2516
#define storage_undefined_p(x)
Definition: ri.h:2477
#define storage_undefined
Definition: ri.h:2476
#define entity_initial(x)
Definition: ri.h:2796
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References area_layout, CAR, code_declarations, ENDP, ENTITY, entity_initial, entity_local_name(), entity_storage, entity_type, free_entity(), gen_remove(), list_undefined, pips_assert, pips_debug, POP, ram_section, storage_formal_p, storage_ram, storage_ram_p, storage_return_p, storage_undefined, storage_undefined_p, type_area, type_area_p, type_undefined, type_undefined_p, value_code, value_undefined, and value_undefined_p.

Referenced by clean_up_points_to_stubs(), and GenericCleanLocalEntities().

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

◆ GenericCleanLocalEntities()

void GenericCleanLocalEntities ( entity  function,
bool  fortran_p 
)
Parameters
functionunction
fortran_portran_p

Definition at line 123 of file clean.c.

124 {
125  list function_local_entities = NIL;
126  //list pe = NIL;
127 
128  set_current_function(function);
129 
130  function_local_entities =
132  entity_domain);
133 
134  GenericCleanEntities(function_local_entities, function, fortran_p);
135 
136  gen_free_list(function_local_entities);
137 }
void GenericCleanEntities(list el, entity function, bool fortran_p)
Useful when the user edit a source file and parse it again or when a program transformation is perfor...
Definition: clean.c:63
static void set_current_function(entity function)
Definition: clean.c:42
static bool local_entity_of_current_function_p(entity e)
Definition: clean.c:53
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
list gen_filter_tabulated(bool(*)(gen_chunk *), int)
returns the list of entities with this caracteristics.
Definition: tabulated.c:144
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410

References entity_domain, gen_filter_tabulated(), gen_free_list(), GenericCleanEntities(), local_entity_of_current_function_p(), NIL, and set_current_function().

Referenced by CCleanLocalEntities(), and CleanLocalEntities().

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

◆ local_entity_of_current_function_p()

static bool local_entity_of_current_function_p ( entity  e)
static

Definition at line 53 of file clean.c.

55 {
57 }
static const char * current_function_local_name
Definition: clean.c:39
#define same_string_p(s1, s2)
const char * entity_module_name(entity e)
See comments about module_name().
Definition: entity.c:1092

References current_function_local_name, entity_module_name(), and same_string_p.

Referenced by GenericCleanLocalEntities(), and RemoveLocalEntities().

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

◆ RemoveLocalEntities()

void RemoveLocalEntities ( entity  function)

Useful for ParserError()?

FI: dangling pointers? Some variables may be referenced in area_layouts of global common entities!

gen_full_free_list(function_local_entities);

A gen_multi_recurse would be required but it's hard to be at the list level to remove the elements?!?

Parameters
functionunction

Definition at line 152 of file clean.c.

154 {
155 
156  set_current_function(function);
157 
158 #if 0
159  list function_local_entities =
161  entity_domain);
162 #endif
163 
164  /* FI: dangling pointers? Some variables may be referenced in area_layouts of
165  global common entities! */
166  /* gen_full_free_list(function_local_entities); */
167  /* A gen_multi_recurse would be required but it's hard to be at the
168  list level to remove the elements?!? */
169  pips_assert("implemented", false);
170 }

References entity_domain, gen_filter_tabulated(), local_entity_of_current_function_p(), pips_assert, and set_current_function().

+ Here is the call graph for this function:

◆ set_current_function()

static void set_current_function ( entity  function)
static

Definition at line 42 of file clean.c.

44 {
45  pips_assert("set_current_function", top_level_entity_p(function)
47  current_function = function;
49 }
static entity current_function
Definition: clean.c:38
bool compilation_unit_p(const char *module_name)
The names of PIPS entities carry information about their nature.
Definition: entity_names.c:56
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
bool top_level_entity_p(entity e)
Check if the scope of entity e is global.
Definition: entity.c:1130

References compilation_unit_p(), current_function, current_function_local_name, entity_module_name(), module_local_name(), pips_assert, and top_level_entity_p().

Referenced by GenericCleanLocalEntities(), and RemoveLocalEntities().

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

Variable Documentation

◆ current_function

entity current_function = entity_undefined
static

Definition at line 38 of file clean.c.

Referenced by set_current_function().

◆ current_function_local_name

const char* current_function_local_name = NULL
static

Definition at line 39 of file clean.c.

Referenced by local_entity_of_current_function_p(), and set_current_function().