PIPS
c_syntax-local.h File Reference
#include "c_parser_private.h"
+ Include dependency graph for c_syntax-local.h:

Go to the source code of this file.

Macros

#define get_label_prefix()   "-"
 The labels in C have function scope... More...
 
#define FIRST_C_LINE_NUMBER   (1)
 Error handling. More...
 
#define UNDEFINED_C_LINE_NUMBER   (-1)
 
#define CParserError(m)   c_parser_error(CURRENT_FUNCTION, m)
 
#define c_parser_user_warning(...)    c_parser_user_warning_func(CURRENT_FUNCTION, __FILE__, __LINE__, __VA_ARGS__)
 

Functions

int c_lex ()
 
int c_parse ()
 
entity GetFunction (void)
 cproto workaround More...
 
void reset_expression_comment (void)
 we don't want an expression comment with new lines, it is disgracefull More...
 
string pop_block_scope (string)
 The scope is moved up the scope tree and a NULL is return when there are no more scope to explore. More...
 
string scope_to_block_scope (string)
 Allocate a new string containing only block scope information. More...
 
c_parser_context CreateDefaultContext (void)
 
void InitScope (void)
 
int ScopeStackSize (void)
 
string GetScope (void)
 
string GetParentScope (void)
 
void ExitScope (void)
 
void PushContext (c_parser_context)
 
void PopContext (void)
 
c_parser_context GetContext (void)
 
c_parser_context GetContextCopy (void)
 
void reset_declaration_counter (void)
 
int get_declaration_counter (void)
 
void init_c_parser_scope_stack (void)
 
void reset_c_parser_scope_stack (void)
 
void force_reset_c_parser_scope_stack (void)
 To be used by an error handler. More...
 
void push_new_c_parser_scope (void)
 
void pop_c_parser_scope_stack (void)
 
bool c_parser_scope_stack_empty_p (void)
 
string get_c_parser_current_scope (void)
 
string get_c_parser_nth_scope (int)
 
int c_parser_number_of_scopes (void)
 
int get_previous_c_lineno (void)
 
unsigned int character_occurences_in_string (string, char)
 Use a stack to survive to file inclusions if any. More...
 
int get_current_C_line_number (void)
 
int get_previous_C_line_number (void)
 Should be called just before get_current_C_line_number. More...
 
void set_current_C_line_number (void)
 
void push_current_C_line_number (void)
 The line number stack, designed for structured control structure, is not used yet. More...
 
int pop_current_C_line_number (void)
 
void reset_current_C_line_number (void)
 
void error_reset_current_C_line_number (void)
 
void reset_token_has_been_seen_p (void)
 
string get_current_C_comment (void)
 Return the current comment as a string to be freed by the caller and reset the current comment. More...
 
void push_current_C_comment (void)
 Push the current C comment so that we can get it back when building the statement later. More...
 
string pop_current_C_comment (void)
 Pop the current comment. More...
 
void update_C_comment (string)
 Add a comment to the current one. More...
 
void remove_LFs_from_C_comment (int)
 Remove "extra_LF" trailing LF from C_current_comment if they can be found at the end of the comment string. More...
 
void discard_C_comment (void)
 Discard a C comment because we don't know how to deal with it. More...
 
void reset_C_comment (bool)
 reset and reset_error should be handled differently More...
 
void error_reset_C_comment (bool)
 
void clear_C_comment (void)
 
void init_C_comment (void)
 
void c_error (char *)
 
void c_reset_lex (void)
 
int c_wrap (void)
 

Variables

FILE * c_in
 
int c_lineno
 the file read in by the c_lexer More...
 
entity DynamicArea
 These global variables are declared in ri-util/util.c. More...
 
entity StaticArea
 
entity HeapArea
 
entity StackArea
 
entity AllocatableArea
 
int C_line_increment
 from "clex.l" More...
 

Macro Definition Documentation

◆ c_parser_user_warning

#define c_parser_user_warning (   ...)     c_parser_user_warning_func(CURRENT_FUNCTION, __FILE__, __LINE__, __VA_ARGS__)

Definition at line 55 of file c_syntax-local.h.

◆ CParserError

#define CParserError (   m)    c_parser_error(CURRENT_FUNCTION, m)

Definition at line 54 of file c_syntax-local.h.

◆ FIRST_C_LINE_NUMBER

#define FIRST_C_LINE_NUMBER   (1)

Error handling.

Definition at line 51 of file c_syntax-local.h.

◆ get_label_prefix

#define get_label_prefix ( )    "-"

The labels in C have function scope...

but beware of inlining... and conflict with user labels To disambiguate labels, in case inlining is performed later and to suppress the potential for conflicts with user labels.

Temporary entities have to be generated to be replaced later by the final labels. The temporary entities should be eliminated from the symbol table...

Definition at line 41 of file c_syntax-local.h.

◆ UNDEFINED_C_LINE_NUMBER

#define UNDEFINED_C_LINE_NUMBER   (-1)

Definition at line 52 of file c_syntax-local.h.

Function Documentation

◆ c_error()

void c_error ( char *  )

◆ c_lex()

int c_lex ( )

◆ c_parse()

int c_parse ( )

Referenced by actual_c_parser().

+ Here is the caller graph for this function:

◆ c_parser_number_of_scopes()

int c_parser_number_of_scopes ( void  )

Definition at line 587 of file cyacc.tab.c.

588  {
590  return n;
591  }
static stack c_parser_scope_stack
Definition: cyacc.tab.c:512
int stack_size(const stack)
observers

References c_parser_scope_stack, and stack_size().

Referenced by is_c_parser_keyword_typedef().

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

◆ c_parser_scope_stack_empty_p()

bool c_parser_scope_stack_empty_p ( void  )

Definition at line 564 of file cyacc.tab.c.

565 {
567 }
bool stack_empty_p(const stack)

References c_parser_scope_stack, and stack_empty_p().

+ Here is the call graph for this function:

◆ c_reset_lex()

void c_reset_lex ( void  )

Referenced by c_parser_error().

+ Here is the caller graph for this function:

◆ c_wrap()

int c_wrap ( void  )

◆ character_occurences_in_string()

unsigned int character_occurences_in_string ( string  s,
char  c 
)

Use a stack to survive to file inclusions if any.

I guess that it is currently not used since file inclusion is already done by the preprocessor... RK To track the absolute line number in the file that is parsed use the default flex yylineno that is renamed c_lineno here Use a stack to survive to file inclusions if any Count the number of c in s.

Definition at line 1133 of file clexer.c.

1134 {
1135  string p = string_undefined;
1136  unsigned int count = 0;
1137 
1138  for(p=s; *p!='\0'; p++) {
1139  count += (*p==c)? 1 : 0 ;
1140  }
1141  return count;
1142 }
static int count
Definition: SDG.c:519
#define string_undefined
Definition: newgen_types.h:40

References count, and string_undefined.

◆ clear_C_comment()

void clear_C_comment ( void  )

Comments in the compilation unit and outside of function bodies are lost because they are related only to declarations and because comments on declarations are lost.

Definition at line 1489 of file clexer.c.

1490 {
1494  }
1495  /* Comments in the compilation unit and outside of function bodies
1496  are lost because they are related only to
1497  declarations and because comments on declarations are lost.*/
1498  if(!comments_empty_p()) {
1499  int count = 0;
1500  pips_debug(3, "Comments stack is not empty:\n");
1501  while(!comments_empty_p()) {
1502  string c = comments_pop();
1503  count++;
1504  pips_debug(3, "Element %d: \"%s\"\n",
1505  count, string_undefined_p(c) ? "string undefined" : c);
1506  if(!string_undefined_p(c))
1507  free(c);
1508  }
1509  }
1510  pips_assert("The comment stack is empty\n", comments_empty_p());
1511 }
static string C_current_comment
Comment management:
Definition: clexer.c:1266
void free(void *)
#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
#define string_undefined_p(s)
Definition: newgen_types.h:41

References C_current_comment, count, free(), pips_assert, pips_debug, string_undefined, and string_undefined_p.

+ Here is the call graph for this function:

◆ CreateDefaultContext()

c_parser_context CreateDefaultContext ( void  )

Definition at line 292 of file cyacc.tab.c.

293 {
297  NIL,
298  false,
299  false);
300  pips_debug(8, "New default context %p\n", c);
301  return c;
302 }
c_parser_context make_c_parser_context(string a1, type a2, storage a3, list a4, bool a5, bool a6)
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
string empty_scope()
Functions used to manage the block scoping in conjunction with ContextStack and yco ntext.
Definition: entity.c:498
#define type_undefined
Definition: ri.h:2883
#define storage_undefined
Definition: ri.h:2476

References empty_scope(), make_c_parser_context(), NIL, pips_debug, storage_undefined, and type_undefined.

+ Here is the call graph for this function:

◆ discard_C_comment()

void discard_C_comment ( void  )

Discard a C comment because we don't know how to deal with it.

The comments are only made of '
', just silently discarding them

Definition at line 1426 of file clexer.c.

1427 {
1430  == strlen(C_current_comment)) {
1431  /* The comments are only made of '\n', just silently discarding them */
1432  pips_debug(3,"The \\n are lost, so the code presentation may be wrong...\n");
1433  }
1434  else {
1435  /*
1436  pips_user_warning("Comment \"%s\" is lost at line %d, "
1437  "probably because comments cannot be attached to declarations.\n",
1438  C_current_comment, C_line_number);
1439  */
1440  pips_debug(8, "Comment \"%s\" is lost at line %d, "
1441  "probably because comments cannot be attached to declarations.\n",
1443  }
1446  }
1447 }
static int C_line_number
To track the user line number, that is the one in the original user file.
Definition: clexer.c:1102
unsigned int character_occurences_in_string(string s, char c)
Use a stack to survive to file inclusions if any.
Definition: clexer.c:1133

References C_current_comment, C_line_number, character_occurences_in_string(), free(), pips_debug, string_undefined, and string_undefined_p.

Referenced by MakeBlock().

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

◆ error_reset_C_comment()

void error_reset_C_comment ( bool  )

◆ error_reset_current_C_line_number()

void error_reset_current_C_line_number ( void  )

Definition at line 1224 of file clexer.c.

1225 {
1230 
1231  free_line_number_stack();
1232  free_absolute_line_number_stack();
1233 }
#define UNDEFINED_C_LINE_NUMBER
#define FIRST_C_LINE_NUMBER
Error handling.
int c_lineno
the file read in by the c_lexer
Definition: c_syntax.h:293
static int previous_C_line_number
Definition: clexer.c:1144
static int previous_c_lineno
To keep track of line intervals.
Definition: clexer.c:1113

References C_line_number, c_lineno, FIRST_C_LINE_NUMBER, previous_C_line_number, previous_c_lineno, and UNDEFINED_C_LINE_NUMBER.

Referenced by c_parser_error().

+ Here is the caller graph for this function:

◆ ExitScope()

void ExitScope ( void  )

Definition at line 400 of file cyacc.tab.c.

401 {
403 
405 
406  pips_assert("The current context is defined", !c_parser_context_undefined_p(c));
407  pips_assert("The current context scope is defined",
409  && c_parser_context_scope(c)!=NULL);
410  pips_assert("The current context only contains scope information",
411  //type_undefined_p(c_parser_context_type(c)) &&
414  //&& !c_parser_context_typedef(c)
415  //&& !c_parser_context_static(c)
416  );
417  pips_debug(8, "Exiting context scope \"\%s\" in context %p\n",
418  c_parser_context_scope(c), c);
420  (void) stack_pop(ContextStack);
423  //pips_assert("ycontext is consistant with stack_head(ContextStack)",
424  // ycontext==stack_head(ContextStack));
425  pips_debug(8, "Back to context scope \"\%s\" in context %p\n",
426  c_parser_context_scope(oc), oc);
427  }
428  else {
429  // ycontext = c_parser_context_undefined;
430  pips_debug(8, "Back to undefined context scope\n");
431  }
432 }
void free_c_parser_context(c_parser_context p)
stack ContextStack
Definition: c_parser.c:117
#define c_parser_context_undefined_p(x)
#define c_parser_context_storage(x)
#define c_parser_context_qualifiers(x)
struct _newgen_struct_c_parser_context_ * c_parser_context
#define c_parser_context_scope(x)
void pop_c_parser_scope_stack()
Definition: cyacc.tab.c:558
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
void * stack_head(const stack)
returns the item on top of stack s
Definition: stack.c:420
void * stack_pop(stack)
POPs one item from stack s.
Definition: stack.c:399
#define storage_undefined_p(x)
Definition: ri.h:2477

References c_parser_context_qualifiers, c_parser_context_scope, c_parser_context_storage, c_parser_context_undefined_p, ContextStack, ENDP, free_c_parser_context(), pips_assert, pips_debug, pop_c_parser_scope_stack(), stack_empty_p(), stack_head(), stack_pop(), storage_undefined_p, and string_undefined_p.

+ Here is the call graph for this function:

◆ force_reset_c_parser_scope_stack()

void force_reset_c_parser_scope_stack ( void  )

To be used by an error handler.

Definition at line 539 of file cyacc.tab.c.

540  {
544  }
546  return;
547  }
#define SCOPE_UNDEFINED
Each scope in the current unit has its own number.
Definition: cyacc.tab.c:510
static int c_parser_scope_number
Definition: cyacc.tab.c:511
#define stack_undefined
Definition: newgen_stack.h:55
void stack_free(stack *)
type, bucket_size, policy
Definition: stack.c:292

References c_parser_scope_number, c_parser_scope_stack, SCOPE_UNDEFINED, stack_free(), and stack_undefined.

Referenced by c_parser_error().

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

◆ get_c_parser_current_scope()

string get_c_parser_current_scope ( void  )

Definition at line 569 of file cyacc.tab.c.

570  {
571  string sn = string_undefined;
573  // We are at the global level: no scope has been entered yet
574  sn = "";
575  }
576  else
578  return sn;
579  }
bool c_parser_scope_stack_empty_p()
Definition: cyacc.tab.c:564
char * string
STRING.
Definition: newgen_types.h:39

References c_parser_scope_stack, c_parser_scope_stack_empty_p(), stack_head(), and string_undefined.

Referenced by c_parser_put_new_typedef(), and is_c_parser_keyword_typedef().

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

◆ get_c_parser_nth_scope()

string get_c_parser_nth_scope ( int  n)

Definition at line 581 of file cyacc.tab.c.

582  {
583  string sn = (string) stack_nth(c_parser_scope_stack, n);
584  return sn;
585  }
void * stack_nth(const stack, int)
returns the nth item starting from the head and counting from 1, when possible, or NULL,...
Definition: stack.c:436

References c_parser_scope_stack, and stack_nth().

Referenced by is_c_parser_keyword_typedef().

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

◆ get_current_C_comment()

string get_current_C_comment ( void  )

Return the current comment as a string to be freed by the caller and reset the current comment.

If the current comment is undefined, returns a copy of the empty string, "".

Reset also the current comment.

If the comment begins with a new-line, it is indeed the new-line that ends the previous statement, so skip it. Quicker than strlen()

  • memmove():

Note there won't be a memory leak since the orginal '\0' is in the malloc() bloc to be free()ed anyway...

If the comment is only an empty one, do not retain it:

Do retain it to keep the statement data structure easy to use, allowing strdup() on its text fields

Remove the trailing new-line if any since the RI is already line-oriented at the comment level: This is already done above.

It is a trailing new-line: just get rid of it:

pips_debug(3, "get_current_C_comment comment \"s"
", cc);

Definition at line 1282 of file clexer.c.

1283 {
1284  string cc = C_current_comment;
1286  if (cc != string_undefined) {
1287  if (cc[0] == '\n') {
1288  /* If the comment begins with a new-line, it is indeed the new-line
1289  that ends the previous statement, so skip it. Quicker than strlen()
1290  + memmove(): */
1291  char * p = &cc[0];
1292  do {
1293  p[0] = p[1];
1294  }
1295  while (*p++ != '\0');
1296  /* Note there won't be a memory leak since the orginal '\0' is in the
1297  malloc() bloc to be free()ed anyway... */
1298  }
1299  /* If the comment is only an empty one, do not retain it: */
1300  if (cc[0] == '\0') {
1301  /* Do retain it to keep the statement data structure easy to use, allowing strdup() on its text fields */
1302  //free(cc);
1303  //cc = string_undefined;
1304  ;
1305  }
1306  else {
1307  /* Remove the trailing new-line if any since the RI is already
1308  line-oriented at the comment level: This is already done above. */
1309  char * last_newline = strrchr(cc, '\n');
1310  if (last_newline != NULL && last_newline[1] == '\0') {
1311  /* It is a trailing new-line: just get rid of it: */
1312  //last_newline[0] = '\0';
1313  ;
1314  }
1315  }
1316  }
1317  else
1318  cc = strdup("");
1319  /* pips_debug(3, "get_current_C_comment comment \"%s\"\n",
1320  cc); */
1321  // Too early
1322  // token_has_been_seen_p = false;
1323  return cc;
1324 }
char * strdup()

References C_current_comment, strdup(), and string_undefined.

Referenced by ExpressionToStatement(), MakeCaseStatement(), MakeDefaultStatement(), and MakeGotoStatement().

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

◆ get_current_C_line_number()

int get_current_C_line_number ( void  )

FI: I assume that get_current_C_line_number is called only by some kind of make_statement()

The PIPS preprocessed C function files contain a specific first line to convert the line number in the workspace unto a line number in the user source file.

Definition at line 1146 of file clexer.c.

1147 {
1148  /* FI: I assume that get_current_C_line_number is called only
1149  * by some kind of make_statement()
1150  *
1151  * The PIPS preprocessed C function files contain a specific first line
1152  * to convert the line number in the workspace unto a line number in the
1153  * user source file.
1154  */
1157  return C_line_number;
1158 }

References C_line_number, c_lineno, previous_C_line_number, and previous_c_lineno.

Referenced by c_parser_error(), c_parser_user_warning_alist(), ExpressionToStatement(), FindEntityFromLocalNameAndPrefix(), MakeForloop(), MakeGotoStatement(), and MakeWhileLoop().

+ Here is the caller graph for this function:

◆ get_declaration_counter()

int get_declaration_counter ( void  )

Definition at line 497 of file cyacc.tab.c.

498  {
499  return declaration_counter;
500  }
static int declaration_counter
Declaration counter.
Definition: cyacc.tab.c:490

References declaration_counter.

Referenced by set_current_dummy_parameter_number().

+ Here is the caller graph for this function:

◆ get_previous_C_line_number()

int get_previous_C_line_number ( void  )

Should be called just before get_current_C_line_number.

Definition at line 1161 of file clexer.c.

1162 {
1163  return previous_C_line_number;
1164 }

References previous_C_line_number.

Referenced by c_parser_user_warning_alist().

+ Here is the caller graph for this function:

◆ get_previous_c_lineno()

int get_previous_c_lineno ( void  )

Definition at line 1115 of file clexer.c.

1116 {
1117  return previous_c_lineno;
1118 }

References previous_c_lineno.

Referenced by c_parser_user_warning_alist().

+ Here is the caller graph for this function:

◆ GetContext()

c_parser_context GetContext ( void  )

Definition at line 458 of file cyacc.tab.c.

459 {
460 
462 
465  else
466  // Should we return a default context?
467  // Not really compatible with a clean memory allocation policy
468  pips_internal_error("No current context");
469 
470  pips_debug(8, "Context %p is obtained from stack position %d\n",
472 
473  return c;
474 }
#define c_parser_context_undefined
#define pips_internal_error
Definition: misc-local.h:149

References c_parser_context_undefined, ContextStack, pips_debug, pips_internal_error, stack_empty_p(), stack_head(), and stack_size().

Referenced by FindOrCreateCurrentEntity().

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

◆ GetContextCopy()

c_parser_context GetContextCopy ( void  )

Definition at line 476 of file cyacc.tab.c.

477 {
480  pips_debug(8, "Context copy %p with scope \"%s\" is obtained from context %p with scope \"%s\" at stack position %d\n",
481  cc, c_parser_context_scope(cc),
484  return cc;
485 }
c_parser_context copy_c_parser_context(c_parser_context p)
C_PARSER_CONTEXT.

References c_parser_context_scope, ContextStack, copy_c_parser_context(), pips_debug, stack_head(), and stack_size().

+ Here is the call graph for this function:

◆ GetFunction()

entity GetFunction ( void  )

cproto workaround

cyacc.tab.c

from "cyacc.y"

Definition at line 146 of file cyacc.tab.c.

147 {
149  return f;
150 }
stack FunctionStack
Definition: c_parser.c:118
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15

References f(), FunctionStack, and stack_head().

+ Here is the call graph for this function:

◆ GetParentScope()

string GetParentScope ( void  )

Definition at line 387 of file cyacc.tab.c.

388 {
389  string s = "";
390 
393 
394  s = c_parser_context_scope(c);
395  }
396 
397  return s;
398 }

References c_parser_context_scope, ContextStack, stack_empty_p(), stack_nth(), and stack_size().

Referenced by FindEntityFromLocalNameAndPrefix().

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

◆ GetScope()

string GetScope ( void  )

FI: I do not know if it wouldn't be better to initialize the ContextStack with a default context before calling the C parser

Definition at line 371 of file cyacc.tab.c.

372 {
373  string s = "";
374 
375  /* FI: I do not know if it wouldn't be better to initialize the
376  ContextStack with a default context before calling the C
377  parser */
380 
381  s = c_parser_context_scope(c);
382  }
383 
384  return s;
385 }

References c_parser_context_scope, ContextStack, stack_empty_p(), and stack_head().

Referenced by CreateEntityFromLocalNameAndPrefix(), CreateMemberScope(), and FindEntityFromLocalNameAndPrefix().

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

◆ init_C_comment()

void init_C_comment ( void  )

Definition at line 1513 of file clexer.c.

1514 {
1515  bracket_depth = 0;
1517  pips_internal_error("Missing reset for C_current_comment");
1518  }
1519  if(!stack_undefined_p(comments_stack) && !STACK_NULL_P(comments_stack) && !comments_empty_p()) {
1520  pips_internal_error("Comment stack is not empty");
1521  }
1522  make_comments_stack();
1523  token_has_been_seen_p = false;
1524 }
static int bracket_depth
Definition: clexer.c:1274
static bool token_has_been_seen_p
To see if comments are collected within a statement or outside it is pretty easy to turn it on.
Definition: clexer.c:1268
#define STACK_NULL_P(s)
Definition: newgen_stack.h:53
#define stack_undefined_p(s)
Definition: newgen_stack.h:56

References bracket_depth, C_current_comment, pips_internal_error, STACK_NULL_P, stack_undefined_p, string_undefined_p, and token_has_been_seen_p.

Referenced by actual_c_parser().

+ Here is the caller graph for this function:

◆ init_c_parser_scope_stack()

void init_c_parser_scope_stack ( void  )

Definition at line 514 of file cyacc.tab.c.

515  {
517  pips_assert("The stack is undefined",
520  }
@ string_domain
Definition: genC.h:170
stack stack_make(int, int, int)
allocation
Definition: stack.c:246

References c_parser_scope_number, c_parser_scope_stack, pips_assert, stack_make(), stack_undefined_p, and string_domain.

Referenced by actual_c_parser().

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

◆ InitScope()

void InitScope ( void  )

Definition at line 306 of file cyacc.tab.c.

307 {
308  C_scope_identifier = -1;
309 }
static int C_scope_identifier
Definition: cyacc.tab.c:304

References C_scope_identifier.

Referenced by actual_c_parser().

+ Here is the caller graph for this function:

◆ pop_block_scope()

string pop_block_scope ( string  old_scope)

The scope is moved up the scope tree and a NULL is return when there are no more scope to explore.

get rid of last block separator

Parameters
old_scopeld_scope

Definition at line 235 of file cyacc.tab.c.

236 {
237  string new_scope = old_scope;
238  string last_scope = string_undefined;
239 
240  pips_debug(8, "old_scope = \"%s\"\n", old_scope);
241  pips_assert("old_scope is a scope", string_block_scope_p(old_scope));
242 
243  if(strlen(old_scope)>0) {
244  /* get rid of last block separator */
245  new_scope[strlen(new_scope)-1] = '\0';
246  last_scope = strrchr(new_scope, BLOCK_SEP_CHAR);
247 
248  if(last_scope==NULL)
249  *new_scope = '\0';
250  else
251  *(last_scope+1) = '\0';
252  }
253  else
254  new_scope = NULL;
255 
256  if(new_scope!=NULL) {
257  pips_debug(8, "new_scope = \"%s\"\n", new_scope);
258  pips_assert("new_scope is a scope", string_block_scope_p(new_scope));
259  }
260  else {
261  pips_debug(8, "new_scope = NULL\n");
262  }
263 
264  return new_scope;
265 }
#define BLOCK_SEP_CHAR
Definition: naming-local.h:51
bool string_block_scope_p(string s)
Definition: entity.c:511

References BLOCK_SEP_CHAR, pips_assert, pips_debug, string_block_scope_p(), and string_undefined.

Referenced by FindEntityFromLocalNameAndPrefixAndScope(), and FindOrCreateEntityFromLocalNameAndPrefixAndScope().

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

◆ pop_c_parser_scope_stack()

void pop_c_parser_scope_stack ( void  )

Definition at line 558 of file cyacc.tab.c.

559  {
561  return;
562  }

References c_parser_scope_stack, and stack_pop().

+ Here is the call graph for this function:

◆ pop_current_C_comment()

string pop_current_C_comment ( void  )

Pop the current comment.

Returns
the previous current comment.

This is typically used at the end of a statement to be built.

Note this do not set the current comment. Strange API...

Definition at line 1352 of file clexer.c.

1353 {
1354  string cc = comments_pop();
1355  if (string_undefined_p(cc))
1356  pips_debug(3, "empty comment popped at line %d\n",
1358  else
1359  pips_debug(3, "comment \"%s\" popped at line %d\n", cc,
1361  return cc;
1362 }
int get_current_C_line_number(void)
Definition: clexer.c:1146

References get_current_C_line_number(), pips_debug, and string_undefined_p.

Referenced by MakeForloop().

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

◆ pop_current_C_line_number()

int pop_current_C_line_number ( void  )

Definition at line 1202 of file clexer.c.

1203 {
1204  int ln = line_number_pop();
1205  c_lineno = absolute_line_number_pop();
1206 
1207  return ln;
1208 }

References c_lineno.

Referenced by MakeForloop().

+ Here is the caller graph for this function:

◆ PopContext()

void PopContext ( void  )

Definition at line 441 of file cyacc.tab.c.

442 {
444 
445  pips_debug(8, "Context %p with scope \"%s\" is popped from stack position %d\n",
447  (void)stack_pop(ContextStack);
449  pips_debug(8, "context stack is now empty\n");
450  }
451  else {
453  pips_debug(8, "Context %p with scope \"%s\" is top of stack at position %d\n",
455  }
456 }

References c_parser_context_scope, ContextStack, pips_debug, stack_empty_p(), stack_head(), stack_pop(), and stack_size().

+ Here is the call graph for this function:

◆ push_current_C_comment()

void push_current_C_comment ( void  )

Push the current C comment so that we can get it back when building the statement later.

This reset the current comment through get_current_C_comment()

Definition at line 1331 of file clexer.c.

1332 {
1333  string cc = get_current_C_comment();
1334 
1335  if (string_undefined_p(cc))
1336  pips_debug(3, "empty comment pushed at line %d\n",
1338  else
1339  pips_debug(3, "comment \"%s\" pushed at line %d\n", cc,
1341  comments_push(cc);
1342 }
string get_current_C_comment(void)
Return the current comment as a string to be freed by the caller and reset the current comment.
Definition: clexer.c:1282

References get_current_C_comment(), get_current_C_line_number(), pips_debug, and string_undefined_p.

+ Here is the call graph for this function:

◆ push_current_C_line_number()

void push_current_C_line_number ( void  )

The line number stack, designed for structured control structure, is not used yet.

Definition at line 1194 of file clexer.c.

1195 {
1196  int ln = get_current_C_line_number();
1197 
1198  line_number_push(ln);
1199  absolute_line_number_push(c_lineno);
1200 }

References c_lineno, and get_current_C_line_number().

+ Here is the call graph for this function:

◆ push_new_c_parser_scope()

void push_new_c_parser_scope ( void  )

Definition at line 549 of file cyacc.tab.c.

550  {
552  string sn = string_undefined;
553  (void) asprintf(&sn, "%d", c_parser_scope_number);
554  stack_push((void *) sn, c_parser_scope_stack);
555  return;
556  }
#define asprintf
Definition: misc-local.h:225
void stack_push(void *, stack)
stack use
Definition: stack.c:373

References asprintf, c_parser_scope_number, c_parser_scope_stack, stack_push(), and string_undefined.

+ Here is the call graph for this function:

◆ PushContext()

void PushContext ( c_parser_context  c)

Definition at line 434 of file cyacc.tab.c.

435 {
436  stack_push((char *) c, ContextStack);
437  pips_debug(8, "Context %p with scope \"%s\" is put in stack position %d\n",
439 }

References c_parser_context_scope, ContextStack, pips_debug, stack_push(), and stack_size().

+ Here is the call graph for this function:

◆ remove_LFs_from_C_comment()

void remove_LFs_from_C_comment ( int  extra_LF)

Remove "extra_LF" trailing LF from C_current_comment if they can be found at the end of the comment string.


Parameters
extra_LFxtra_LF

Definition at line 1398 of file clexer.c.

1399 {
1401  int l = strlen(C_current_comment);
1402  int c = 0;
1403  char * p = C_current_comment+l-1;
1404  pips_debug(3,"begin: %s\n", C_current_comment);
1405  // pips_assert("The comment string is longer than the number of LF to remove\n",
1406  // extra_LF<=l);
1407  if(extra_LF<=l) {
1408  while(c<extra_LF && *p=='\n') {
1409  c++;
1410  *p = '\000';
1411  p--;
1412  }
1413  if(c==extra_LF) { // We are fine
1414  ;
1415  }
1416  else {
1417  // Should be a pips_internal_warning()
1418  pips_user_warning("%d extraneous LF left in comment\n", extra_LF-c);
1419  }
1420  }
1421  pips_debug(3,"end: %s\n", C_current_comment);
1422  }
1423 }
#define pips_user_warning
Definition: misc-local.h:146

References C_current_comment, pips_debug, pips_user_warning, string_undefined, and token_has_been_seen_p.

Referenced by analyze_preprocessor_line().

+ Here is the caller graph for this function:

◆ reset_C_comment()

void reset_C_comment ( bool  is_compilation_unit_p)

reset and reset_error should be handled differently

Comments in the compilation unit are lost because they are related only to declarations and because comments on declarations are lost. Also, comments located at the end of a block are lost, as we do not generate an extra NOP to carry them.

pips_internal_error("Comments stack is not empty\n");

Parameters
is_compilation_unit_ps_compilation_unit_p

Definition at line 1450 of file clexer.c.

1451 {
1455  }
1456  /* Comments in the compilation unit are lost because they are related only to
1457  declarations and because comments on declarations are lost. Also, comments
1458  located at the end of a block are lost, as we do not generate an extra NOP to carry them. */
1459  if(!is_compilation_unit_p && !comments_empty_p()) {
1460  int count = 0;
1461  pips_user_warning("Comments stack is not empty (only meaningful comments are shown):\n");
1462  while(!comments_empty_p()) {
1463  string c = comments_pop();
1464  count++;
1465  if(strcmp(c, "\n")!=0)
1466  fprintf(stderr, "Element %d: \"%s\"\n", count, c);
1467  free(c);
1468  }
1469  /* pips_internal_error("Comments stack is not empty\n"); */
1470  }
1471  clear_C_comment();
1472  free_comments_stack();
1473  bracket_depth = -1;
1474  token_has_been_seen_p = false;
1475 }
void clear_C_comment()
Definition: clexer.c:1489
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...

References bracket_depth, C_current_comment, clear_C_comment(), count, fprintf(), free(), pips_user_warning, string_undefined, string_undefined_p, and token_has_been_seen_p.

Referenced by actual_c_parser(), and c_parser_error().

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

◆ reset_c_parser_scope_stack()

void reset_c_parser_scope_stack ( void  )

Definition at line 522 of file cyacc.tab.c.

523  {
528  }
529  else {
530  // pips_internal_error? Could be a bad input C file...
531  pips_user_warning("Parser scope stack is not empty.\n");
532  }
533  }
535  return;
536  }

References c_parser_scope_number, c_parser_scope_stack, pips_user_warning, SCOPE_UNDEFINED, stack_empty_p(), stack_free(), and stack_undefined.

Referenced by actual_c_parser().

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

◆ reset_current_C_line_number()

void reset_current_C_line_number ( void  )

Definition at line 1210 of file clexer.c.

1211 {
1216 
1217  if(!line_number_empty_p()) {
1218  pips_internal_error("Line number stack is not empty\n");
1219  }
1220  free_line_number_stack();
1221  free_absolute_line_number_stack();
1222 }

References C_line_number, c_lineno, FIRST_C_LINE_NUMBER, pips_internal_error, previous_C_line_number, previous_c_lineno, and UNDEFINED_C_LINE_NUMBER.

Referenced by actual_c_parser().

+ Here is the caller graph for this function:

◆ reset_declaration_counter()

void reset_declaration_counter ( void  )

Definition at line 492 of file cyacc.tab.c.

493  {
495  }

References declaration_counter.

Referenced by actual_c_parser(), and c_parser_error().

+ Here is the caller graph for this function:

◆ reset_expression_comment()

void reset_expression_comment ( void  )

we don't want an expression comment with new lines, it is disgracefull

Too bad. This should not happen, but it happens with comma expressions in header files

Definition at line 169 of file cyacc.tab.c.

170 {
172  /* Too bad. This should not happen, but it happens with comma
173  expressions in header files */
176  }
177 
179 }
static int expression_line_number
Definition: cyacc.tab.c:166
static string expression_comment
FI: these two variables are used in conjunction with comma expressions.
Definition: cyacc.tab.c:165
void free(void *)
#define STATEMENT_NUMBER_UNDEFINED
default values

References expression_comment, expression_line_number, free(), STATEMENT_NUMBER_UNDEFINED, string_undefined, and string_undefined_p.

Referenced by actual_c_parser(), and c_parser_error().

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

◆ reset_token_has_been_seen_p()

void reset_token_has_been_seen_p ( void  )

Definition at line 1270 of file clexer.c.

1270 {token_has_been_seen_p = false;}

References token_has_been_seen_p.

◆ scope_to_block_scope()

string scope_to_block_scope ( string  full_scope)

Allocate a new string containing only block scope information.

Parameters
full_scopeull_scope

Definition at line 268 of file cyacc.tab.c.

269 {
270  string l_scope = strrchr(full_scope, BLOCK_SEP_CHAR);
271  string f_scope = strchr(full_scope, MODULE_SEP);
272  string block_scope = string_undefined;
273 
274  pips_debug(8, "full_scope = \"%s\"\n", full_scope);
275 
276  if(f_scope==NULL)
277  f_scope = full_scope;
278  else
279  f_scope++;
280 
281  if(l_scope==NULL)
282  block_scope = strdup("");
283  else
284  block_scope = gen_strndup0(f_scope, (unsigned) (l_scope-f_scope+1));
285 
286  pips_debug(8, "f_scope = \"%s\", l_scope = \"%s\"\n", f_scope, l_scope);
287  pips_assert("block_scope is a scope", string_block_scope_p(block_scope));
288 
289  return block_scope;
290 }
#define MODULE_SEP
special characters to build entity names of various kinds
Definition: naming-local.h:27
string gen_strndup0(string, size_t)
Like strdup() but copy at most n characters.
Definition: string.c:83

References BLOCK_SEP_CHAR, gen_strndup0(), MODULE_SEP, pips_assert, pips_debug, strdup(), string_block_scope_p(), and string_undefined.

Referenced by constant_memory_access_path_to_location_name(), CreateEntityFromLocalNameAndPrefix(), CreateMemberScope(), FindEntityFromLocalNameAndPrefix(), and FindOrCreateCurrentEntity().

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

◆ ScopeStackSize()

int ScopeStackSize ( void  )

Definition at line 366 of file cyacc.tab.c.

367 {
368  return stack_size(ContextStack);
369 }

References ContextStack, and stack_size().

Referenced by FindEntityFromLocalNameAndPrefix().

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

◆ set_current_C_line_number()

void set_current_C_line_number ( void  )

Initialize the user line number...

... and the absolute line number in the current file

The first line is used to indicate the line number in the user source file

Some check on it first? It should have been disallocated by reset_current_C_line_number()

Definition at line 1166 of file clexer.c.

1167 {
1169  /* Initialize the user line number... */
1171  // Rely on preprocessor pragma lines, which are not always present
1172  // especially for code synthesized by PIPS...
1173  // C_line_number = UNDEFINED_C_LINE_NUMBER;
1175  /* ... and the absolute line number in the current file */
1177  /* The first line is used to indicate the line number in the user
1178  * source file
1179  */
1181  }
1182  else
1183  pips_internal_error("C_line_number not resetted\n");
1184 
1185  C_line_increment = 1;
1186 
1187  /* Some check on it first? It should have been disallocated by reset_current_C_line_number() */
1188  make_line_number_stack();
1189  make_absolute_line_number_stack();
1190 }
int C_line_increment
The line increment is set to zero when header files are parsed.
Definition: clexer.c:1110

References C_line_increment, C_line_number, c_lineno, FIRST_C_LINE_NUMBER, pips_internal_error, previous_C_line_number, previous_c_lineno, and UNDEFINED_C_LINE_NUMBER.

Referenced by actual_c_parser().

+ Here is the caller graph for this function:

◆ update_C_comment()

void update_C_comment ( string  a_comment)

Add a comment to the current one.

Do not add LFs that appear within a statement

Do not concatenate two comments without a LF

Parameters
a_comment_comment

Definition at line 1365 of file clexer.c.

1366 {
1367  /* Do not add LFs that appear within a statement */
1368  bool is_LF_p = *a_comment=='\n' && *(a_comment+1)=='\000';
1369  if(!(token_has_been_seen_p && a_comment!=NULL
1370  && is_LF_p)) {
1371  string new_comment = string_undefined;
1372  // FI: seems to imply that concatenate accepts string_undefined as an argument...
1374  /* Do not concatenate two comments without a LF */
1375  if(l>0 && *(C_current_comment+l-1)!='\n' && !is_LF_p)
1376  new_comment = strdup(concatenate(C_current_comment, "\n", a_comment, NULL));
1377  else
1378  new_comment = strdup(concatenate(C_current_comment, a_comment, NULL));
1379 
1382  C_current_comment = new_comment;
1383  }
1384  else {
1385  static int c = 0;
1386  c++;
1387  pips_debug(8, "LF ignored: %d\n", c++);
1388  }
1389 
1390  pips_debug(3,"update_C_comment %s\n",
1392  "still undefined" : C_current_comment);
1393 }
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183

References C_current_comment, concatenate(), free(), pips_debug, strdup(), string_undefined, string_undefined_p, and token_has_been_seen_p.

+ Here is the call graph for this function:

Variable Documentation

◆ AllocatableArea

entity AllocatableArea
extern

Definition at line 61 of file area.c.

◆ c_in

◆ C_line_increment

int C_line_increment
extern

from "clex.l"

from "clex.l"

The goal is to reconstruct the line number in the user file and not the line number in the preprocessed file.

This is performed in analyze_preprocessor_line() (util.c)

Definition at line 296 of file c_syntax.h.

Referenced by analyze_preprocessor_line().

◆ c_lineno

◆ DynamicArea

entity DynamicArea
extern

These global variables are declared in ri-util/util.c.

These global variables are declared in ri-util/util.c.

functions for areas Four areas used to allocate variables which are not stored in a Fortran common. These areas are just like Fortran commons, but the dynamic area is the only non-static area according to Fortran standard. The heap and the stack area are used to deal with Fortran ANSI extensions and C, pointers and allocatable arrays, and adjustable arrays (VLA in C). The dynamic area is stack allocated by most compilers but could be statically allocated since the array sizes are known.

Areas are declared for each module. These four global variables are managed by the Fortran and C parsers and used to allocate variables in the current module. Note that the C parser uses more areas at the same time to cope with global variables.

Definition at line 57 of file area.c.

Referenced by ComputeAddresses(), EndOfProcedure(), gfc2pips_code2instruction__TOP(), gfc2pips_computeAdressesDynamic(), gfc2pips_computeAdressesOfArea(), gfc2pips_expr2entity(), gfc2pips_expr2expression(), gfc2pips_vars_(), init_c_areas(), init_c_implicit_variables(), InitAreas(), make_empty_module(), MakeStorageRam(), MakeVariableStatic(), ParserError(), save_all_entities(), and SaveEntity().

◆ HeapArea

◆ StackArea

◆ StaticArea