PIPS
symbol_table.c File Reference
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include "genC.h"
#include "linear.h"
#include "misc.h"
#include "properties.h"
#include "pipsdbm.h"
#include "text-util.h"
#include "ri-util.h"
#include "prettyprint.h"
+ Include dependency graph for symbol_table.c:

Go to the source code of this file.

Macros

#define NL   "\n"
 

Functions

static string check_derived_and_typedef (basic b, int indent, const char *parent)
 
static string entities_type_and_name (list entities, int indent, const char *parent)
 
void dump_common_layout (string_buffer result, entity c, bool debug_p, bool isfortran)
 This function is called from c_parse() via ResetCurrentModule() and fprint_environment() More...
 
string get_symbol_table (entity m, bool isfortran)
 
void actual_symbol_table_dump (const char *module_name, bool is_parsed)
 
bool parsed_symbol_table (const char *module_name)
 bool c_symbol_table(const char* module_name) More...
 
bool symbol_table (const char *module_name)
 To replace c_symbol_table() and fortran_symbol_table() because the information about the language is available in the symbol table. More...
 

Variables

static string indent_table [9]
 

Macro Definition Documentation

◆ NL

#define NL   "\n"

Definition at line 42 of file symbol_table.c.

Function Documentation

◆ actual_symbol_table_dump()

void actual_symbol_table_dump ( const char *  module_name,
bool  is_parsed 
)

This function is called in two different context: as a standalone phase or as part of debugging the parser?!?

Parameters
module_nameodule_name
is_parseds_parsed

Definition at line 582 of file symbol_table.c.

583 {
584  FILE *out;
585  string ppt;
586  bool isfortran = false;
587 
590  if(value_code_p(v)) {
591  code c = value_code(v);
592  language l = code_language(c);
594  isfortran = true;
595  }
596  else if(language_c_p(l)) {
597  isfortran = false;
599  }
600  else {
601  pips_internal_error("Language %d is not supported.\n");
602  }
603  }
604  else {
605  pips_internal_error("Module \"%s\" has no code.\n", module_name);
606  }
607 
608  string symboltable = db_build_file_resource_name(DBR_SYMBOL_TABLE_FILE,
609  module_name, NULL);
610  string dir = db_get_current_workspace_directory();
611  string filename = strdup(concatenate(dir, "/", symboltable, NULL));
612  bool reset_p = false;
613 
614  debug_on("SYMBOL_TABLE_DEBUG_LEVEL");
615 
616  /* This function is called in two different context: as a
617  standalone phase or as part of debugging the parser?!? */
619  reset_p = true;
621  }
622 
623  out = safe_fopen(filename, "w");
624 
625  ppt = get_symbol_table(module, isfortran);
626 
627  fprintf(out, "%s\n%s", module_name, ppt);
628  safe_fclose(out, filename);
629 
630  free(dir);
631  free(filename);
632 
633  if(reset_p)
635 
636  debug_off();
637 
638  if(is_parsed)
639  DB_PUT_FILE_RESOURCE(DBR_PARSED_SYMBOL_TABLE_FILE, module_name, symboltable);
640  else
641  DB_PUT_FILE_RESOURCE(DBR_SYMBOL_TABLE_FILE, module_name, symboltable);
642 
643 }
static FILE * out
Definition: alias_check.c:128
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
void free(void *)
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
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 DB_PUT_FILE_RESOURCE
Put a file resource into the current workspace database.
Definition: pipsdbm-local.h:85
void set_prettyprint_language_tag(enum language_utype lang)
set the prettyprint language from a language_utype argument
Definition: language.c:143
string db_build_file_resource_name(const char *rname, const char *oname, const char *suffix)
returns an allocated file name for a file resource.
Definition: lowlevel.c:169
#define debug_on(env)
Definition: misc-local.h:157
#define pips_internal_error
Definition: misc-local.h:149
#define debug_off()
Definition: misc-local.h:160
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
static char * module
Definition: pips.c:74
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
#define value_code_p(x)
Definition: ri.h:3065
#define language_fortran95_p(x)
Definition: ri.h:1597
#define entity_undefined_p(x)
Definition: ri.h:2762
#define language_c_p(x)
Definition: ri.h:1594
#define value_code(x)
Definition: ri.h:3067
#define code_language(x)
Definition: ri.h:792
#define language_fortran_p(x)
Definition: ri.h:1591
@ is_language_c
Definition: ri.h:1567
#define entity_initial(x)
Definition: ri.h:2796
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
char * strdup()
string get_symbol_table(entity m, bool isfortran)
Definition: symbol_table.c:304

References code_language, concatenate(), db_build_file_resource_name(), db_get_current_workspace_directory(), DB_PUT_FILE_RESOURCE, debug_off, debug_on, entity_initial, entity_undefined_p, fprintf(), free(), get_current_module_entity(), get_symbol_table(), is_language_c, language_c_p, language_fortran95_p, language_fortran_p, module, module_name(), module_name_to_entity(), out, pips_internal_error, reset_current_module_entity(), safe_fclose(), safe_fopen(), set_current_module_entity(), set_prettyprint_language_tag(), strdup(), value_code, and value_code_p.

Referenced by parsed_symbol_table(), and symbol_table().

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

◆ check_derived_and_typedef()

static string check_derived_and_typedef ( basic  b,
int  indent,
const char *  parent 
)
static

Definition at line 93 of file symbol_table.c.

94  {
95  string result = NULL;
96  if (basic_derived_p (b)) {
97  pips_debug(3, "Derived found, let's look at it\n");
98  entity e2 = basic_derived (b);
99  type t2 = entity_type (e2);
100  if (type_struct_p(t2)) {
101  pips_debug(3, "Struct found, let's go deeper\n");
102  result = entities_type_and_name (type_struct (t2), indent, parent);
103  }
104  }
105  if (basic_typedef_p (b)) {
106  pips_debug(3, "typedef found, let's look at it\n");
107  entity e2 = basic_typedef (b);
108  type t2 = entity_type (e2);
109  if (type_variable_p(t2)) {
110  variable v2 = type_variable(t2);
111  basic b2 = variable_basic(v2);
112  result = check_derived_and_typedef (b2, indent, parent);
113  }
114  }
115  return ((result == NULL) ? strdup ("") : result);
116 }
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define type_struct(x)
Definition: ri.h:2964
#define type_struct_p(x)
Definition: ri.h:2962
#define basic_derived(x)
Definition: ri.h:640
#define basic_typedef_p(x)
Definition: ri.h:641
#define type_variable(x)
Definition: ri.h:2949
#define basic_derived_p(x)
Definition: ri.h:638
#define basic_typedef(x)
Definition: ri.h:643
#define entity_type(x)
Definition: ri.h:2792
#define type_variable_p(x)
Definition: ri.h:2947
#define variable_basic(x)
Definition: ri.h:3120
Value b2
Definition: sc_gram.c:105
static string check_derived_and_typedef(basic b, int indent, const char *parent)
Definition: symbol_table.c:93
static string entities_type_and_name(list entities, int indent, const char *parent)
Definition: symbol_table.c:57

References b2, basic_derived, basic_derived_p, basic_typedef, basic_typedef_p, entities_type_and_name(), entity_type, pips_debug, strdup(), type_struct, type_struct_p, type_variable, type_variable_p, and variable_basic.

Referenced by dump_common_layout(), and entities_type_and_name().

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

◆ dump_common_layout()

void dump_common_layout ( string_buffer  result,
entity  c,
bool  debug_p,
bool  isfortran 
)

This function is called from c_parse() via ResetCurrentModule() and fprint_environment()

symbol_table.c

FI: a weaker test to stay independent from the syntax library and its internal static variables.

This piece of code can be used in a pass or as debugging code for library syntax.

Parameters
resultesult
debug_pebug_p
isfortransfortran

Definition at line 120 of file symbol_table.c.

124 {
126  list members = get_common_members(c, mod, false);
127  list equiv_members = NIL;
128 
129  string_buffer_append(result,
130  concatenate(NL,"Layout for ",
131  isfortran?"common /":"memory area \"",
132  entity_name(c),isfortran?"/":"\""," of size ",
134  ":",NL,NULL));
135 
136 
137  if(ENDP(members)) {
138  pips_assert("An empty area has size 0",
139  area_size(type_area(entity_type(c))) ==0);
140  string_buffer_append(result, concatenate("\t* empty area *",NL,NL,NULL));
141  }
142  else {
143  // Different preconditions for C and fortran
144 
145  if(isfortran){
146  if(area_size(type_area(entity_type(c)))==0
147  /* FI: a weaker test to stay independent from the syntax
148  * library and its internal static variables.
149  *
150  * This piece of code can be used in a pass or as debugging
151  * code for library syntax.
152  */
153  // && fortran_relevant_area_entity_p(c))
154  && !heap_area_p(c) && !stack_area_p(c))
155  {
156  if(debug_p) {
157  user_warning("dump_common_layout",
158  "Non-empty area %s should have a final size greater than 0\n",
159  entity_module_name(c));
160  }
161  else {
162  pips_internal_error("Non-empty area %s should have a size greater than 0",
163  entity_module_name(c));
164  }
165  }
166  }
167  else {
168  if(area_size(type_area(entity_type(c))) == 0)
169  {
170  if(debug_p) {
171  user_warning("dump_common_layout",
172  "Non-empty area %s should have a final size greater than 0\n",
173  entity_module_name(c));
174  }
175  }
176  }
177 
178  if(isfortran){
179  FOREACH(ENTITY, m, members) {
180  pips_assert("RAM storage",
182  if(ram_function(storage_ram(entity_storage(m)))==mod) {
183  int s;
184 
186  pips_internal_error("Variable %s declared in area %s but allocated in area %s",
189  }
190 
191  if(!SizeOfArray(m, &s)) {
194  s = -1;
195  }
196  else {
197  user_warning("print_common_layout",
198  "Varying size of array \"%s\"\n", entity_name(m));
199  pips_internal_error("Fortran standard prohibit varying size array\n");
200  }
201  }
202 
203  string_buffer_append(result,
205  ("\tVariable ",entity_name(m),"\toffset = ",
207  string_buffer_append(result,
208  concatenate("\tsize = ",i2a(s),NL,NULL));
209  }
210  }
211  }
212  else { // C language
213  FOREACH(ENTITY, m, members) {
214  if(!place_holder_variable_p(m)) {
215  pips_assert("RAM storage",
217  int s;
218 
219  SizeOfArray(m, &s);
220 
221  pips_assert("An area has no offset as -1",
223 
225  string_buffer_append(result,
226  concatenate(
227  "\tDynamic Variable \"",entity_name(m),
228  "\"\toffset = UNKNOWN, \tsize = DYNAMIC",
229  NL,NULL));
230  }
232  string_buffer_append(result,
234  ("\tExternal Variable \"", entity_name(m),
235  "\"\toffset = UNKNOWN,\tsize = ",
236  s>0?i2a(s): "unknown", NL, NULL));
237  }
238  else {
239  string_buffer_append(result,
241  ("\tVariable \"", entity_name(m),"\"\toffset = ",
243  if (get_bool_property("EXTENDED_VARIABLE_INFORMATION")) {
244  pips_debug(3, "extended information required\n");
245  type t = entity_type (m);
246  if (type_variable_p(t)) {
247  variable v = type_variable(t);
248  basic b = variable_basic(v);
249  string_buffer_append(result,
250  concatenate("\ttype = \"",
251  basic_to_string(b), "\"",
252  "\tuser name = \"",
253  entity_user_name (m), "\"",
254  NULL));
255  // check if the basic is derived or typedef to be investigated
256  string deeper = check_derived_and_typedef (b, 2, entity_user_name (m));
257  if (strcmp (deeper, "") != 0) {
258  string_buffer_append (result, NL);
259  string_buffer_append (result, deeper);
260  }
261  else free (deeper);
262  }
263  }
264  string_buffer_append(result,
265  concatenate("\tsize = ",i2a(s),NL,NULL));
266  }
267  }
268  }
269  }
270 
271  string_buffer_append(result, NL);
272 
273  FOREACH(ENTITY, m, members) {
275 
276  equiv_members = arguments_union(equiv_members, equiv);
277  }
278 
279  if(!ENDP(equiv_members)){
280  equiv_members = arguments_difference(equiv_members, members);
281  if(!ENDP(equiv_members)) {
282  sort_list_of_entities(equiv_members);
283 
284  string_buffer_append(result, concatenate("\tVariables aliased to this common:",NL,
285  NULL));
286 
287  FOREACH(ENTITY, m, equiv_members) {
288  pips_assert("RAM storage",
290  string_buffer_append(result,
292  ("\tVariable", entity_name(m) ,"\toffset =",
293  ram_offset(storage_ram(entity_storage(m))),"\tsize = ",
294  array_size(m),NL,NULL));
295  }
296  string_buffer_append(result, concatenate(NL,NULL));
297  gen_free_list(equiv_members);
298  }
299  }
300  }
301  gen_free_list(members);
302 }
cons * arguments_union(cons *a1, cons *a2)
cons * arguments_union(cons * a1, cons * a2): returns a = union(a1, a2) where a1 and a2 are lists of ...
Definition: arguments.c:116
cons * arguments_difference(cons *a1, cons *a2)
set difference: a1 - a2 ; similar to set intersection
Definition: arguments.c:233
entity HeapArea
Definition: area.c:59
entity StackArea
Definition: area.c:60
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
static int array_size(dim)
ARRAY_SIZE returns the number of elements in the array whose dimension list is DIM.
Definition: genClib.c:155
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#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
#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 pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define user_warning(fn,...)
Definition: misc-local.h:262
char * i2a(int)
I2A (Integer TO Ascii) yields a string for a given Integer.
Definition: string.c:121
void string_buffer_append(string_buffer, const string)
append string s (if non empty) to string buffer sb, the duplication is done if needed according to th...
string basic_to_string(basic)
Definition: type.c:87
#define DYNAMIC_RAM_OFFSET
FI: I would have assumed that it is used for the stack area, but I must be wrong.....
#define UNDEFINED_RAM_OFFSET
bool stack_area_p(entity aire)
Definition: area.c:104
bool heap_area_p(entity aire)
Definition: area.c:86
list get_common_members(entity common, entity __attribute__((unused)) module, bool __attribute__((unused)) only_primary)
The fprint_functional() and fprint_environment() functions are moved from syntax/declaration....
Definition: declarations.c:106
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
void sort_list_of_entities(list l)
sorted in place.
Definition: entity.c:1358
const char * entity_module_name(entity e)
See comments about module_name().
Definition: entity.c:1092
bool SizeOfArray(entity, int *)
This function computes the total size of a variable in bytes, ie.
Definition: size.c:87
bool place_holder_variable_p(entity)
Definition: variable.c:2069
#define area_size(x)
Definition: ri.h:544
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define entity_storage(x)
Definition: ri.h:2794
#define storage_ram_p(x)
Definition: ri.h:2519
#define ram_section(x)
Definition: ri.h:2249
#define entity_name(x)
Definition: ri.h:2790
#define type_area(x)
Definition: ri.h:2946
#define storage_ram(x)
Definition: ri.h:2521
#define ram_function(x)
Definition: ri.h:2247
#define ram_shared(x)
Definition: ri.h:2253
#define ram_offset(x)
Definition: ri.h:2251
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define NL
Definition: symbol_table.c:42

References area_size, arguments_difference(), arguments_union(), array_size(), basic_to_string(), check_derived_and_typedef(), concatenate(), DYNAMIC_RAM_OFFSET, ENDP, ENTITY, entity_local_name(), entity_module_name(), entity_name, entity_storage, entity_type, entity_user_name(), FOREACH, free(), gen_free_list(), get_bool_property(), get_common_members(), get_current_module_entity(), heap_area_p(), HeapArea, i2a(), NIL, NL, pips_assert, pips_debug, pips_internal_error, place_holder_variable_p(), ram_function, ram_offset, ram_section, ram_shared, SizeOfArray(), sort_list_of_entities(), stack_area_p(), StackArea, storage_ram, storage_ram_p, string_buffer_append(), type_area, type_variable, type_variable_p, UNDEFINED_RAM_OFFSET, user_warning, and variable_basic.

Referenced by get_symbol_table().

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

◆ entities_type_and_name()

static string entities_type_and_name ( list  entities,
int  indent,
const char *  parent 
)
static

Definition at line 57 of file symbol_table.c.

58  {
59  string result = strdup ("");
60  string indent_str = (indent < 9)? indent_table[indent] : indent_table[8];
61  string old = NULL;
62 
63  // if more that 8 indentation required continue to build the indentation
64  // string
65  for (int i = 8; i < indent; i++) {
66  old = indent_str;
67  indent_str = concatenate (indent_str, "\t", NULL);
68  free (old);
69  }
70 
71  FOREACH (ENTITY, e, entities) {
72  type t = entity_type (e);
73  if (type_variable_p(t)) {
74  old = result;
75  variable v = type_variable(t);
76  basic b = variable_basic(v);
77  string name = strdup (concatenate (parent, ".", entity_user_name (e),
78  NULL));
79  string deeper = check_derived_and_typedef (b, indent + 1, name);
80  result = strdup (concatenate(result, indent_str, "type = \"",
81  basic_to_string(b), "\"",
82  "\tuser name = \"", name, "\"\n",
83  deeper, NULL)
84  );
85  free (deeper);
86  free (name);
87  free (old);
88  }
89  }
90  return result;
91 }
static string indent_table[9]
Definition: symbol_table.c:44

References basic_to_string(), check_derived_and_typedef(), concatenate(), ENTITY, entity_type, entity_user_name(), FOREACH, free(), indent_table, strdup(), type_variable, type_variable_p, and variable_basic.

Referenced by check_derived_and_typedef().

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

◆ get_symbol_table()

string get_symbol_table ( entity  m,
bool  isfortran 
)

return variable

To simplify validation, at the expense of some information about the parsing process.

FI: struct, union and enum are also declared (in theory...), but their characteristics should be given differently.

&& (storage_ram_p(s) || storage_return_p(s) || storage_formal_p(s))

FI: How do we want to print out structures, unions and enums?

FI: How do we want to print out typedefs?

FI: it would be useful to dump more information aout fields and members

Formal parameters

Return variable

Structure of each area/common

Parameters
isfortransfortran

Definition at line 304 of file symbol_table.c.

305 {
306  string_buffer result = string_buffer_make(true);
307  string result2;
309  int nth = 0;
310  entity rv = entity_undefined; /* return variable */
311  list ce = list_undefined;
312 
313  pips_assert("m is a module", entity_module_p(m));
314  pips_assert("decls is a list of entities", entity_list_p(decls));
315 
316  /* To simplify validation, at the expense of some information about
317  the parsing process. */
318 
320 
321  string_buffer_append(result, concatenate(NL,"Declarations for module \"",
322  module_local_name(m),"\" with type \"", NULL));
323 
325  string_buffer_append(result, "\"" NL);
326 
327  /*
328  * List of implicitly and explicitly declared variables, functions
329  * and areas
330  *
331  */
332  if(ENDP(decls))
333  string_buffer_append(result, concatenate("\n* empty declaration list *",NL,NL,NULL));
334  else
335  string_buffer_append(result, concatenate("\nVariable list:",NL,NL,NULL));
336 
337  FOREACH(ENTITY, e, decls) {
338  // FI: more filtering needed for entities generated by the
339  // different passes, such as location entities
340  if(!typedef_entity_p(e) && !derived_entity_p(e)) {
341  type t = entity_type(e);
342 
343  pips_debug(8, "Processing entity \"%s\"\n", entity_name(e));
344  string_buffer_append(result, concatenate("\tDeclared entity \"",
345  entity_name(e),"\" with type \"",
346  type_to_string(t),"\" ",NULL));
347 
348  /* FI: struct, union and enum are also declared (in theory...), but
349  their characteristics should be given differently. */
350  if(type_variable_p(t)
351  /* && (storage_ram_p(s) || storage_return_p(s) || storage_formal_p(s))*/) {
352  variable v = type_variable(t);
353  list dl = variable_dimensions(v);
354  list ql = variable_qualifiers(v);
355  basic b = variable_basic(v);
358  string_buffer_append(result, "\"(");
359  dump_functional(f,result);
360  string_buffer_append(result, ") *\""NL);
361  }
362  else {
363  if(ENDP(dl)) {
364  if(ENDP(ql)) {
365  string_buffer_append(result,
366  concatenate("\"", basic_to_string(b), "\""NL,NULL));
367  }
368  else {
369  string sql = list_to_string(words_qualifiers(ql));
370  string_buffer_append(result,
371  concatenate("\"", sql, basic_to_string(b), "\""NL,NULL));
372  }
373  }
374  else {
375  list pdl = NIL;
376  string sdl = list_to_string(words_dimensions(dl, &pdl));
377  gen_free_list(pdl);
378  if(ENDP(ql)) {
379  string_buffer_append(result,
380  concatenate("\"", basic_to_string(b), sdl, "\""NL,NULL));
381  }
382  else {
383  string sql = list_to_string(words_qualifiers(ql));
384  string_buffer_append(result,
385  concatenate("\"", sql, basic_to_string(b), sdl, "\""NL,NULL));
386  }
387  }
388  }
389  }
390  else if(type_functional_p(t)) {
391  string_buffer_append(result, "\"");
392  dump_functional(type_functional(t),result);
393  string_buffer_append(result, "\""NL);
394  }
395  else if(type_area_p(t)) {
396  string_buffer_append(result,concatenate("with size ",
397  i2a(area_size(type_area(t))),NL, NULL));
398  }
399  else {
400  /* FI: How do we want to print out structures, unions and enums? */
401  /* FI: How do we want to print out typedefs? */
402  string_buffer_append(result, NL);
403  }
404  }
405  }
406 
407  /*
408  * Extern declarations
409  */
410 
411  if(!isfortran) {
413 
414  //gen_sort_list(decls, compare_entities);
415 
416  if(ENDP(edecls))
417  string_buffer_append(result, concatenate("\n* empty extern declaration list *",NL,NL,NULL));
418  else
419  string_buffer_append(result, concatenate("\nExternal variable list:",NL,NL,NULL));
420 
421  for(ce=edecls; !ENDP(ce); POP(ce)) {
422  entity e = ENTITY(CAR(ce));
423  type t = entity_type(e);
424 
425  pips_debug(8, "Processing external entity \"%s\"\n", entity_name(e));
426  pips_assert("e is an entity", entity_domain_number(e)==entity_domain);
427  string_buffer_append(result, concatenate("\tDeclared external entity \"",
428  entity_name(e),"\"\twith type \"",
429  type_to_string(t),"\" ",NULL));
430 
431  if(type_variable_p(t)) {
432  variable v = type_variable(t);
433  basic b = variable_basic(v);
436  string_buffer_append(result, "\"(");
437  dump_functional(f,result);
438  string_buffer_append(result, ") *\"" NL);
439  }
440  else {
441  string_buffer_append(result,
442  concatenate("\"", basic_to_string(b), "\""NL,NULL));
443  }
444  }
445  else if(type_functional_p(t)) {
446  string_buffer_append(result, "\"");
447  dump_functional(type_functional(t),result);
448  string_buffer_append(result, "\"" NL);
449  }
450  else if(type_area_p(t)) {
451  string_buffer_append(result,concatenate("with size ",
452  i2a(area_size(type_area(t))),NL, NULL));
453  }
454  else
455  string_buffer_append(result, NL);
456  }
457  }
458 
459  /*
460  * Derived entities: struct, union and enum
461  */
462 
463  nth = 0;
464  FOREACH(ENTITY, de, decls) {
465  if(entity_struct_p(de) || entity_union_p(de) || entity_enum_p(de)) {
466  nth++;
467  if(nth==1) {
468  string_buffer_append(result, concatenate(NL,"Derived entities:"
469  ,NL,NL,NULL));
470  }
471  /* FI: it would be useful to dump more information aout
472  fields and members */
473  string_buffer_append(result, concatenate("\tVariable \"", entity_name(de),
474  "\"\tkind = ",
475  entity_struct_p(de)? "struct" :
476  entity_union_p(de)? "union" : "enum",
477  "\n", NULL));
478  }
479  }
480 
481  /*
482  * Typedefs
483  */
484 
485  nth = 0;
486  FOREACH(ENTITY, te, decls) {
487  if(typedef_entity_p(te)) {
488  type t = entity_type(te);
489  nth++;
490  if(nth==1) {
491  string_buffer_append(result, concatenate(NL,"Typedef entities:"
492  ,NL,NL,NULL));
493  }
494  string_buffer_append(result, concatenate("\tTypedef \"", entity_name(te),
495  "\"\twith type \"",type_to_string(t),"\" ", NULL));
496 
497  if(type_variable_p(t)) {
498  variable v = type_variable(t);
499  basic b = variable_basic(v);
502  string_buffer_append(result, "\"(");
503  dump_functional(f,result);
504  string_buffer_append(result, ") *\"" NL);
505  }
506  else {
507  string_buffer_append(result,
508  concatenate("\"", basic_to_string(b), "\""NL,NULL));
509  }
510  }
511  else if(type_functional_p(t)) {
512  string_buffer_append(result, "\"");
513  dump_functional(type_functional(t),result);
514  string_buffer_append(result, "\"" NL);
515  }
516  else if(type_void_p(t)) {
517  string_buffer_append(result, "\"void\"" NL);
518  }
519  else {
520  pips_internal_error("unexpected type for a typedef");
521  }
522  }
523  }
524 
525  /* Formal parameters */
526  nth = 0;
527  FOREACH(ENTITY, v, decls) {
528  storage vs = entity_storage(v);
529 
530  pips_assert("All storages are defined", !storage_undefined_p(vs));
531 
532  if(storage_formal_p(vs)) {
533  nth++;
534  if(nth==1) {
535  string_buffer_append(result, concatenate(NL,"Layout for formal parameters:"
536  ,NL,NL,NULL));
537  }
538  string_buffer_append(result, concatenate("\tVariable ", entity_name(v),
539  "\toffset = ",
541  "\n", NULL));
542  }
543  else if(storage_return_p(vs)) {
544  pips_assert("No more than one return variable", entity_undefined_p(rv));
545  rv = v;
546  }
547  }
548 
549  /* Return variable */
550  if(!entity_undefined_p(rv)) {
552  string_buffer_append(result, concatenate(NL,"Layout for return variable:",NL,NL,NULL));
553  string_buffer_append(result, concatenate("\tVariable \"",
554  entity_name(rv),
555  "\"\tsize = ",
556  strdup(i2a(SizeOfElements(rb))),
557  "\n", NULL));
558  }
559 
560  /* Structure of each area/common */
561  if(!ENDP(decls)) {
562  string_buffer_append(result, concatenate(NL,"Layouts for ",isfortran?"commons:":"memory areas:",NL,NULL));
563  }
564 
565  FOREACH (ENTITY, e, decls) {
566  if(type_area_p(entity_type(e))) {
567  dump_common_layout(result, e, false, isfortran);
568  }
569  }
570 
571  string_buffer_append(result, concatenate("End of declarations for module ",
572  module_local_name(m), NL,NL, NULL));
573 
574  gen_free_list(decls);
575 
576  result2 = string_buffer_to_string(result);
577  string_buffer_free(&result);
578 
579  return result2;
580 }
string list_to_string(list l)
Return the malloc()ed version of the concatenation of all the strings in the list.
Definition: args.c:74
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
list gen_copy_seq(list l)
Copy a list structure.
Definition: list.c:501
#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
void gen_sort_list(list l, gen_cmp_func_t compare)
Sorts a list of gen_chunks in place, to avoid allocations...
Definition: list.c:796
string string_buffer_to_string(const string_buffer)
return malloc'ed string from string buffer sb
void string_buffer_free(string_buffer *)
free string buffer structure, also free string contents according to the dup field
Definition: string_buffer.c:82
string_buffer string_buffer_make(bool dup)
allocate a new string buffer
Definition: string_buffer.c:58
int(* gen_cmp_func_t)(const void *, const void *)
Definition: newgen_types.h:114
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
list words_qualifiers(list obj)
Definition: declarations.c:795
list words_dimensions(list dims, list *ppdl)
Definition: declarations.c:932
void dump_functional(functional f, string_buffer result)
Definition: declarations.c:581
bool entity_list_p(list el)
Checks that el only contains entity.
Definition: entity.c:1411
int compare_entities(const entity *pe1, const entity *pe2)
Comparison function for qsort.
Definition: entity.c:1328
bool entity_struct_p(entity e)
Is entity e the entity corresponding to a struct declaration?
Definition: entity.c:1002
bool entity_enum_p(entity e)
Definition: entity.c:968
bool typedef_entity_p(entity e)
Definition: entity.c:1902
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
bool entity_module_p(entity e)
Definition: entity.c:683
bool derived_entity_p(entity e)
Definition: entity.c:1048
bool entity_union_p(entity e)
Is entity e an entity representing the union declaration?
Definition: entity.c:1038
type ultimate_type(type)
Definition: type.c:3466
_int SizeOfElements(basic)
This function returns the length in bytes of the Fortran or C type represented by a basic,...
Definition: size.c:297
string type_to_string(const type)
type.c
Definition: type.c:51
#define type_functional_p(x)
Definition: ri.h:2950
#define formal_offset(x)
Definition: ri.h:1408
#define basic_pointer(x)
Definition: ri.h:637
#define storage_formal_p(x)
Definition: ri.h:2522
#define code_externs(x)
Definition: ri.h:790
#define type_functional(x)
Definition: ri.h:2952
#define basic_pointer_p(x)
Definition: ri.h:635
#define code_declarations(x)
Definition: ri.h:784
#define storage_formal(x)
Definition: ri.h:2524
#define entity_undefined
Definition: ri.h:2761
#define type_void_p(x)
Definition: ri.h:2959
#define variable_qualifiers(x)
Definition: ri.h:3124
#define variable_dimensions(x)
Definition: ri.h:3122
#define type_area_p(x)
Definition: ri.h:2944
#define entity_domain_number(x)
Definition: ri.h:2788
#define storage_return_p(x)
Definition: ri.h:2516
#define storage_undefined_p(x)
Definition: ri.h:2477
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410
internally defined structure.
Definition: string_buffer.c:47
void dump_common_layout(string_buffer result, entity c, bool debug_p, bool isfortran)
This function is called from c_parse() via ResetCurrentModule() and fprint_environment()
Definition: symbol_table.c:120

References area_size, basic_pointer, basic_pointer_p, basic_to_string(), CAR, code_declarations, code_externs, compare_entities(), concatenate(), derived_entity_p(), dump_common_layout(), dump_functional(), ENDP, ENTITY, entity_domain, entity_domain_number, entity_enum_p(), entity_initial, entity_list_p(), entity_module_p(), entity_name, entity_storage, entity_struct_p(), entity_type, entity_undefined, entity_undefined_p, entity_union_p(), f(), FOREACH, formal_offset, gen_copy_seq(), gen_free_list(), gen_sort_list(), i2a(), list_to_string(), list_undefined, module_local_name(), NIL, NL, pips_assert, pips_debug, pips_internal_error, POP, SizeOfElements(), storage_formal, storage_formal_p, storage_return_p, storage_undefined_p, strdup(), string_buffer_append(), string_buffer_free(), string_buffer_make(), string_buffer_to_string(), type_area, type_area_p, type_functional, type_functional_p, type_to_string(), type_variable, type_variable_p, type_void_p, typedef_entity_p(), ultimate_type(), value_code, variable_basic, variable_dimensions, variable_qualifiers, words_dimensions(), and words_qualifiers().

Referenced by actual_symbol_table_dump().

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

◆ parsed_symbol_table()

bool parsed_symbol_table ( const char *  module_name)

bool c_symbol_table(const char* module_name)

{ set_prettyprint_language_tag(is_language_c); //all the way down to words_basic() actual_symbol_table_dump(module_name, false); return true; } bool fortran_symbol_table(const char* module_name) { actual_symbol_table_dump(module_name, true); return true; } To replace c_symbol_table() and fortran_symbol_table() because the information about the language is available in the symbol table.

This the symbol table is never duplicated, this function's output is correct only if the controlizer has not been applied.

Parameters
module_nameodule_name

Definition at line 665 of file symbol_table.c.

666 {
668  return true;
669 }
void actual_symbol_table_dump(const char *module_name, bool is_parsed)
Definition: symbol_table.c:582

References actual_symbol_table_dump(), and module_name().

+ Here is the call graph for this function:

◆ symbol_table()

bool symbol_table ( const char *  module_name)

To replace c_symbol_table() and fortran_symbol_table() because the information about the language is available in the symbol table.

Parameters
module_nameodule_name

Definition at line 673 of file symbol_table.c.

674 {
676  return true;
677 }

References actual_symbol_table_dump(), and module_name().

Referenced by expression_similar_get_context_p(), and expression_similar_p().

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

Variable Documentation

◆ indent_table

string indent_table[9]
static
Initial value:
= {"",
"\t",
"\t\t",
"\t\t\t",
"\t\t\t\t",
"\t\t\t\t\t",
"\t\t\t\t\t\t",
"\t\t\t\t\t\t\t",
"\t\t\t\t\t\t\t\t"}

Definition at line 44 of file symbol_table.c.

Referenced by entities_type_and_name().