PIPS
prettyprint.c File Reference
#include <stdlib.h>
#include "all.h"
#include "text-util.h"
#include "text.h"
#include "prettyprint.h"
#include "top-level.h"
+ Include dependency graph for prettyprint.c:

Go to the source code of this file.

Macros

#define REGION_BUFFER_SIZE   2048
 print complementary sections More...
 
#define REGION_FORESYS_PREFIX   "C$REG"
 
#define PIPS_NORMAL_PREFIX   "C"
 

Functions

static text text_statement_array_comp_regions (entity, int, statement)
 
static text text_array_comp_regions (list l_reg)
 }} More...
 
static bool print_code_with_comp_regions (const char *module_name, string resource_name, string summary_resource_name, string file_suffix)
 bool print_code_with_comp_regions(const char* module_name, list summary_comp_regions) input : the name of the current module, the name of the region and summary region resources and the file suffix the comp_regions are in the global variable local_regions_map. More...
 
static text get_any_comp_regions_text (const char *module_name, string resource_name, string summary_resource_name, bool give_code_p)
 {{ get any comp_regions text More...
 
text get_text_comp_regions (const char *module_name)
 }}} More...
 
bool print_source_comp_regions (char *module_name) const
 bool print_source_regions(const char* module_name) input : the name of the current module modifies : nothing. More...
 
bool print_code_comp_regions (char *module_name) const
 bool print_code_comp_regions(const char* module_name) input : the name of the current module modifies : nothing. More...
 
static text text_statement_array_comp_regions (entity __attribute__((unused)) module, int __attribute__((unused)) margin, statement stat)
 }} More...
 
text text_all_comp_regions (list l_reg)
 }} More...
 
text text_comp_regions (list l_reg)
 }} More...
 
text text_comp_region (effect reg)
 }} More...
 

Variables

static bool in_out_comp_regions_p = false
 {{{ function prototype More...
 
static bool is_user_view_p = false
 
static hash_table nts = hash_table_undefined
 

Macro Definition Documentation

◆ PIPS_NORMAL_PREFIX

#define PIPS_NORMAL_PREFIX   "C"

Definition at line 57 of file prettyprint.c.

◆ REGION_BUFFER_SIZE

#define REGION_BUFFER_SIZE   2048

print complementary sections

{{{ banner package comp_regions : Alexis Platonoff, 5 September 1990,
Beatrice Creusillet, April 1994


prettyprint.c

This file contains the functions specific to the prettyprinting of comp_regions. }}}

Definition at line 54 of file prettyprint.c.

◆ REGION_FORESYS_PREFIX

#define REGION_FORESYS_PREFIX   "C$REG"

Definition at line 56 of file prettyprint.c.

Function Documentation

◆ get_any_comp_regions_text()

static text get_any_comp_regions_text ( const char *  module_name,
string  resource_name,
string  summary_resource_name,
bool  give_code_p 
)
static

{{ get any comp_regions text

load comp_regions corresponding to the current module

change later

To set up the hash table to translate value into value names

prepare the prettyprinting

summary comp_regions first

then code with comp_regions, using text_array_comp_regions

Definition at line 154 of file prettyprint.c.

158 {
159  list summary_comp_regions;
160  entity module;
161  statement module_stat, user_stat = statement_undefined;
162  text txt = make_text(NIL);
163 
164  debug_on("COMP_REGIONS_DEBUG_LEVEL");
165 
166  /* load comp_regions corresponding to the current module */
167  /* change later */
168 
172  (resource_name, module_name, true)) );
173 
174  summary_comp_regions =
176  (summary_resource_name,
177  module_name, true));
178 
181 
183  (DBR_CODE, module_name, true));
184 
185  module_stat = get_current_module_statement();
186 
187  /* To set up the hash table to translate value into value names */
189  db_get_memory_resource(DBR_CUMULATED_EFFECTS, module_name, true));
191  db_get_memory_resource(DBR_PROPER_EFFECTS, module_name, true));
193 
194  if(is_user_view_p)
195  {
196  user_stat = (statement)
197  db_get_memory_resource(DBR_PARSED_CODE, module_name, true);
198 
200  nts = build_number_to_statement(nts, module_stat);
201 
202  ifdebug(5)
203  {
205  }
206  }
207 
208  /* prepare the prettyprinting */
209  /* summary comp_regions first */
211  MERGE_TEXTS(txt, text_array_comp_regions(summary_comp_regions));
212 
213  if (give_code_p)
214  /* then code with comp_regions, using text_array_comp_regions */
216  is_user_view_p? user_stat : module_stat));
217 
218  if(is_user_view_p)
219  {
222  }
223 
225 
226  debug_off();
227 
233 
234  return txt;
235 }
text make_text(list a)
Definition: text.c:107
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
static text text_array_comp_regions(list)
}}
Definition: prettyprint.c:284
static bool is_user_view_p
Definition: prettyprint.c:62
static text text_statement_array_comp_regions(entity, int, statement)
static hash_table nts
Definition: prettyprint.c:63
statement_mapping comp_secs_map_to_listmap(statement_mapping)
Definition: dbase.c:60
void free_local_comp_regions_map(void)
void set_local_comp_regions_map(statement_mapping)
list comp_desc_set_to_list(comp_desc_set)
Definition: dbase.c:40
#define resource_name(x)
Definition: database.h:108
void reset_proper_rw_effects(void)
void set_proper_rw_effects(statement_effects)
void set_cumulated_rw_effects(statement_effects)
void reset_cumulated_rw_effects(void)
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
void reset_current_module_statement(void)
Reset the current module statement.
Definition: static.c:221
statement set_current_module_statement(statement)
Set the current module statement.
Definition: static.c:165
statement get_current_module_statement(void)
Get the current module statement.
Definition: static.c:208
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
Definition: database.c:755
hash_table allocate_number_to_statement(void)
Definition: statement.c:1540
hash_table build_number_to_statement(hash_table, statement)
Definition: statement.c:1516
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
#define hash_table_undefined
Value of an undefined hash_table.
Definition: newgen_hash.h:49
static char * module
Definition: pips.c:74
void close_prettyprint()
because some prettyprint functions may be used for debug, so the last hook set by somebody may have s...
Definition: misc.c:242
void init_prettyprint(text(*hook)(entity, int, statement))
checks that the prettyprint hook was actually reset...
Definition: misc.c:231
text text_module(entity, statement)
void print_number_to_statement(hash_table)
Definition: statement.c:209
entity local_name_to_top_level_entity(const char *n)
This function try to find a top-level entity from a local name.
Definition: entity.c:1450
#define statement_undefined
Definition: ri.h:2419
void module_to_value_mappings(entity m)
void module_to_value_mappings(entity m): build hash tables between variables and values (old,...
Definition: mappings.c:624
#define ifdebug(n)
Definition: sg.c:47
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define MERGE_TEXTS(r, t)

References allocate_number_to_statement(), build_number_to_statement(), close_prettyprint(), comp_desc_set_to_list(), comp_secs_map_to_listmap(), db_get_memory_resource(), debug_off, debug_on, free_local_comp_regions_map(), get_current_module_entity(), get_current_module_statement(), hash_table_free(), hash_table_undefined, ifdebug, init_prettyprint(), is_user_view_p, local_name_to_top_level_entity(), make_text(), MERGE_TEXTS, module, module_name(), module_to_value_mappings(), NIL, nts, print_number_to_statement(), reset_cumulated_rw_effects(), reset_current_module_entity(), reset_current_module_statement(), reset_proper_rw_effects(), resource_name, set_cumulated_rw_effects(), set_current_module_entity(), set_current_module_statement(), set_local_comp_regions_map(), set_proper_rw_effects(), statement_undefined, text_array_comp_regions(), text_module(), and text_statement_array_comp_regions().

Referenced by get_text_comp_regions(), and print_code_with_comp_regions().

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

◆ get_text_comp_regions()

text get_text_comp_regions ( const char *  module_name)

}}}

prettyprint.c

Parameters
module_nameodule_name

Definition at line 72 of file prettyprint.c.

73 {
74  is_user_view_p = false;
75  in_out_comp_regions_p = false;
76 
78  DBR_REGIONS,
79  DBR_SUMMARY_REGIONS,
80  false);
81 }
static text get_any_comp_regions_text(const char *, string, string, bool)
{{ get any comp_regions text
Definition: prettyprint.c:154
static bool in_out_comp_regions_p
{{{ function prototype
Definition: prettyprint.c:61

References get_any_comp_regions_text(), in_out_comp_regions_p, is_user_view_p, and module_name().

+ Here is the call graph for this function:

◆ print_code_comp_regions()

bool print_code_comp_regions ( char*  module_name) const

bool print_code_comp_regions(const char* module_name) input : the name of the current module modifies : nothing.

comment : prints the source code with the corresponding regions.

Definition at line 107 of file prettyprint.c.

109 {
110  is_user_view_p = false;
111  in_out_comp_regions_p = false;
112 
114  DBR_COMPSEC,
115  DBR_SUMMARY_COMPSEC,
117 }
#define SEQUENTIAL_COMPSEC_SUFFIX
static bool print_code_with_comp_regions(const char *, string, string, string)
bool print_code_with_comp_regions(const char* module_name, list summary_comp_regions) input : the nam...
Definition: prettyprint.c:126

References in_out_comp_regions_p, is_user_view_p, module_name(), print_code_with_comp_regions(), and SEQUENTIAL_COMPSEC_SUFFIX.

+ Here is the call graph for this function:

◆ print_code_with_comp_regions()

static bool print_code_with_comp_regions ( const char *  module_name,
string  resource_name,
string  summary_resource_name,
string  file_suffix 
)
static

bool print_code_with_comp_regions(const char* module_name, list summary_comp_regions) input : the name of the current module, the name of the region and summary region resources and the file suffix the comp_regions are in the global variable local_regions_map.

modifies : nothing. comment : prints the source code with the corresponding comp_regions.

Definition at line 126 of file prettyprint.c.

130 {
131  char *file_name, *file_resource_name;
132 
133  file_name = strdup(concatenate(file_suffix,
135  ("PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH") ?
136  GRAPH_FILE_EXT : "",
137  NULL));
138  file_resource_name = get_bool_property("PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH") ?
139  DBR_GRAPH_PRINTED_FILE :
140  (is_user_view_p ? DBR_PARSED_PRINTED_FILE : DBR_PRINTED_FILE);
141 
142  bool success = make_text_resource(module_name, file_resource_name,
143  file_name,
146  summary_resource_name,
147  true));
148 
149  free(file_name);
150  return success ;
151 }
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
void free(void *)
bool success
Definition: gpips-local.h:59
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
bool make_text_resource(const char *, const char *, const char *, text)
print.c
Definition: print.c:55
char * strdup()
static string file_name

References concatenate(), file_name, free(), get_any_comp_regions_text(), get_bool_property(), is_user_view_p, make_text_resource(), module_name(), resource_name, and strdup().

Referenced by print_code_comp_regions(), and print_source_comp_regions().

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

◆ print_source_comp_regions()

bool print_source_comp_regions ( char*  module_name) const

bool print_source_regions(const char* module_name) input : the name of the current module modifies : nothing.

comment : prints the original source code with the corresponding regions.

Definition at line 89 of file prettyprint.c.

91 {
92  is_user_view_p = true;
93  in_out_comp_regions_p = false;
94 
96  DBR_REGIONS,
97  DBR_SUMMARY_REGIONS,
99 }
#define USER_REGION_SUFFIX

References in_out_comp_regions_p, is_user_view_p, module_name(), print_code_with_comp_regions(), and USER_REGION_SUFFIX.

+ Here is the call graph for this function:

◆ text_all_comp_regions()

text text_all_comp_regions ( list  l_reg)

}}

{{ text all comp_regions text text_all_comp_regions(list l_reg) input : a list of comp_regions output : a text representing this list (with non-array comp_regions)

Parameters
l_reg_reg

Definition at line 329 of file prettyprint.c.

331 {
332  text reg_text = make_text(NIL);
333 
334  MAP(EFFECT, reg,
335  {
336  MERGE_TEXTS(reg_text, text_region(reg));
337  },
338  l_reg);
339  return(reg_text);
340 }
text text_region(effect)
#define EFFECT(x)
EFFECT.
Definition: effects.h:608
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
Definition: newgen_list.h:226

References EFFECT, make_text(), MAP, MERGE_TEXTS, NIL, and text_region().

+ Here is the call graph for this function:

◆ text_array_comp_regions()

static text text_array_comp_regions ( list  l_reg)
static

}}

{{ text array comp_regions static text text_array_comp_regions(list l_reg) input : a list of comp_regions output : a text representing this list of comp_regions. comment : if the number of array comp_regions is not nul, and if PRETTYPRINT_LOOSE is true, then empty lines are added before and after the text of the list of comp_regions.

in case of loose_prettyprint, at least one region to print?

GO: No redundant test anymore, see text_statement_array_comp_regions

Definition at line 284 of file prettyprint.c.

286 {
287  text reg_text = make_text(NIL);
288  /* in case of loose_prettyprint, at least one region to print? */
289  bool loose_p = get_bool_property("PRETTYPRINT_LOOSE");
290  bool one_p = false;
291 
292  /* GO: No redundant test anymore, see text_statement_array_comp_regions */
293  if (l_reg != (list) HASH_UNDEFINED_VALUE && l_reg != list_undefined)
294  {
295 /*
296  MAP(COMP_DESC, reg,
297  {
298  entity ent = effect_entity(reg);
299  if ( get_bool_property("PRETTYPRINT_SCALAR_comp_regions") ||
300  ! entity_scalar_p(ent))
301  {
302  if (loose_p && !one_p )
303  {
304  ADD_SENTENCE_TO_TEXT(reg_text,
305  make_sentence(is_sentence_formatted,
306  strdup("\n")));
307  one_p = true;
308  }
309  MERGE_TEXTS(reg_text, text_comp_region(reg));
310  }
311  },
312  l_reg);
313  */
314 
315  if (loose_p && one_p)
316  ADD_SENTENCE_TO_TEXT(reg_text,
318  strdup("\n")));
319  }
320  return(reg_text);
321 }
sentence make_sentence(enum sentence_utype tag, void *val)
Definition: text.c:59
#define list_undefined
Undefined list definition :-)
Definition: newgen_list.h:69
#define HASH_UNDEFINED_VALUE
value returned by hash_get() when the key is not found; could also be called HASH_KEY_NOT_FOUND,...
Definition: newgen_hash.h:56
#define ADD_SENTENCE_TO_TEXT(t, p)
@ is_sentence_formatted
Definition: text.h:57

References ADD_SENTENCE_TO_TEXT, get_bool_property(), HASH_UNDEFINED_VALUE, is_sentence_formatted, list_undefined, make_sentence(), make_text(), NIL, and strdup().

Referenced by get_any_comp_regions_text(), and text_statement_array_comp_regions().

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

◆ text_comp_region()

text text_comp_region ( effect  reg)

}}

{{ text region text text_region(effect reg) input : a region output : a text consisting of several lines of commentaries, representing the region modifies : nothing

Parameters
regeg

Definition at line 375 of file prettyprint.c.

377 {
378  text t_reg = make_text(NIL);
379  bool foresys = get_bool_property("PRETTYPRINT_FOR_FORESYS");
380  string str_prefix;
381 
382  if (foresys)
383  str_prefix = REGION_FORESYS_PREFIX;
384  else
385  str_prefix = PIPS_NORMAL_PREFIX;
386 
387  if(reg == effect_undefined)
388  {
389  ADD_SENTENCE_TO_TEXT(t_reg,
390  make_pred_commentary_sentence(strdup("<REGION_UNDEFINED>"),
391  str_prefix));
392  user_log("[region_to_string] unexpected effect undefined\n");
393  }
394  else
395  {
396  free_text(t_reg);
397  t_reg = words_predicate_to_commentary(words_effect(reg), str_prefix);
398  }
399 
400  return(t_reg);
401 }
void user_log(const char *format,...)
Definition: message.c:234
void free_text(text p)
Definition: text.c:74
#define REGION_FORESYS_PREFIX
Definition: prettyprint.c:56
#define PIPS_NORMAL_PREFIX
Definition: prettyprint.c:57
list words_effect(effect)
#define effect_undefined
Definition: effects.h:614
sentence make_pred_commentary_sentence(string str_pred, string comment_prefix)
sentence make_pred_commentary_sentence(string str_pred, string comment_prefix) input : a substring fo...
Definition: prettyprint.c:678
text words_predicate_to_commentary(list w_pred, string comment_prefix)
text words_predicate_to_commentary(list w_pred, string comment_prefix) input : a list of strings,...
Definition: prettyprint.c:653

References ADD_SENTENCE_TO_TEXT, effect_undefined, free_text(), get_bool_property(), make_pred_commentary_sentence(), make_text(), NIL, PIPS_NORMAL_PREFIX, REGION_FORESYS_PREFIX, strdup(), user_log(), words_effect(), and words_predicate_to_commentary().

Referenced by text_comp_regions().

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

◆ text_comp_regions()

text text_comp_regions ( list  l_reg)

}}

{{ text comp_regions text text_comp_regions(list l_reg) input : a list of comp_regions output : a text representing this list (with non-array comp_regions)

change later

Parameters
l_reg_reg

Definition at line 347 of file prettyprint.c.

349 {
350 
351  text reg_text = make_text(NIL);
352  /* change later */
353  return(reg_text);
354 
355  MAP(EFFECT, reg,
356  {
357  entity ent = effect_entity(reg);
358  if (! entity_scalar_p(ent))
359  {
360  MERGE_TEXTS(reg_text, text_comp_region(reg));
361  }
362  },
363  l_reg);
364 
365  return(reg_text);
366 }
text text_comp_region(effect reg)
}}
Definition: prettyprint.c:375
entity effect_entity(effect)
cproto-generated files
Definition: effects.c:52
bool entity_scalar_p(entity)
The concrete type of e is a scalar type.
Definition: variable.c:1113

References EFFECT, effect_entity(), entity_scalar_p(), make_text(), MAP, MERGE_TEXTS, NIL, and text_comp_region().

+ Here is the call graph for this function:

◆ text_statement_array_comp_regions() [1/2]

static text text_statement_array_comp_regions ( entity __attribute__((unused))  module,
int __attribute__((unused))  margin,
statement  stat 
)
static

}}

{{ text statement array comp_regions static text text_statement_array_comp_regions(entity module, int margin, statement stat) output : a text representing the list of array comp_regions associated with the statement stat. comment : if the number of array comp_regions is not nul, then empty lines are added before and after the text of the list of comp_regions.

Necessary because of unreachable statements - In this case, no comp_regions are stored in the statement_mapping, and their values are thus HASH_UNDEFINED_VALUE or list_undefined. BC. 25/07/95.

GO 31/7/95: I replace it by a different test in text_array_comp_regions

Definition at line 245 of file prettyprint.c.

248 {
249  list l_reg = NIL;
250 
251  if (is_user_view_p) {
252  statement i;
253 
254  i = (statement) hash_get(nts, (char *) statement_number(stat));
255 
256  if (i != (statement) HASH_UNDEFINED_VALUE) {
258  }
259  else
260  l_reg = (list) HASH_UNDEFINED_VALUE;
261  }
262  else
263  l_reg = load_statement_local_comp_regions(stat);
264 
265 
266  /* Necessary because of unreachable statements - In this case, no comp_regions
267  * are stored in the statement_mapping, and their values are thus
268  * HASH_UNDEFINED_VALUE or list_undefined. BC. 25/07/95. */
269  /* GO 31/7/95: I replace it by a different test in text_array_comp_regions */
270 
271  return text_array_comp_regions(l_reg);
272 }
list load_statement_local_comp_regions(statement)
void * hash_get(const hash_table htp, const void *key)
this function retrieves in the hash table pointed to by htp the couple whose key is equal to key.
Definition: hash.c:449
struct cons * list
Definition: newgen_types.h:106
#define statement_number(x)
Definition: ri.h:2452

References hash_get(), HASH_UNDEFINED_VALUE, is_user_view_p, load_statement_local_comp_regions(), NIL, nts, statement_number, and text_array_comp_regions().

+ Here is the call graph for this function:

◆ text_statement_array_comp_regions() [2/2]

static text text_statement_array_comp_regions ( entity  ,
int  ,
statement   
)
static

Referenced by get_any_comp_regions_text().

+ Here is the caller graph for this function:

Variable Documentation

◆ in_out_comp_regions_p

bool in_out_comp_regions_p = false
static

{{{ function prototype

Definition at line 61 of file prettyprint.c.

Referenced by get_text_comp_regions(), print_code_comp_regions(), and print_source_comp_regions().

◆ is_user_view_p

◆ nts