PIPS
c_parser.c
Go to the documentation of this file.
1 /*
2 
3  $Id: c_parser.c 23495 2018-10-24 09:19:47Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 
32 #include "genC.h"
33 #include "linear.h"
34 #include "misc.h"
35 #include "ri.h"
36 #include "ri-util.h"
37 
38 #include "cyacc.h"
39 
40 #include "c_syntax.h"
41 
42 #include "resources.h"
43 #include "database.h"
44 
45 #include "pipsdbm.h"
46 #include "workspace-util.h"
47 #include "text-util.h" // for debugging
48 
50 
52 
54 ␌
55 // To track the file name we are parsing for error messages:
57 
59 {
61  pips_internal_error("c_parser_current_file_name not initialized.\n");
63 }
64 
66 {
67  // Could check that it is undefined on entry
69  pips_internal_error("c_parser_current_file_name no initialized.\n");
71 }
72 
74 {
75  // Could check that it is defined on entry
77  pips_internal_error("c_parser_current_file_name no initialized.\n");
79 }
80 
82 {
84 }
85 ␌
86 // To track the file name we are parsing for error messages:
88 
90 {
92  pips_internal_error("c_parser_current_user_input_file_name not initialized.\n");
94 }
95 
97 {
98  // Could check that it is undefined on entry
100  pips_internal_error("c_parser_current_user_input_file_name no initialized.\n");
102 }
103 
105 {
106  // Could check that it is defined on entry
108  pips_internal_error("c_parser_current_user_input_file_name no initialized.\n");
110 }
111 
113 {
115 }
116 ␌
122 
123 /* Global counter */
124 int loop_counter = 1;
126 
127 // To store the mapping between the entity and its type stack
129 
130 
132 {
136  //put_stack_storage_table("test","T");
137 }
138 
140 {
142  pips_internal_error("The stack must be defined");
144 }
145 
147 {
149 
150  if(p==HASH_UNDEFINED_VALUE)
151  return stack_undefined;
152  else
153  return ((stack) p);
154 }
155 
157 {
158  //entity te = entity_undefined;
159  void * p = hash_get(entity_to_type_stack_table, (void *) entity_name(e));
160  //void * p = hash_delget(entity_to_type_stack_table, (void *) e, (void **) &te);
161 
162  pips_debug(8, "Remove type stack for \"%s\":", entity_name(e));
163  //fprintf(stderr, "Remove type stack for \"%s\"\n", entity_name(e));
164  //pips_debug(8, "get=%p, delget=%p\n", p1, p);
165  if(p==HASH_UNDEFINED_VALUE) {
166  ifdebug(8) {fprintf(stderr, "no associated stack\n");
167  }
168  }
169  else {
170  stack es = (stack) p;
171 
172  (void) hash_del(entity_to_type_stack_table, (void *) entity_name(e));
173  if(!stack_undefined_p(es))
174  stack_free(&es);
175  ifdebug(8) fprintf(stderr, "done\n");
176  }
177 }
178 
180 {
181  FOREACH(ENTITY, e, el) {
183  }
184 }
185 
187 {
191 }
192 ␌
194 {
195  /* FI: keyword_typedef_table is also a global variable. I am trying
196  * to move towards some kind of functional wrapping around the
197  * global variable, which I would like to declare static in
198  * ri-util/static.c.
199  */
201  hash_put(keyword_typedef_table,"auto", (char *) TK_AUTO);
202  hash_put(keyword_typedef_table,"break", (char *) TK_BREAK);
203  hash_put(keyword_typedef_table,"case", (char *) TK_CASE);
204  hash_put(keyword_typedef_table,"char", (char *) TK_CHAR);
205  hash_put(keyword_typedef_table,"const", (char *) TK_CONST);
206  hash_put(keyword_typedef_table,"__const", (char *) TK_CONST);
207  hash_put(keyword_typedef_table,"continue", (char *) TK_CONTINUE);
208  hash_put(keyword_typedef_table,"default", (char *) TK_DEFAULT);
209  hash_put(keyword_typedef_table,"do", (char *) TK_DO);
210  hash_put(keyword_typedef_table,"double", (char *) TK_DOUBLE);
211  hash_put(keyword_typedef_table,"else", (char *) TK_ELSE);
212  hash_put(keyword_typedef_table,"enum", (char *) TK_ENUM);
213  hash_put(keyword_typedef_table,"extern", (char *) TK_EXTERN);
214  hash_put(keyword_typedef_table,"float", (char *) TK_FLOAT);
215  hash_put(keyword_typedef_table,"for", (char *) TK_FOR);
216  hash_put(keyword_typedef_table,"goto", (char *) TK_GOTO);
217  hash_put(keyword_typedef_table,"if", (char *) TK_IF);
218  hash_put(keyword_typedef_table,"inline", (char *) TK_INLINE);
219  hash_put(keyword_typedef_table,"int", (char *) TK_INT);
220  hash_put(keyword_typedef_table,"__int128_t", (char *) TK_INT128);
221  hash_put(keyword_typedef_table,"__uint128_t", (char *) TK_UINT128);
222  hash_put(keyword_typedef_table,"_Complex", (char *) TK_COMPLEX);
223  hash_put(keyword_typedef_table,"long", (char *) TK_LONG);
224  hash_put(keyword_typedef_table,"register", (char *) TK_REGISTER);
225  hash_put(keyword_typedef_table,"restrict", (char *) TK_RESTRICT);
226  hash_put(keyword_typedef_table,"__restrict", (char *) TK_RESTRICT);
227  hash_put(keyword_typedef_table,"__restrict__", (char *) TK_RESTRICT);
228  hash_put(keyword_typedef_table,"return", (char *) TK_RETURN);
229  hash_put(keyword_typedef_table,"short", (char *) TK_SHORT);
230  hash_put(keyword_typedef_table,"signed", (char *) TK_SIGNED);
231  hash_put(keyword_typedef_table,"sizeof", (char *) TK_SIZEOF);
232  hash_put(keyword_typedef_table,"static", (char *) TK_STATIC);
233  hash_put(keyword_typedef_table,"struct", (char *) TK_STRUCT);
234  hash_put(keyword_typedef_table,"switch", (char *) TK_SWITCH);
235  hash_put(keyword_typedef_table,"__thread", (char *) TK_THREAD);
236  hash_put(keyword_typedef_table,"typedef", (char *) TK_TYPEDEF);
237  hash_put(keyword_typedef_table,"union", (char *) TK_UNION);
238  hash_put(keyword_typedef_table,"unsigned", (char *) TK_UNSIGNED);
239  hash_put(keyword_typedef_table,"void", (char *) TK_VOID);
240  hash_put(keyword_typedef_table,"volatile", (char *) TK_VOLATILE);
241  hash_put(keyword_typedef_table,"while", (char *) TK_WHILE);
242  hash_put(keyword_typedef_table,"__builtin_va_arg", (char *) TK_BUILTIN_VA_ARG);
243  hash_put(keyword_typedef_table,"asm", (char *) TK_ASM);
244  hash_put(keyword_typedef_table,"__asm__", (char *) TK_ASM);
245  hash_put(keyword_typedef_table,"__volatile__", (char *) TK_VOLATILE);
246 
247  /* GNU predefined type(s), expecting no conflict with user named type */
248 
249  hash_put(keyword_typedef_table,"__builtin_va_list", (char *) TK_NAMED_TYPE);
250  hash_put(keyword_typedef_table,"_Bool", (char *) TK_NAMED_TYPE);
251 
252  /* AM: en attendant mieux... */
253  hash_put(keyword_typedef_table,"STEP_ARG", (char *) TK_NAMED_TYPE);
254 
255  /* typedef names are added later when encoutered. */
256 }
257 
258 /* Output a parser message error
259  *
260  * At the end there is a pips_user_error that launch an exception so
261  * that this function may not really exit but may be caught at a
262  * higher level...
263  *
264  * This function is called by macro CParserError()
265  */
266 bool c_parser_error(const char * func, const char *msg)
267 {
269  const char * mod_name = entity_undefined_p(mod)? "entity_undefined":entity_user_name(mod);
270  /* Since many information are lost by the various resetting, first save
271  them for later display: */
273  //int effective_line_number = c_lineno;
274 
275  pips_debug(1, "Parser error detected in function \"%s\".\n", func);
276 
277  c_reset_lex();
278 
279  /* Reset the parser global variables ?*/
280 
281  pips_debug(4,"Reset current module entity %s\n", mod_name);
282 
283  /* The error may occur before the current module entity is defined */
287 
288  // Get rid of partly declared variables
289  if(mod!=entity_undefined) {
290  value v = entity_initial(mod);
291  code c = value_code(v);
292 
293  code_declarations(c) = NIL;
295  CleanLocalEntities(mod);
296  }
297 
298  // Free CalledModules?
299 
300  // Could not rebuild filename (A. Mensi)
301  // c_in = safe_fopen(file_name, "r");
302  // safe_fclose(c_in, file_name);
303 
304  /* Stacks are not allocated yet when dealing with external
305  declarations. I assume that all stacks are declared
306  simultaneously, hence a single test before freeing. */
307  if(!entity_undefined_p(mod)) {
315  /* Reset them to stack_undefined_p instead of STACK_NULL */
320 
331  }
332  }
333 
335  /* get rid of all collected comments */
336  reset_C_comment(true);
339 
340  //debug_off();
341 
342  pips_user_warning("\nRecovery from C parser failure not (fully) implemented yet.\n"
343  "C parser is likely to fail later if re-used.\n");
347  pips_user_error("\n%s at user line %d in file \"%s\"\n",
348  msg, user_line_number, /*effective_line_number,*/ fn);
349  // Never reached, but for compatibility with Fortran ParserError
350  return true;
351 }
352 ␌
353 
355 {
356  entity l = statement_label(s);
357 
358  if(!entity_empty_label_p(l)) {
359  entity nl = (entity) hash_get(l_to_nl, (char *) l);
360  if(nl!=(entity) HASH_UNDEFINED_VALUE) {
361  statement_label(s) = nl;
362  /* FI: entity l could be destroyed right away... */
363  }
364  }
365 
366  return true;
367 }
368 
369 /* To avoid label name conflicts, the parser uses a special character
370  that cannot appear in a C label. Any label that uses this
371  character must be replaced. A new label entity must be introduced.
372 */
374 {
375  list pll = statement_to_labels(s);
376  hash_table label_to_new_label = hash_table_make(hash_pointer, 0);
377  int count = 0;
378 
379  /* Build the substitution table while avoiding label name conflicts */
380  FOREACH(ENTITY, l, pll) {
381  const char* ln = label_local_name(l);
382  string p = get_label_prefix(); // The prefix is assumed to be one
383  // character long
384  if(*p==*ln) {
385  string nln = strdup(ln);
386  *nln = '_';
387 
388  // In case of presence of '-' in the label
389  for(char * c = nln; *c != '\0'; c++)
390  if (*c == '-')
391  *c = '_';
392 
393  while(label_name_conflict_with_labels(nln, pll)) {
394  string nnln = strdup(concatenate("_", nln, NULL));
395  free(nln);
396  nln = nnln;
397  }
398  /* Here we end up with a conflict free label name */
399  const char* mn = entity_module_name(l);
400  // The current module is no longer definned at this point in the parser
401  //entity nl = MakeCLabel(nln);
402  string cln = strdup(concatenate(LABEL_PREFIX, nln, NULL));
403  entity nl = FindOrCreateEntity(mn, cln);
404  hash_put(label_to_new_label, (char *) l, (char *) nl);
405  free(nln), free(cln);
406  count++;
407  }
408  }
409 
410  /* Substitute the labels by the new labels in all substatement of s */
411  if(count>0) {
412  gen_context_recurse(s, (void *) label_to_new_label, statement_domain,
414 
415  /* Get rid of useless label entities, unless it has already been
416  performed by substitute_statement_label(). */
417  ;
418  }
419 
420  hash_table_free(label_to_new_label);
421 
422  return;
423 }
424 ␌
426 {
427  entity built_in_va_list = entity_undefined;
428  entity built_in_bool = entity_undefined;
429  entity built_in_complex = entity_undefined;
430  entity built_in_va_start = entity_undefined;
431  entity built_in_va_end = entity_undefined;
432  entity built_in_va_copy = entity_undefined;
433 
434  /* Predefined type(s): __builtin_va_list */
435  built_in_va_list =
437  if(storage_undefined_p(entity_storage(built_in_va_list))) {
438  entity_storage(built_in_va_list) = make_storage_rom();
439  /* Let's lie about the real type */
440  entity_type(built_in_va_list) =
443  NIL,
444  NIL));
445  entity_initial(built_in_va_list) = make_value_unknown();
446  }
447  built_in_bool =
449  if(storage_undefined_p(entity_storage(built_in_bool))) {
450  entity_storage(built_in_bool) = make_storage_rom();
451  entity_type(built_in_bool) =
454  NIL, NIL));
455  entity_initial(built_in_bool) = make_value_unknown();
456  }
457  built_in_complex =
459  if(storage_undefined_p(entity_storage(built_in_complex))) {
460  entity_storage(built_in_complex) = make_storage_rom();
461  entity_type(built_in_complex) =
464  NIL, NIL));
465  entity_initial(built_in_complex) = make_value_unknown();
466  }
467 
468  /* Predefined functions(s): __builtin_va_end (va_arg() is parsed directly) */
469  built_in_va_start =
471  if(storage_undefined_p(entity_storage(built_in_va_start))) {
472  basic va_list_b = make_basic(is_basic_typedef, built_in_va_list);
473  type va_list_t =
476  type void_start_t =
478  entity_storage(built_in_va_start) = make_storage_rom();
479  /* Let's lie about the real type... */
480  entity_type(built_in_va_start) =
483  make_parameter(va_list_t,
485  UU),
487  CONS(PARAMETER,
488  make_parameter(void_start_t,
491  NIL)),
493  entity_initial(built_in_va_start) = make_value_intrinsic();
494  }
495 
496  built_in_va_end =
498  if(storage_undefined_p(entity_storage(built_in_va_end))) {
499  basic va_list_b = make_basic(is_basic_typedef, built_in_va_list);
500  type va_list_t =
502  entity_storage(built_in_va_end) = make_storage_rom();
503  /* Let's lie about the real type */
504  entity_type(built_in_va_end) =
507  make_parameter(va_list_t,
510  NIL),
512  entity_initial(built_in_va_end) = make_value_intrinsic();
513  }
514 
515  built_in_va_copy =
517  if(storage_undefined_p(entity_storage(built_in_va_copy))) {
518  basic va_list_b = make_basic(is_basic_typedef, built_in_va_list);
519  type va_list_t =
521  parameter va_list_p = make_parameter(va_list_t,
522  make_mode_value(),
524  entity_storage(built_in_va_copy) = make_storage_rom();
525  /* Let's lie about the real type */
526  entity_type(built_in_va_copy) =
529  va_list_p,
530  CONS(PARAMETER,
531  copy_parameter(va_list_p),
532  NIL)),
534  entity_initial(built_in_va_copy) = make_value_intrinsic();
535  }
536 }
537 
538 /* To pass down the information to functions used by the syntactical
539  * analyzer
540  */
543 
544 static bool actual_c_parser(const char* module_name,
545  string dbr_file,
546  bool is_compilation_unit_parser)
547 {
548  string dir = db_get_current_workspace_directory();
549  string file_name =
550  strdup(concatenate(dir, "/",
551  db_get_file_resource(dbr_file,module_name,true), NULL));
552  free(dir);
553 
555  string input_file_name =
556  (string) db_get_memory_resource(DBR_INPUT_FILE_NAME, module_name, true);
560 
561  if (is_compilation_unit_parser) {
565  }
566  else {
569  (hash_table) db_get_memory_resource(DBR_DECLARATIONS,
570  compilation_unit_name,true);
572  }
573 
575  InitScope();
581 
582  loop_counter = 1;
583  derived_counter = 1;
584  CalledModules = NIL;
585 
586  debug_on("C_SYNTAX_DEBUG_LEVEL");
587  pips_debug(1,"Module name: %s\n", module_name);
588  pips_debug(1,"Compilation unit name: %s\n", compilation_unit_name);
589  ifdebug(1)
591 
592  /* FI: not clean, but useful for debugging statement */
593  /* ifdebug(1) */
594  /* { */
595  /* set_prettyprint_language_tag(is_language_c); */
596  /* } */
597 
599 
601  {
602  /* Special case, set the compilation unit as the current module */
604  /* I do not know to put this where to avoid repeated creations*/
606  /* Rather than dealing with the issue in error handling */
611  }
612 
613  /* discard_C_comment(); */
614  init_C_comment();
615  /* Mainly reset the line number: */
618 
619  /* yacc parser is called */
620  c_in = safe_fopen(file_name, "r");
621  //c_parser_current_file_name = file_name;
622 
624  c_parse();
625 
627 
629 
630  pips_assert("Module statement is consistent",
632 
634 
635  pips_assert("Module statement is consistent",
637 
639 
640  pips_assert("Module statement is consistent",
642 
643  ifdebug(2)
644  {
645  /* pips_debug(2,"Module statement: \n"); */
646  /* print_statement_of_module(ModuleStatement, module_name); */
647 
648  pips_debug(2,"and declarations: ");
651  pips_assert("e's type is defined", !type_undefined_p(entity_type(e)));
652  pips_assert("e's storage is defined", !storage_undefined_p(entity_storage(e)));
653  pips_assert("e's initial value is defined", !value_undefined_p(entity_initial(e)));
654  // Too strong because the normalize field of expressions in
655  //not initialized in the parser.
656  //pips_assert("e is fully defined", entity_defined_p(e));
657  }
659  /* Even if you are not in a compilation unit, external
660  functions may be declared many times within one scope. */
661  pips_assert("Variables are declared once",
663  }
664  else {
665  /* Variables allocated within the compilation unit should be declared only once, no? */
666  ; // no check yet
667  }
668  printf("\nList of callees:\n");
670  {
671  printf("\t%s\n",s);
672  }
673  }
674 
676  {
678  // unused: value v = entity_initial(ne);
679  type t = entity_type(ne);
680  if(/*value_code_p(v) &&*/ !type_variable_p(t))
681  RemoveFromExterns(ne);
682  }
685  ResetCurrentCompilationUnitEntity(is_compilation_unit_parser);
686  }
687 
688  if (is_compilation_unit_parser)
689  {
690  /* Beware : the rule in pipsmake-rc.tex for compilation_unit_parser
691  does not include the production of parsed_code and callees.
692  This is not very clean, and is done to work around the way pipsmake
693  handles compilation units and modules.
694  There was no simple solution... BC.
695  */
696  DB_PUT_MEMORY_RESOURCE(DBR_PARSED_CODE,
697  module_name,
698  (char *) ModuleStatement);
699  DB_PUT_MEMORY_RESOURCE(DBR_DECLARATIONS,
700  module_name,
701  (void *) keyword_typedef_table);
702  DB_PUT_MEMORY_RESOURCE(DBR_CALLEES,
703  module_name,
704  (char *) make_callees(NIL));
705  }
706  else
707  {
708  DB_PUT_MEMORY_RESOURCE(DBR_PARSED_CODE,
709  module_name,
710  (char *) ModuleStatement);
711  DB_PUT_MEMORY_RESOURCE(DBR_CALLEES,
712  module_name,
713  (char *) make_callees(CalledModules));
714  }
715 
716  free(file_name);
717  file_name = NULL;
720  reset_entity_type_stack_table(); /* Used to be done in ResetCurrentCompilationUnitEntity() */
726  /* free_keyword_typedef_table();*/
727  pips_assert("ContextStack is empty", stack_empty_p(ContextStack));
735  debug_off();
736  return true;
737 }
738 
739 bool c_parser(const char* module_name)
740 {
741  /* When the compilation_unit is parsed, it is parsed a second time
742  and multiple declarations are certain to happen. */
743  return actual_c_parser(module_name,DBR_C_SOURCE_FILE,false);
744 }
745 
747 {
748  return actual_c_parser(module_name,DBR_C_SOURCE_FILE,true);
749 }
functional make_functional(list a1, type a2)
Definition: ri.c:1109
parameter copy_parameter(parameter p)
PARAMETER.
Definition: ri.c:1459
basic make_basic_complex(intptr_t _field_)
Definition: ri.c:170
value make_value_unknown(void)
Definition: ri.c:2847
parameter make_parameter(type a1, mode a2, dummy a3)
Definition: ri.c:1495
mode make_mode(enum mode_utype tag, void *val)
Definition: ri.c:1350
basic make_basic(enum basic_utype tag, void *val)
Definition: ri.c:155
storage make_storage_rom(void)
Definition: ri.c:2285
basic make_basic_int(intptr_t _field_)
Definition: ri.c:158
type make_type_void(list _field_)
Definition: ri.c:2727
bool statement_consistent_p(statement p)
Definition: ri.c:2195
variable make_variable(basic a1, list a2, list a3)
Definition: ri.c:2895
basic make_basic_logical(intptr_t _field_)
Definition: ri.c:164
value make_value_intrinsic(void)
Definition: ri.c:2844
dummy make_dummy_unknown(void)
Definition: ri.c:617
mode make_mode_value(void)
Definition: ri.c:1353
type make_type(enum type_utype tag, void *val)
Definition: ri.c:2706
callees make_callees(list a)
Definition: ri.c:227
static int count
Definition: SDG.c:519
struct _newgen_struct_entity_ * entity
Definition: abc_private.h:14
void error_reset_c_parser_current_user_input_file_name(void)
Definition: c_parser.c:112
int derived_counter
Definition: c_parser.c:125
void set_c_parser_current_user_input_file_name(string file_name)
Definition: c_parser.c:96
bool c_parser(const char *module_name)
Definition: c_parser.c:739
static bool actual_c_parser(const char *module_name, string dbr_file, bool is_compilation_unit_parser)
Definition: c_parser.c:544
void reset_entity_type_stack_table()
Definition: c_parser.c:186
void reset_c_parser_current_input_file_name(void)
Definition: c_parser.c:73
static hash_table entity_to_type_stack_table
Definition: c_parser.c:128
static string c_parser_current_file_name
Definition: c_parser.c:56
void set_c_parser_current_input_file_name(string file_name)
Definition: c_parser.c:65
bool c_parser_error(const char *func, const char *msg)
Output a parser message error.
Definition: c_parser.c:266
stack StructNameStack
Definition: c_parser.c:121
void parser_init_keyword_typedef_table()
Definition: c_parser.c:193
list CalledModules
Definition: c_parser.c:51
string compilation_unit_name
cproto-generated files
Definition: c_parser.c:49
void reset_c_parser_current_user_input_file_name(void)
Definition: c_parser.c:104
stack get_from_entity_type_stack_table(entity key)
Definition: c_parser.c:146
void error_reset_c_parser_current_input_file_name(void)
Definition: c_parser.c:81
static string c_parser_current_user_input_file_name
Definition: c_parser.c:87
static bool substitute_statement_label(statement s, hash_table l_to_nl)
Definition: c_parser.c:354
bool compilation_unit_parser_is_running_p
To pass down the information to functions used by the syntactical analyzer.
Definition: c_parser.c:541
stack OffsetStack
Definition: c_parser.c:120
stack FunctionStack
Definition: c_parser.c:118
void init_entity_type_storage_table()
Definition: c_parser.c:131
void make_predefined_C_entities(string compilation_unit_name)
Definition: c_parser.c:425
void remove_entity_type_stack(entity e)
Definition: c_parser.c:156
void put_to_entity_type_stack_table(entity key, stack value)
Definition: c_parser.c:139
list removable_extern_entities
Definition: c_parser.c:542
int loop_counter
Global counter.
Definition: c_parser.c:124
string get_c_parser_current_user_input_file_name()
Definition: c_parser.c:89
void remove_entity_type_stacks(list el)
Definition: c_parser.c:179
stack FormalStack
Definition: c_parser.c:119
bool compilation_unit_parser(const char *module_name)
Definition: c_parser.c:746
stack ContextStack
Definition: c_parser.c:117
string get_c_parser_current_input_file_name()
Definition: c_parser.c:58
statement ModuleStatement
Definition: c_parser.c:53
static void FixCInternalLabels(statement s)
To avoid label name conflicts, the parser uses a special character that cannot appear in a C label.
Definition: c_parser.c:373
#define c_parser_context_domain
newgen_qualifier_domain_defined
void reset_expression_comment(void)
we don't want an expression comment with new lines, it is disgracefull
Definition: cyacc.tab.c:169
void init_c_parser_scope_stack(void)
Definition: cyacc.tab.c:514
#define get_label_prefix()
The labels in C have function scope...
void set_current_C_line_number(void)
Definition: clexer.c:1166
void reset_c_parser_scope_stack(void)
Definition: cyacc.tab.c:522
void reset_declaration_counter(void)
Definition: cyacc.tab.c:492
int c_parse()
int get_current_C_line_number(void)
Definition: clexer.c:1146
FILE * c_in
Definition: c_syntax.h:291
void init_C_comment(void)
Definition: clexer.c:1513
void reset_current_C_line_number(void)
Definition: clexer.c:1210
void InitScope(void)
Definition: cyacc.tab.c:306
void reset_C_comment(bool)
reset and reset_error should be handled differently
Definition: clexer.c:1450
void c_reset_lex(void)
void error_reset_current_C_line_number(void)
Definition: clexer.c:1224
void force_reset_c_parser_scope_stack(void)
To be used by an error handler.
Definition: cyacc.tab.c:539
void MakeTopLevelEntity(void)
Definition: util.c:157
void FixCReturnStatements(statement)
When return statements have been encountered, each of them has been replaced by a goto to a unique re...
Definition: return.c:223
stack SwitchControllerStack
Definition: statement.c:63
bool check_declaration_uniqueness_p(statement)
This is designed for standard C functions, not for compilation units.
Definition: util.c:3540
stack LoopStack
Definition: statement.c:64
void reset_preprocessor_line_analysis(void)
Definition: util.c:3592
void ResetCurrentCompilationUnitEntity(bool)
Definition: util.c:349
void RemoveFromExterns(entity)
Definition: util.c:2884
void Reset_C_ReturnStatement(void)
The return statement must be reset when it is used by the parser to add the return statement to the f...
Definition: return.c:115
stack SwitchGotoStack
list of labeled statements of the current module
Definition: statement.c:62
stack BlockStack
statement.c
Definition: statement.c:58
void reset_current_dummy_parameter_number(void)
Definition: util.c:144
void MakeCurrentCompilationUnitEntity(const char *)
A compilation unit is also considered as a module.
Definition: util.c:328
void CleanLocalEntities(entity function)
Fortran version.
Definition: clean.c:140
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
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
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
#define STRING(x)
Definition: genC.h:87
void free(void *)
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
void gen_null2(__attribute__((unused)) void *u1, __attribute__((unused)) void *u2)
idem with 2 args, to please overpeaky compiler checks
Definition: genClib.c:2758
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define list_undefined_p(c)
Return if a list is undefined.
Definition: newgen_list.h:75
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
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 list_undefined
Undefined list definition :-)
Definition: newgen_list.h:69
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
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
Definition: pipsdbm-local.h:66
list statement_to_labels(statement)
Look for non-empty labels appearing directly or indirectly and allocate a label list.
Definition: statement.c:3169
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
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
void hash_put(hash_table htp, const void *key, const void *val)
This functions stores a couple (key,val) in the hash table pointed to by htp.
Definition: hash.c:364
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
void * hash_del(hash_table htp, const void *key)
this function removes from the hash table pointed to by htp the couple whose key is equal to key.
Definition: hash.c:439
void set_prettyprint_language_tag(enum language_utype lang)
set the prettyprint language from a language_utype argument
Definition: language.c:143
#define debug_on(env)
Definition: misc-local.h:157
#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_user_warning
Definition: misc-local.h:146
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define pips_internal_error
Definition: misc-local.h:149
#define debug_off()
Definition: misc-local.h:160
#define pips_user_error
Definition: misc-local.h:147
#define LABEL_PREFIX
Definition: naming-local.h:31
#define TYPEDEF_PREFIX
Definition: naming-local.h:62
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
#define HASH_MAP(k, v, code, ht)
Definition: newgen_hash.h:60
@ hash_string
Definition: newgen_hash.h:32
@ hash_pointer
Definition: newgen_hash.h:32
#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 hash_table_undefined_p(h)
Definition: newgen_hash.h:50
#define hash_table_undefined
Value of an undefined hash_table.
Definition: newgen_hash.h:49
struct __hash_table * hash_table
Define hash_table structure which is hidden.
Definition: newgen_hash.h:43
#define stack_undefined
Definition: newgen_stack.h:55
bool stack_empty_p(const stack)
void stack_free(stack *)
type, bucket_size, policy
Definition: stack.c:292
stack stack_make(int, int, int)
allocation
Definition: stack.c:246
struct __stack_head * stack
STACK MANAGEMENT – headers.
Definition: newgen_stack.h:47
#define stack_undefined_p(s)
Definition: newgen_stack.h:56
#define string_undefined
Definition: newgen_types.h:40
char * string
STRING.
Definition: newgen_types.h:39
#define string_undefined_p(s)
Definition: newgen_types.h:41
#define UU
Definition: newgen_types.h:98
#define db_get_file_resource
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
int user_line_number
To be exported to the parser for error messages related to the user file.
Definition: lexer.c:1087
#define BUILTIN_VA_END
vararg stuff.
#define DEFAULT_LOGICAL_TYPE_SIZE
#define BUILTIN_VA_COPY
#define DEFAULT_INTEGER_TYPE_SIZE
#define DEFAULT_COMPLEX_TYPE_SIZE
#define BUILTIN_VA_START
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487
entity FindOrCreateEntity(const char *package, const char *local_name)
Problem: A functional global entity may be referenced without parenthesis or CALL keyword in a functi...
Definition: entity.c:1586
void print_entities(list l)
Definition: entity.c:167
bool label_name_conflict_with_labels(const char *n, list ll)
Definition: entity.c:610
bool entity_empty_label_p(entity e)
Definition: entity.c:666
const char * entity_module_name(entity e)
See comments about module_name().
Definition: entity.c:1092
const char * label_local_name(entity e)
END_EOLE.
Definition: entity.c:604
void statement_normalize_subscripts(statement s)
To be used for module statements.
Definition: expression.c:4471
hash_table make_keyword_typedef_table(int)
Definition: static.c:256
hash_table keyword_typedef_table
Because of typedefs, the C lexers need help to decide if a character string such as toto is a type na...
Definition: static.c:253
void error_reset_current_module_entity(void)
To be called by an error management routine only.
Definition: static.c:109
#define value_undefined_p(x)
Definition: ri.h:3017
@ is_basic_pointer
Definition: ri.h:578
@ is_basic_typedef
Definition: ri.h:580
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
@ is_mode_value
Definition: ri.h:1675
#define entity_storage(x)
Definition: ri.h:2794
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
#define code_declarations(x)
Definition: ri.h:784
#define statement_label(x)
Definition: ri.h:2450
#define type_undefined_p(x)
Definition: ri.h:2884
#define entity_undefined_p(x)
Definition: ri.h:2762
#define basic_domain
newgen_area_domain_defined
Definition: ri.h:42
#define entity_undefined
Definition: ri.h:2761
#define entity_name(x)
Definition: ri.h:2790
#define PARAMETER(x)
PARAMETER.
Definition: ri.h:1788
#define value_code(x)
Definition: ri.h:3067
#define code_decls_text(x)
Definition: ri.h:786
#define statement_declarations(x)
Definition: ri.h:2460
@ is_type_void
Definition: ri.h:2904
@ is_type_functional
Definition: ri.h:2901
@ is_type_variable
Definition: ri.h:2900
#define entity_type(x)
Definition: ri.h:2792
#define type_variable_p(x)
Definition: ri.h:2947
#define code_domain
newgen_cast_domain_defined
Definition: ri.h:74
#define storage_undefined_p(x)
Definition: ri.h:2477
@ is_language_c
Definition: ri.h:1567
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410
#define statement_undefined
Definition: ri.h:2419
#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()
int printf()
#define ifdebug(n)
Definition: sg.c:47
#define TK_STATIC
Definition: splitc.c:782
#define TK_BREAK
Definition: splitc.c:837
#define TK_SHORT
Definition: splitc.c:779
#define TK_WHILE
Definition: splitc.c:844
#define TK_RESTRICT
Definition: splitc.c:784
#define TK_INT128
Definition: splitc.c:766
#define TK_RETURN
Definition: splitc.c:840
#define TK_INLINE
Definition: splitc.c:850
#define TK_THREAD
Definition: splitc.c:787
#define TK_CASE
Definition: splitc.c:842
#define TK_REGISTER
Definition: splitc.c:786
#define TK_COMPLEX
Definition: splitc.c:771
#define TK_GOTO
Definition: splitc.c:839
#define TK_STRUCT
Definition: splitc.c:773
#define TK_SIZEOF
Definition: splitc.c:789
#define TK_CONST
Definition: splitc.c:783
#define TK_VOID
Definition: splitc.c:770
#define TK_UINT128
Definition: splitc.c:767
#define TK_INT
Definition: splitc.c:765
#define TK_LONG
Definition: splitc.c:778
#define TK_NAMED_TYPE
Definition: splitc.c:760
#define TK_FOR
Definition: splitc.c:846
#define TK_FLOAT
Definition: splitc.c:769
#define TK_SIGNED
Definition: splitc.c:776
#define TK_BUILTIN_VA_ARG
Definition: splitc.c:856
#define TK_SWITCH
Definition: splitc.c:841
#define TK_VOLATILE
Definition: splitc.c:780
#define TK_CONTINUE
Definition: splitc.c:838
#define TK_ELSE
Definition: splitc.c:848
#define TK_EXTERN
Definition: splitc.c:781
#define TK_ENUM
Definition: splitc.c:772
#define TK_IF
Definition: splitc.c:847
#define TK_CHAR
Definition: splitc.c:764
#define TK_AUTO
Definition: splitc.c:785
#define TK_TYPEDEF
Definition: splitc.c:774
#define TK_DO
Definition: splitc.c:845
#define TK_DEFAULT
Definition: splitc.c:843
#define TK_DOUBLE
Definition: splitc.c:768
#define TK_UNSIGNED
Definition: splitc.c:777
#define TK_UNION
Definition: splitc.c:775
#define TK_ASM
Definition: splitc.c:851
the stack head
Definition: stack.c:62
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
static string file_name