PIPS
preprocessor.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SRCPATH   "PIPS_SRCPATH"
 Warning! Do not modify this file that is automatically generated! More...
 
#define CPP_PIPS_ENV   "PIPS_CPP"
 pre-processor and added options from environment More...
 
#define CPP_PIPS_OPTIONS_ENV   "PIPS_CPP_FLAGS"
 
#define FPP_PIPS_ENV   "PIPS_FPP"
 
#define FPP_PIPS_OPTIONS_ENV   "PIPS_FPP_FLAGS"
 
#define CPP_CPP   "cpp -C -std=c99"
 default preprocessor and basic options -C: do not discard comments... More...
 
#define CPP_CPPFLAGS   " -D__PIPS__ -D__HPFC__ -U__GNUC__ "
 #define CPP_CPPFLAGS " -P -D__PIPS__ -D__HPFC__ " More...
 
#define FPP_CPP   "gfortran -E"
 The preprocessor to use for Fortran files. More...
 
#define FPP_CPPFLAGS   " -P -D__PIPS__ -D__HPFC__ "
 The default preprocessor flags to use with Fortran files. More...
 
#define DEFAULT_PIPS_FLINT   "gfortran -Wall"
 
#define DEFAULT_PIPS_CC   "gcc -std=c99 -D__PIPS__ -D__HPFC__ -U__GNUC__ "
 See necessary definitions in pipsmake-rc.tex. More...
 
#define DEFAULT_PIPS_CC_FLAGS   " -Wall "
 
#define csplit_parser_warning(...)
 

Typedefs

typedef size_t yy_size_t
 symbols exported by lex / yacc More...
 

Functions

void MakeTypedefStack ()
 Define some functions from the .l or .y since cproto cannot dig them out: More...
 
void ResetTypedefStack ()
 
int splitc_lex ()
 
int splitc_lex_destroy ()
 
int splitc_parse ()
 
void splitc_error (const char *)
 
void pips_get_workspace_list (gen_array_t)
 cproto-generated files More...
 
void pips_get_fortran_list (gen_array_t)
 Select the true file with names ending in ".[fF]" and return a sorted arg list: More...
 
string hpfc_generate_path_name_of_file_name (const char *)
 Return the path of an HPFC file name relative to the current PIPS directory. More...
 
int hpfc_get_file_list (gen_array_t, char **)
 
string pips_change_directory (const char *)
 Change to the given directory if it exists and return a canonical name. More...
 
void pips_srcpath_set (string)
 Set the PIPS source path. More...
 
string pips_srcpath_append (string)
 returns an allocated pointer to the old value More...
 
void init_processed_include_cache (void)
 
void close_processed_include_cache (void)
 
bool filter_file (string)
 
string preprocessed_to_user_file (string)
 Allocate a new string containing the user file name, before preprocessing. More...
 
bool dot_F_file_p (string)
 Test if a name ends with .F. More...
 
bool dot_f_file_p (string)
 Test if a name ends with .f. More...
 
bool dot_f90_file_p (string)
 Test if a name ends with .f90. More...
 
bool dot_f95_file_p (string)
 Test if a name ends with .f95. More...
 
bool dot_c_file_p (string)
 Test if a name ends with .c. More...
 
language workspace_language (gen_array_t)
 Choose a language if all filenames in "files" have the same C or Fortran extensions. More...
 
int find_eol_coding (string)
 Returns the newly allocated name if preprocessing succeeds. More...
 
bool process_user_file (string)
 
bool flag_as_stub (const string)
 
bool bootstrap_stubs (const string)
 
char * fsplit (char *, char *, FILE *)
 
char * process_bang_comments_and_hollerith (FILE *, FILE *)
 processing extracted for includes... More...
 
void init_module_name_list (void)
 
void reset_module_name_list (void)
 
void error_reset_module_name_list (void)
 No checking, to be called from a (future) error handling module. More...
 
string get_splitc_input_file_name (void)
 
void reset_current_input_line (void)
 In file just above. More...
 
void csplit_open_compilation_unit (string)
 Disambiguate the compilation unit base name (special character to avoid conflicts with function names and rank if same basename exists elsewhere in user files). More...
 
void csplit_close_compilation_unit (void)
 
void copy_between_2_fd_up_to_offset (FILE *, FILE *, unsigned long long, bool)
 
void csplit_append_to_compilation_unit (int, unsigned long long)
 Copy the input file to the compilation unit between the function declarations up to the current function definition. More...
 
void csplit_copy (const char *, string, int, int, size_t, size_t, int, bool)
 Create the module directory and file, copy the definition of the module and add the module name to the module name list. More...
 
void keep_track_of_typedef (string)
 
void csplit_error_handler (void)
 Close open files and reset variables. More...
 
void csplit_reset (void)
 
void csplit_close_files (string)
 
void preprocessor_init_keyword_typedef_table (void)
 
string csplit (char *, char *, FILE *)
 
char * f95split (char *, char *, FILE **)
 f95split_file.c More...
 
void csplit_parser_warning_func (const char *, const char *, const int, const string,...)
 
void csplit_parser_error (const string)
 Redundant with splitc_error()? More...
 
void ForceResetTypedefStack (void)
 
void init_preprocessor_scope_stack (void)
 
void reset_preprocessor_scope_stack (void)
 
void force_reset_preprocessor_scope_stack (void)
 To be used by an error handler. More...
 
void push_new_preprocessor_scope (void)
 
void pop_preprocessor_scope (void)
 
bool preprocessor_scope_stack_empty_p (void)
 
string get_preprocessor_current_scope (void)
 
string get_preprocessor_nth_scope (int)
 
int preprocessor_scope_number (void)
 
int check_signature_balance (void)
 
void reset_csplit_line_number (void)
 Reinitialise global position numbers for a new file. More...
 
void reset_csplit_current_beginning (void)
 This function is called at the end of any top-level C construct: More...
 
int get_csplit_current_beginning (void)
 
int get_user_current_beginning (void)
 Get the current line number in the file to split from the user point of view (before preprocessor expansion): More...
 
size_t get_csplit_file_offset_beginning (void)
 Get the file position in the file to split where the current function begins: More...
 
size_t get_current_csplit_file_offset (void)
 Get the current file position in the file to split: More...
 
void update_csplit_file_offset_information (void)
 Function called each time a token is read to trac file position information: More...
 
void splitc_restart (FILE *)
 
void splitc_pop_buffer_state (void)
 
int splitc_get_lineno (void)
 
FILE * splitc_get_in (void)
 
FILE * splitc_get_out (void)
 
int splitc_get_leng (void)
 
char * splitc_get_text (void)
 
void splitc_set_lineno (int)
 
void splitc_set_in (FILE *)
 
void splitc_set_out (FILE *)
 
int splitc_get_debug (void)
 
void splitc_set_debug (int)
 
void * splitc_alloc (yy_size_t)
 
void * splitc_realloc (void *, yy_size_t)
 
void splitc_free (void *)
 
int splitc_wrap (void)
 

Variables

char * splitc_text
 
FILE * splitc_in
 
string preprocessor_current_split_file_name
 Split a C or Fortran file into as many files as modules. More...
 
string preprocessor_current_initial_file_name
 The digestion of a user file by PIPS begins here. More...
 
char fsplit_copyright []
 split_file.c More...
 
char fsplit_sccsid []
 not lint More...
 
char * current_include_file_path
 csplit_file.c More...
 
char * current_file_path
 
string current_file_name
 Split a C file into one file per module (function or procedure) plus. More...
 
int csplit_is_external
 splitc.c More...
 
int csplit_is_function
 to know if the variable is declared inside or outside a function More...
 
string csplit_current_function_name
 to know if this is the declaration of a function or not, to distinguish between a static variable and a static function More...
 
string csplit_current_function_name2
 
string csplit_definite_function_name
 
string csplit_definite_function_signature
 
bool csplit_is_static_p
 static int enum_counter = 0; More...
 
int splitc_char
 
int splitc_nerrs
 
int splitc_leng
 lexer.c More...
 
FILE * splitc_out
 
int splitc_lineno
 
int splitc__flex_debug
 
int csplit_line_number
 To be exported to the parser for splitting the preprocessed file. More...
 
int user_line_number
 To be exported to the parser for error messages related to the user file. More...
 
size_t current_csplit_file_offset
 
size_t csplit_file_offset_beginning
 
enum gather_comment_state_t gather_comment_state_machine
 Indeed it does not work since csplit_copy() is called from splitc.y when a function definition is found and thus we cannot gather the comment in it... More...
 

Macro Definition Documentation

◆ CPP_CPP

#define CPP_CPP   "cpp -C -std=c99"

default preprocessor and basic options -C: do not discard comments...

-P: inhibit linemakers (# 1 "file.c") -ffreestanding: ignore "stdc-predef.h"

Definition at line 52 of file preprocessor.h.

◆ CPP_CPPFLAGS

#define CPP_CPPFLAGS   " -D__PIPS__ -D__HPFC__ -U__GNUC__ "

#define CPP_CPPFLAGS " -P -D__PIPS__ -D__HPFC__ "

-U__GNUC__ seems to be still useful to avoid spoiling the libC files with too many GCC extensions:

Definition at line 57 of file preprocessor.h.

◆ CPP_PIPS_ENV

#define CPP_PIPS_ENV   "PIPS_CPP"

pre-processor and added options from environment

Definition at line 40 of file preprocessor.h.

◆ CPP_PIPS_OPTIONS_ENV

#define CPP_PIPS_OPTIONS_ENV   "PIPS_CPP_FLAGS"

Definition at line 41 of file preprocessor.h.

◆ csplit_parser_warning

#define csplit_parser_warning (   ...)
Value:
__VA_ARGS__)
#define CURRENT_FUNCTION
package arithmetique
void csplit_parser_warning_func(const char *, const char *, const int, const string,...)
Definition: splitc.c:174

Definition at line 81 of file preprocessor.h.

◆ DEFAULT_PIPS_CC

#define DEFAULT_PIPS_CC   "gcc -std=c99 -D__PIPS__ -D__HPFC__ -U__GNUC__ "

See necessary definitions in pipsmake-rc.tex.

Definition at line 74 of file preprocessor.h.

◆ DEFAULT_PIPS_CC_FLAGS

#define DEFAULT_PIPS_CC_FLAGS   " -Wall "

Definition at line 75 of file preprocessor.h.

◆ DEFAULT_PIPS_FLINT

#define DEFAULT_PIPS_FLINT   "gfortran -Wall"

Definition at line 70 of file preprocessor.h.

◆ FPP_CPP

#define FPP_CPP   "gfortran -E"

The preprocessor to use for Fortran files.

Alternative values: "gcc -E -C" or "fpp". The issue with cpp or gcc -E is that they don't undestand Fortran and chokes on unbalanced strings in Fortran comments and so on.

Definition at line 65 of file preprocessor.h.

◆ FPP_CPPFLAGS

#define FPP_CPPFLAGS   " -P -D__PIPS__ -D__HPFC__ "

The default preprocessor flags to use with Fortran files.

Definition at line 68 of file preprocessor.h.

◆ FPP_PIPS_ENV

#define FPP_PIPS_ENV   "PIPS_FPP"

Definition at line 42 of file preprocessor.h.

◆ FPP_PIPS_OPTIONS_ENV

#define FPP_PIPS_OPTIONS_ENV   "PIPS_FPP_FLAGS"

Definition at line 43 of file preprocessor.h.

◆ SRCPATH

#define SRCPATH   "PIPS_SRCPATH"

Warning! Do not modify this file that is automatically generated!

Modify src/Libs/preprocessor/preprocessor-local.h instead, to add your own modifications. header file built by cproto preprocessor-local.h Preprocessing and splitting of Fortran and C files the name of the environment variable where source files are searched for.

Definition at line 36 of file preprocessor.h.

Typedef Documentation

◆ yy_size_t

typedef size_t yy_size_t

symbols exported by lex / yacc

Definition at line 86 of file preprocessor.h.

Function Documentation

◆ bootstrap_stubs()

bool bootstrap_stubs ( const  string)
Parameters
stringodule_name

Definition at line 1344 of file source_file.c.

1345 {
1346  if (db_resource_p(DBR_STUBS, ""))
1347  pips_internal_error("kernels already initialized for %s", module_name);
1348  callees stubs=make_callees(NIL);
1349  DB_PUT_MEMORY_RESOURCE(DBR_STUBS,"",stubs);
1350  return true;
1351 }
callees make_callees(list a)
Definition: ri.c:227
bool db_resource_p(const char *rname, const char *oname)
true if exists and in loaded or stored state.
Definition: database.c:524
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
Definition: pipsdbm-local.h:66
#define pips_internal_error
Definition: misc-local.h:149

References DB_PUT_MEMORY_RESOURCE, db_resource_p(), make_callees(), module_name(), NIL, and pips_internal_error.

Referenced by generic_initializer().

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

◆ check_signature_balance()

int check_signature_balance ( void  )

pips_internal_error("More signatures freed than allocated: %d\n", imbalance);

Definition at line 524 of file splitc.c.

525  {
527  if(imbalance<0) {
528  /* pips_internal_error("More signatures freed than allocated: %d\n", imbalance); */
529  pips_debug(5, "More signatures freed than allocated: %d\n", imbalance);
530  }
531  return imbalance;
532  }
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
static int number_of_signatures_freed
Definition: splitc.c:356
static int number_of_signatures_built
If any of the strings is undefined, we are in trouble.
Definition: splitc.c:355

References number_of_signatures_built, number_of_signatures_freed, and pips_debug.

Referenced by reset_csplit_current_beginning().

+ Here is the caller graph for this function:

◆ close_processed_include_cache()

void close_processed_include_cache ( void  )

pips may call this without a prior call to init_processed_include_cache under some error conditions, such as a file not found in the initializer, or a failed cpp.

Definition at line 283 of file source_file.c.

284 {
285  //fprintf(stderr, "[close_processed_include_cache] Entering\n");
287  {
288  /* pips may call this without a prior call to
289  * init_processed_include_cache under some error conditions,
290  * such as a file not found in the initializer, or a failed cpp.
291  */
292  /*
293  Do not warn the user about PIPS internal architecture issues... :-/
294  pips_user_warning("no 'processed include cache' to close, "
295  "skipping...\n");
296  */
297  return;
298  }
300  HASH_MAP(k, v, { unlink(v); free(v); }, processed_cache);
303 }
void free(void *)
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define HASH_MAP(k, v, code, ht)
Definition: newgen_hash.h:60
#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
static hash_table processed_cache
cache of preprocessed includes
Definition: source_file.c:271

References free(), HASH_MAP, hash_table_free(), hash_table_undefined, hash_table_undefined_p, pips_assert, and processed_cache.

Referenced by check_delete_workspace(), and close_workspace().

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

◆ copy_between_2_fd_up_to_offset()

void copy_between_2_fd_up_to_offset ( FILE *  ,
FILE *  ,
unsigned long long  ,
bool   
)

◆ csplit()

string csplit ( char *  dir_name,
char *  file_name,
FILE *  out 
)

In case a error occurs

The same file is opened twice for parsing, for copying the compilation unit and for copying the modules.

splitc_in_copy = safe_fopen(file_name, "r");

Do not forget to catch what could remain after the last function up to the end of file:

Parameters
dir_nameir_name
file_nameile_name
outut

Definition at line 641 of file csplit_file.c.

645 {
646  string error_message = string_undefined;
647  current_file_name = file_name; /* In case a error occurs*/
648 
649  debug_on("CSPLIT_DEBUG_LEVEL");
650 
651  pips_debug(1, "Begin in directory %s for file %s\n", dir_name, file_name);
652 
653  /* The same file is opened twice for parsing, for copying the
654  compilation unit and for copying the modules. */
655 
656  if ((splitc_in = fopen(file_name, "r")) == NULL) {
657  fprintf(stderr, "csplit: cannot open %s\n", file_name);
658  return "cannot open file";
659  }
661 
662  current_workspace_name = dir_name;
663 
665  /* splitc_in_copy = safe_fopen(file_name, "r"); */
666 
668 
674  current_file_path = NULL;
675 
677  error_message = "PIPS preprocessor parser error";
678  }
679  TRY {
680  splitc_parse();
681  error_message = NULL;
683  }
684 
685  if(error_message==NULL) {
686  /* Do not forget to catch what could remain after the last function up
687  to the end of file: */
688  csplit_append_to_compilation_unit(INT_MAX, ULLONG_MAX);
690 
691  csplit_reset();
692  }
693  debug_off();
694 
695  return error_message;
696 }
static FILE * out
Definition: alias_check.c:128
#define CATCH(what)
@ any_exception_error
catch all
#define UNCATCH(what)
#define TRY
char * current_file_path
Definition: csplit_file.c:52
static string splitc_input_file_name
File management.
Definition: csplit_file.c:82
string current_file_name
Split a C file into one file per module (function or procedure) plus.
Definition: csplit_file.c:640
static FILE * module_list_file
Compilation unit.
Definition: csplit_file.c:102
void csplit_open_compilation_unit(string input_file_name)
Disambiguate the compilation unit base name (special character to avoid conflicts with function names...
Definition: csplit_file.c:116
void csplit_reset()
Definition: csplit_file.c:539
static FILE * splitc_in_append
The FILE descriptor used to generate the compilation unit:
Definition: csplit_file.c:90
void preprocessor_init_keyword_typedef_table()
Definition: csplit_file.c:567
void csplit_close_files(string file_name)
Definition: csplit_file.c:547
static string current_workspace_name
Definition: csplit_file.c:104
char * current_include_file_path
used to keep track of include level
Definition: csplit_file.c:51
void csplit_append_to_compilation_unit(int last_line, unsigned long long last_offset)
Copy the input file to the compilation unit between the function declarations up to the current funct...
Definition: csplit_file.c:262
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
#define string_undefined
Definition: newgen_types.h:40
FILE * splitc_in
Definition: preprocessor.h:174
void MakeTypedefStack()
Define some functions from the .l or .y since cproto cannot dig them out:
Definition: splitc.c:243
int splitc_parse()
void init_preprocessor_scope_stack(void)
Definition: splitc.c:274
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
static string file_name

References any_exception_error, CATCH, csplit_append_to_compilation_unit(), csplit_close_files(), csplit_open_compilation_unit(), csplit_reset(), current_file_name, current_file_path, current_include_file_path, current_workspace_name, debug_off, debug_on, file_name, fprintf(), init_preprocessor_scope_stack(), MakeTypedefStack(), module_list_file, out, pips_debug, preprocessor_init_keyword_typedef_table(), safe_fopen(), splitc_in, splitc_in_append, splitc_input_file_name, splitc_parse(), string_undefined, TRY, and UNCATCH.

Referenced by pips_split_file().

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

◆ csplit_append_to_compilation_unit()

void csplit_append_to_compilation_unit ( int  last_line,
unsigned long long  last_offset 
)

Copy the input file to the compilation unit between the function declarations up to the current function definition.

We are in the offset mode instead of line mode

Copy up to function begin

We are in the line-oreiented mode:

In some cases, e.g. two module definitions are contiguous, nothing has to be copied.

Parameters
last_lineast_line
last_offsetast_offset

Definition at line 262 of file csplit_file.c.

263  {
264  pips_debug(2, "append to compilation unit up-to line %d (from %d) or offset %llu\n",
265  last_line, current_input_line, last_offset);
266 
267  if (last_offset != 0) {
268  /* We are in the offset mode instead of line mode */
269  pips_debug(2, "copying to compilation unit file up to offset %llu, we are at currently at offset %lu\n",
270  last_offset, ftell(splitc_in_append));
273  last_offset,
274  true /* Copy up to function begin */);
275  }
276  else {
277  /* We are in the line-oreiented mode: */
278  pips_assert("last_line is positive", last_line >= 0);
279  pips_assert("if last_line is strictly less than current_input_line, then last_line is 0",
280  last_line >= current_input_line || last_line == 0);
281 
282  pips_assert("The compilation unit file is open", compilation_unit_file != NULL);
283 
284  if(last_line == 0)
285  current_input_line = 0;
286  else {
287  /* In some cases, e.g. two module definitions are contiguous, nothing
288  has to be copied. */
289  while(current_input_line < last_line) {
290  char c = fgetc(splitc_in_append);
291 
292  ifdebug(5)
293  putc(c, stderr);
294  fputc(c, compilation_unit_file);
295  if(c == '\n')
297  }
298  }
299  }
300 }
static FILE * compilation_unit_file
includes FILE_SEP_STRING as a suffix.
Definition: csplit_file.c:100
void copy_between_2_fd_up_to_offset(FILE *source, FILE *destination, unsigned long long up_to_offset, bool greedy_spaces __attribute__((__unused__)))
Copy data from on file to another up to an offset.
Definition: csplit_file.c:208
static int current_input_line
Definition: csplit_file.c:91
if(!(yy_init))
Definition: genread_lex.c:1029
#define ifdebug(n)
Definition: sg.c:47

References compilation_unit_file, copy_between_2_fd_up_to_offset(), current_input_line, ifdebug, pips_assert, pips_debug, and splitc_in_append.

Referenced by csplit(), and csplit_copy().

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

◆ csplit_close_compilation_unit()

void csplit_close_compilation_unit ( void  )

Definition at line 183 of file csplit_file.c.

184 {
191 }
static string current_compilation_unit_file_name
Definition: csplit_file.c:98
static string current_compilation_unit_name
Definition: csplit_file.c:99
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
void reset_preprocessor_scope_stack(void)
Definition: splitc.c:280

References compilation_unit_file, current_compilation_unit_file_name, current_compilation_unit_name, free(), reset_preprocessor_scope_stack(), safe_fclose(), and string_undefined.

Referenced by csplit_close_files().

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

◆ csplit_close_files()

void csplit_close_files ( string  file_name)

No close, because this file descriptor is managed by the caller.

Parameters
file_nameile_name

Definition at line 547 of file csplit_file.c.

548 {
552  current_file_path=NULL;
555  splitc_in = NULL;
558  splitc_in_append = NULL;
559  /*
560  safe_fclose(splitc_in_copy, file_name);
561  splitc_in_copy = NULL;
562  */
563  /* No close, because this file descriptor is managed by the caller. */
564  module_list_file = NULL;
565 }
void csplit_close_compilation_unit()
Definition: csplit_file.c:183
void ForceResetTypedefStack(void)
Definition: splitc.c:259

References csplit_close_compilation_unit(), current_file_path, current_include_file_path, file_name, ForceResetTypedefStack(), free(), module_list_file, safe_fclose(), splitc_in, splitc_in_append, splitc_input_file_name, and string_undefined.

Referenced by csplit(), and csplit_parser_error().

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

◆ csplit_copy()

void csplit_copy ( const char *  module_name,
string  signature,
int  first_line,
int  last_line,
size_t  first_offset,
size_t  last_offset,
int  user_first_line,
bool  is_static_p 
)

Create the module directory and file, copy the definition of the module and add the module name to the module name list.

The compilation unit name used for static functions is retrieved from a global variable set by csplit_open_compilation_unit(), current_compilation_unit_name.

If first_offset and last_offset are not both 0, the module is found in the source file between these file offset instead of between lines first_line and int last_line.

Unambiguous, unless the user has given the same name to two functions.

MODULE_SEP_STRING,

string unambiguous_module_name = module_name;

Keep track of the existence of a C main function in the workspace

pips_assert("First line is strictly positive and lesser than last_line", first_line>0 && first_line<last_line);

Step 1: Define an unambiguous name and open the file if possible

Concatenate the unambigous compilation unit name and the module name

Note: the same static function may be declared twice in the compilation unit because the user is mistaken.

pips_internal_error("Not implemented yet.");

FILE_SEP_STRING,

The name should be unique in the workspace, but the user may have provided several module with the same name

Open the module code file for writing as the mfd FILE descriptor:

Such a module already exists

Possible access right problem?

Step 2: Copy the file source from the end of the last function definition up to the begin of the current one into the compilation unit to get variable and type declarations, etc.

Only bother in line-oriented mode

Step 3: Copy the function declaration in its module file, starting with its line number in the original file.

skip is up to the C preprocessor choice for local files: foo.c or ./foo.c.

It does not really matter because the ambiguity is taken care of by the PIPS C parser.

Begin and end are specified as line numbers:

Begin and end are specified as file offsets. First seek at the begin of the function:

Copy up to the function end:

Do not include trailing spaces

Step 4: Copy the function definition

Fabien: you could add here anything you might want to unsplit the file later. SG: what about inline static ? why add an extern qualifier ?

check for the static qualifier

or the extern qualifier

default to extern qualifier? Not mandatory, but expected by the C parser

Step 5: Keep track of the new module

SG hook: do not keep track of module declared inside a header not very reliable in the presence of used inline function in user header, so left apart as of now

Do not free unambiguous_module_name since it is already done in reset_csplit_current_beginning()

Parameters
module_nameodule_name
signatureignature
first_lineirst_line
last_lineast_line
first_offsetirst_offset
last_offsetast_offset
user_first_lineser_first_line
is_static_ps_static_p

Definition at line 334 of file csplit_file.c.

341 {
342  FILE * mfd = NULL;
343  /* Unambiguous, unless the user has given the same name to two functions. */
344  string unambiguous_module_file_name;
345  const char* unambiguous_module_name = is_static_p?
346  strdup(concatenate(current_compilation_unit_name, /* MODULE_SEP_STRING,*/ module_name, NULL)) :
347  module_name;
348  /* string unambiguous_module_name = module_name; */
349 
350  if(same_string_p(module_name, "main")) {
351  /* Keep track of the existence of a C main function in the workspace*/
352  // full_name() in split_file.c... but declared static
353  char * main_list = strdup(concatenate(current_workspace_name, "/", MAIN_FILE_NAMES, NULL));
354  FILE * fm = fopen(main_list, "a");
355  if (fm==NULL) {
356  fprintf(stderr, "fopen(\"%s\", ...) failed\n", main_list);
357  // FI: not user friendly...
358  abort();
359  }
360  fputs(module_name, fm);
361  putc('\n', fm);
362  fclose(fm);
363  free(main_list);
364  }
365 
366  /* pips_assert("First line is strictly positive and lesser than last_line",
367  first_line>0 && first_line<last_line); */
368  if(!(first_line > 0 && first_line <= last_line)) {
369  pips_user_error("Definition of function %s starts at line %d and ends a t line %d\n"
370  "PIPS assumes the function definition to start on a new line "
371  "after the function signature\n", module_name, first_line, last_line);
372  }
373  pips_assert("current_compilation_unit_name is defined",
375 
376  /* Step 1: Define an unambiguous name and open the file if possible */
377  if(is_static_p) {
378  /* Concatenate the unambigous compilation unit name and the module name */
379  /* Note: the same static function may be declared twice in the
380  compilation unit because the user is mistaken. */
381  /* pips_internal_error("Not implemented yet."); */
382  unambiguous_module_file_name
384  /* FILE_SEP_STRING, */ module_name, C_FILE_SUFFIX, NULL));
385  }
386  else {
387  /* The name should be unique in the workspace, but the user may have
388  provided several module with the same name */
389  unambiguous_module_file_name
390  = strdup(concatenate(current_workspace_name, "/", module_name, C_FILE_SUFFIX, NULL));
391  }
392 
393  /* Open the module code file for writing as the mfd FILE descriptor: */
394  pips_debug(1, "Begin for %s module \"%s\" from line %d to line %d (offset [%zd-%zd]) in compilation unit %s towards %s\n",
395  is_static_p? "static" : "global",
396  module_name,
397  first_line, last_line, first_offset, last_offset,
399  unambiguous_module_file_name);
400 
401  if((mfd=fopen(unambiguous_module_file_name, "r"))!=NULL) {
402  /* Such a module already exists */
403  pips_user_error("Duplicate function \"%s\".\n"
404  "Copy in file %s from input file %s is ignored\n"
405  "Check source code with a compiler or set property %s\n",
406  module_name,
407  unambiguous_module_file_name,
409  "PIPS_CHECK_FORTRAN");
410  }
411  else if((mfd=fopen(unambiguous_module_file_name, "w"))==NULL) {
412  /* Possible access right problem? */
413  pips_user_error("Access or creation right denied for %s\n",
414  unambiguous_module_file_name);
415  }
416 
417  pips_assert("The module file descriptor is defined", mfd!=NULL);
418 
419  /* Step 2: Copy the file source from the end of the last function
420  definition up to the begin of the current one into the compilation
421  unit to get variable and type declarations, etc. */
422  csplit_append_to_compilation_unit(first_line - 1, first_offset);
423 
424  pips_assert("Current position is OK", /* Only bother in line-oriented mode */
425  (first_offset != 0 || last_offset != 0) || current_input_line == first_line-1);
426 
427  /* Step 3: Copy the function declaration in its module file, starting
428  with its line number in the original file. */
429 
430  /* skip is up to the C preprocessor choice for local files: foo.c or
431  * ./foo.c.
432  *
433  * It does not really matter because the ambiguity is taken care of
434  * by the PIPS C parser.
435  */
436  int skip = 0;
437  char * p = (char *) preprocessor_current_initial_file_name;
438  if(*p=='.' && *(p+1)=='/')
439  skip = 2;
440  fprintf(mfd, "# %d \"%s\"\n", user_first_line,
442  //preprocessor_current_split_file_name);
443  if (first_offset == 0 && last_offset == 0) {
444  pips_debug(2, "copying to module file lines [%d-%d]\n",
445  current_input_line, last_line);
446  /* Begin and end are specified as line numbers: */
447  while(current_input_line<last_line) {
448  char c = fgetc(splitc_in_append);
449  ifdebug(5)
450  putc(c, stderr);
451  fputc(c, mfd);
452  if(c=='\n')
454  }
455  }
456  else {
457  pips_debug(2, "copying to module file offset [%zd-%zd]\n",
458  first_offset, last_offset);
459  /* Begin and end are specified as file offsets. First seek at the begin
460  of the function: */
461  //safe_fseek(splitc_in_append, first_offset, SEEK_SET, "splitc_in_append");
462  /* Copy up to the function end: */
464  mfd,
465  last_offset,
466  false /* Do not include trailing spaces */);
467  }
468 
469  /* Step 4: Copy the function definition */
470  /* Fabien: you could add here anything you might want to unsplit the
471  file later.
472  SG: what about inline static ? why add an extern qualifier ?
473  */
474  /* check for the static qualifier */
475  char * where;
476  if( (where = strstr(signature,"static") ) &&
477  isspace(where[sizeof("static")-1]) &&
478  ( where == signature || isspace(where[-1]) )
479  ) {
480  fprintf(compilation_unit_file, "# %d \"%s\"\n", user_first_line,
482  fprintf(compilation_unit_file, "%s;\n", signature);
483  }
484  /* or the extern qualifier */
485  else if ( (where = strstr(signature,"extern") ) &&
486  isspace(where[sizeof("extern")-1]) &&
487  ( where == signature || isspace(where[-1]) )
488  ){
489  fprintf(compilation_unit_file, "%s;\n", signature);
490  }
491  /* default to extern qualifier? Not mandatory, but expected by the C parser */
492  else {
493  fprintf(compilation_unit_file, "# %d \"%s\"\n", (int) user_first_line,
495  fprintf(compilation_unit_file, "extern %s;\n", signature);
496  // fprintf(compilation_unit_file, "%s;\n", signature);
497  }
498 
499  /* Step 5: Keep track of the new module */
500  /* SG hook: do not keep track of module declared inside a header
501  * not very reliable in the presence of used inline function in user header,
502  * so left apart as of now
503  */
504  if(true || !get_bool_property("IGNORE_FUNCTION_IN_HEADER")
506  fprintf(module_list_file, "%s %s\n", unambiguous_module_name, unambiguous_module_file_name);
507  }
508 
509 
510  safe_fclose(mfd, unambiguous_module_file_name);
511  free(unambiguous_module_file_name);
512  /* Do not free unambiguous_module_name since it is already done in
513  reset_csplit_current_beginning() */
514  //free(unambiguous_module_name);
515 }
static bool path_header_p(const char *filepath)
Definition: csplit_file.c:318
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define abort()
Definition: misc-local.h:53
#define pips_user_error
Definition: misc-local.h:147
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
#define same_string_p(s1, s2)
#define string_undefined_p(s)
Definition: newgen_types.h:41
#define MAIN_FILE_NAMES
Name of the file containing the names of the main procedures.
Definition: pipsdbm-local.h:41
string preprocessor_current_initial_file_name
The digestion of a user file by PIPS begins here.
Definition: source_file.c:1088
char * strdup()
else
Definition: set.c:239

References abort, compilation_unit_file, concatenate(), copy_between_2_fd_up_to_offset(), csplit_append_to_compilation_unit(), current_compilation_unit_name, current_include_file_path, current_input_line, current_workspace_name, fprintf(), free(), get_bool_property(), ifdebug, MAIN_FILE_NAMES, module_list_file, module_name(), path_header_p(), pips_assert, pips_debug, pips_user_error, preprocessor_current_initial_file_name, safe_fclose(), same_string_p, splitc_in_append, splitc_input_file_name, strdup(), and string_undefined_p.

+ Here is the call graph for this function:

◆ csplit_error_handler()

void csplit_error_handler ( void  )

Close open files and reset variables.

Reset keyword table

Definition at line 531 of file csplit_file.c.

532 {
533  /* Reset keyword table */
537 }
void reset_current_input_line(void)
In file just above.
Definition: csplit_file.c:93
void reset_csplit_line_number()
Reinitialise global position numbers for a new file.
Definition: lexer.c:1124
void free_keyword_typedef_table(void)
Definition: static.c:275

References free_keyword_typedef_table(), reset_csplit_line_number(), and reset_current_input_line().

Referenced by csplit_parser_error().

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

◆ csplit_open_compilation_unit()

void csplit_open_compilation_unit ( string  input_file_name)

Disambiguate the compilation unit base name (special character to avoid conflicts with function names and rank if same basename exists elsewhere in user files).

Do not create the corresponding directory and within it the compilation unit file.

Initialize compilation_unit_file by opening this last file.

Set the current_compilation_unit_file_name.

string compilation_unit_name = string_undefined;

string compilation_unit_file_name = string_undefined;

Step 1: Define the compilation unit name from the input file name.

Loop with a counter until the open is OK. Two or more files with the same local names may be imported from different directories.

This does not work because this file is later moved in the proper directory.

Loop over counter not implemented.

Does this current compilation unit already exist?

Keep track of the new compilation unit as a "module" stored in a file

Parameters
input_file_namenput_file_name

Definition at line 116 of file csplit_file.c.

117 {
118  string unambiguous_file_name = string_undefined;
119  string simpler_file_name = pips_basename(input_file_name, PP_C_ED);
120  /* string compilation_unit_name = string_undefined; */
121  /* string compilation_unit_file_name = string_undefined; */
122 
123  pips_debug(1, "Open compilation unit \"%s\"\n", input_file_name);
124 
125  pips_assert("No current compilation unit",
127 
128  pips_assert("No current compilation unit",
130 
131  /* Step 1: Define the compilation unit name from the input file name. */
132  unambiguous_file_name = strdup(concatenate(current_workspace_name,
133  "/",
134  simpler_file_name,
136  C_FILE_SUFFIX,
137  NULL));
138 
139  /* Loop with a counter until the open is OK. Two or more files with the
140  same local names may be imported from different directories. */
141  /* This does not work because this file is later moved in the proper directory. */
142  /*
143  if(fopen(unambiguous_file_name, "r")!=NULL) {
144  pips_internal_error("Two source files (at least) with same name: \"%s\"",
145  simpler_file_name);
146  }
147  */
148  compilation_unit_file = safe_fopen(unambiguous_file_name, "w");
149 
150  /* Loop over counter not implemented. */
151 
152  pips_assert("compilation_unit_file is defined",
153  compilation_unit_file != NULL);
154 
155  current_compilation_unit_file_name = unambiguous_file_name;
157  = strdup(concatenate(simpler_file_name, FILE_SEP_STRING, NULL));
158 
159  /* Does this current compilation unit already exist? */
161  "/",
162  simpler_file_name,
164  "/",
165  simpler_file_name,
167  C_FILE_SUFFIX, NULL)
168  , "r")!=NULL) {
169  pips_user_error("Two source files (at least) with same name: \"%s"
170  C_FILE_SUFFIX "\".\n"
171  "Not supported yet.\n",
172  simpler_file_name);
173  }
174 
175  /* Keep track of the new compilation unit as a "module" stored in a file */
176 
177  fprintf(module_list_file, "%s %s\n",
180  free(simpler_file_name);
181 }
char * pips_basename(char *fullpath, char *suffix)
Definition: file.c:822
#define FILE_SEP_STRING
Definition: naming-local.h:41

References compilation_unit_file, concatenate(), current_compilation_unit_file_name, current_compilation_unit_name, current_workspace_name, FILE_SEP_STRING, fprintf(), free(), module_list_file, pips_assert, pips_basename(), pips_debug, pips_user_error, safe_fopen(), strdup(), string_undefined, and string_undefined_p.

Referenced by csplit().

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

◆ csplit_parser_error()

void csplit_parser_error ( const  string)

Redundant with splitc_error()?

Should add the current line number of the lexer

csplit_parser_warning("Corrupted or non-supported C constructs.\n"

"Make sure your code is compiled by gcc -stc=c99 first, "

"and/or set proper PIPS option, "

"CHECK_FORTRAN_SYNTAX_BEFORE_RUNNING_PIPS or "

"CHECK_C_SYNTAX_BEFORE_RUNNING_PIPS.\n");

Reset all static variables

Close all open files: at least three...

Parameters
stringsg

Definition at line 188 of file splitc.c.

189 {
190  /* Should add the current line number of the lexer */
191 
192  /* csplit_parser_warning("Corrupted or non-supported C constructs.\n" */
193  /* "Make sure your code is compiled by gcc -stc=c99 first, " */
194  /* "and/or set proper PIPS option, " */
195  /* "CHECK_FORTRAN_SYNTAX_BEFORE_RUNNING_PIPS or " */
196  /* "CHECK_C_SYNTAX_BEFORE_RUNNING_PIPS.\n"); */
197 
199 
200  //pips_internal_error("Not implemented yet\n."
201  // " Should reset all static variables.\n");
202  /* Reset all static variables */
203  /* Close all open files: at least three... */
204  extern string current_file_name;
207 
208  // See syn_reset_lex() -> syn_restart(syn_in); as in ParserError,
209  // the error routine for the Fortran parser, but its lexer is
210  // made of two passes, a Fortran-specific first pass and a lex second pass
211  // syn_restart(splitc_in);
212  // yy_flush_buffer(); //YY_FLUSH_BUFFER;
213  splitc_lex_destroy(); // trial and error
214  // BEGIN(0); we might have to reset the state of lex
215 
216  //pips_user_error(s);
217  pips_user_error("Corrupted or non-supported C constructs.\n"
218  "Make sure your code is compiled by gcc -stc=c99 first, "
219  "and/or set proper PIPS option, "
220  "CHECK_FORTRAN_SYNTAX_BEFORE_RUNNING_PIPS or "
221  "CHECK_C_SYNTAX_BEFORE_RUNNING_PIPS.\n");
222 }
void csplit_error_handler()
Close open files and reset variables.
Definition: csplit_file.c:531
int splitc_lex_destroy()
#define csplit_parser_warning(...)

References csplit_close_files(), csplit_error_handler(), csplit_parser_warning, current_file_name, pips_user_error, and splitc_lex_destroy().

+ Here is the call graph for this function:

◆ csplit_parser_warning_func()

void csplit_parser_warning_func ( const char *  pips_func,
const char *  pips_file,
const int  pips_line,
const  string,
  ... 
)
Parameters
pips_funcips_func
pips_fileips_file
pips_lineips_line
stringormat

Definition at line 174 of file splitc.c.

180 {
181  va_list args;
182  va_start(args, format);
183  csplit_parser_warning_alist(pips_func, pips_file, pips_line, format, &args);
184  va_end(args);
185 }
static void csplit_parser_warning_alist(const char *pips_func, const char *pips_file, const int pips_line, const string format, va_list *args)
Definition: splitc.c:146

References csplit_parser_warning_alist().

+ Here is the call graph for this function:

◆ csplit_reset()

void csplit_reset ( void  )

Reset keyword table

Definition at line 539 of file csplit_file.c.

540 {
541  /* Reset keyword table */
545 }

References free_keyword_typedef_table(), reset_csplit_line_number(), and reset_current_input_line().

Referenced by csplit().

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

◆ dot_c_file_p()

bool dot_c_file_p ( string  name)

Test if a name ends with .c.

Parameters
nameame

Definition at line 661 of file source_file.c.

661  {
662  return !!find_suffix(name, C_FILE_SUFFIX);
663 }
string find_suffix(const string, const string)
Find if a string s end with a suffix.
Definition: string.c:273

References find_suffix().

Referenced by get_new_user_file(), pips_split_file(), process_user_file(), and workspace_language().

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

◆ dot_f90_file_p()

bool dot_f90_file_p ( string  name)

Test if a name ends with .f90.

Parameters
nameame

Definition at line 649 of file source_file.c.

649  {
650  return !!find_suffix( name, FORTRAN90_FILE_SUFFIX );
651 }

References find_suffix().

Referenced by create_workspace(), get_new_user_file(), pips_split_file(), process_user_file(), and workspace_language().

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

◆ dot_f95_file_p()

bool dot_f95_file_p ( string  name)

Test if a name ends with .f95.

Parameters
nameame

Definition at line 655 of file source_file.c.

655  {
656  return !!find_suffix( name, FORTRAN95_FILE_SUFFIX );
657 }

References find_suffix().

Referenced by create_workspace(), get_new_user_file(), pips_split_file(), process_user_file(), and workspace_language().

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

◆ dot_F_file_p()

bool dot_F_file_p ( string  name)

Test if a name ends with .F.

Parameters
nameame

Definition at line 637 of file source_file.c.

637  {
638  return !!find_suffix(name, RATFOR_FILE_SUFFIX);
639 }

References find_suffix().

Referenced by pips_split_file(), process_thru_cpp(), process_user_file(), and workspace_language().

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

◆ dot_f_file_p()

bool dot_f_file_p ( string  name)

Test if a name ends with .f.

Parameters
nameame

Definition at line 643 of file source_file.c.

643  {
644  return !!find_suffix(name, FORTRAN_FILE_SUFFIX);
645 }

References find_suffix().

Referenced by get_new_user_file(), pips_split_file(), process_user_file(), and workspace_language().

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

◆ error_reset_module_name_list()

void error_reset_module_name_list ( void  )

No checking, to be called from a (future) error handling module.

Definition at line 74 of file csplit_file.c.

75 {
78 }
static list module_name_list
Kind of useless since a file is used to mimic fsplit.
Definition: csplit_file.c:56
void reset_module_name_list()
Definition: csplit_file.c:65
#define list_undefined_p(c)
Return if a list is undefined.
Definition: newgen_list.h:75

References list_undefined_p, module_name_list, and reset_module_name_list().

+ Here is the call graph for this function:

◆ f95split()

char* f95split ( char *  dir_name,
char *  file_name,
FILE **  out 
)

f95split_file.c

printf(stderr, "\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n" "+ Starting gfc parser in PIPS. -\n" "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n" );

string source_filename = strdup( concatenate( dir, "/", db_get_file_resource( DBR_SOURCE_FILE, module, true ), NULL ) );

dump_parse_tree is the gfc pass that have been hacked to call the gfc2pips stuff

we may have non-standard file extensions (e.g. .f_initial) and gfortran will not be able to know what it is so we force the language input

I don't know what the following stuff is ...

-fcray-pointer",

This debug_off() occurs too late since pipsdbm has been called before. Initially, the parser was designed to parse more than one subroutine/function/program at a time.

Parameters
dir_nameir_name
file_nameile_name
outut

Definition at line 56 of file f95split_file.c.

56  {
57 
58  FILE *fd;
59 
60 
61  debug_on( "SYNTAX_DEBUG_LEVEL" );
62 
63  /*fprintf(stderr,
64  "\n-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"
65  "+ Starting gfc parser in PIPS. -\n"
66  "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"
67  );*/
68 
69  // string callees_filename = get_resource_file_name( DBR_CALLEES, module );
70  // Create if it doesn't exist
71  // close( open( callees_filename, O_CREAT, S_IRWXU ) );
72 
73 
74  /*
75  *
76  */
77 
78  // Create xxx.database/Program if it doesn't exist Yet
79  string program_dirname = get_resource_file_name( "", "" );
80  mkdir( program_dirname, S_IRWXU );
81  free( program_dirname );
82 
83  /*
84  * Dump entities
85  */
86  string entities_filename = get_resource_file_name( DBR_ENTITIES, "" );
87  fd = (FILE *) safe_fopen( (char *) entities_filename, "w" );
89  safe_fclose( fd, (char *) entities_filename );
90 
91  /*
92  * directory where module are precompiled
93  */
94  char *compiled_dir_name = get_resource_file_name( "", "/Precompiled" );
95 
96  // Check if source file exist
97  /* string source_filename =
98  strdup( concatenate( dir, "/", db_get_file_resource( DBR_SOURCE_FILE,
99  module,
100  true ), NULL ) );
101  */
102  // "char **argv" for gfc2pips :-)
103  char* gfc2pips_args[] = { "gfc2pips", "-Wall",// "-Werror",
104  // We give it where to output...
105  "-pips-entities",
106  entities_filename,
107  "-o","/dev/null",
108  //parsedcode_filename,
109  file_name,
110  // ... and where to read inputs
111  "-auxbase",
112  //source_filename,
113  dir_name,
114  /* dump_parse_tree is the gfc pass that have been
115  * hacked to call the gfc2pips stuff
116  */
117  "-fdump-parse-tree",
118  "-quiet",
119  "-I",compiled_dir_name,
120  /* we may have non-standard file extensions
121  * (e.g. .f_initial) and gfortran will not be able
122  * to know what it is so we force the language input
123  */
124  // "-x",
125  // "f95",
126  "-cpp",
127  // "-quiet",// "-Werror",
128  /* I don't know what the following stuff is ... */
129  /*"-fcray-pointer",*/
130  "-ffree-form",
131  //"-fdefault-double-8",
132  //"-fdefault-integer-8",
133  //"-fdefault-real-8",
134 
135  // Argv must be null terminated
136  NULL };
137 
138  // we will fork now in order to call GFC
139  int statut;
140  pid_t child_pid = fork( );
141 
142  // Now we have two process runing the same code
143  // We differentiate them with fork() return value
144 
145  if ( child_pid == -1 ) {
146  // Error
147  perror( "Fork" );
148  return false;
149  } else if ( child_pid == 0 ) {
150  // in the child
151 
152 
153  pips_debug( 2, "build module %s\n", file_name );
154 
155  // MAIN CALL TO GFC
156  char** arg = gfc2pips_args;
157  ifdebug(1) {
158  fprintf( stderr, "execvp : " );
159  while ( *arg ) {
160  fprintf( stderr, " %s", *arg );
161  arg++;
162  }
163  fprintf( stderr, "\n" );
164  }
165  execvp( "gfc2pips", gfc2pips_args );
166  // No return from exec
167  pips_user_error("gfc2pips is not installed, did you compile PIPS with"
168  " Fortran95 support ?\n");
169  exit( -1 );
170  } else {
171  // in the Father
172 
173  // Wait that gfc has done the job
174  if ( waitpid( child_pid, &statut, 0 ) == -1 ) {
175  // Error in waitpid
176  perror( "waitpid" );
177  return "Erreur in wait pid";
178  } else {
179  // Child has correctly finished
180 
181  // Check the gfc2pips return code
182  if ( statut != EXIT_SUCCESS ) {
183  fprintf(stderr,"error code %d\n",statut);
184  return "gfc2pips return an error";
185  }
186  }
187  }
188 
189  // If we are, everything was done properly :-)
190 
191 
192  // Reload entities
193 
194  // We have to close it and re-open since gfc2pips has written into it.
195  fclose( *out );
196 
197  //out will be close in caller
198  *out = safe_fopen( entities_filename, "r" );
199 
200  gen_read_tabulated( *out, 0 );
201 // safe_fclose( fp, entities_filename );
202 
203 
204 
205  /* This debug_off() occurs too late since pipsdbm has been called
206  * before. Initially, the parser was designed to parse more than
207  * one subroutine/function/program at a time. */
208  debug_off( );
209 
210 
211 
212  return NULL;
213 
214 }
int gen_write_tabulated(FILE *fd, int domain)
GEN_WRITE_TABULATED writes the tabulated object TABLE on FD.
Definition: genClib.c:1866
int gen_read_tabulated(FILE *file, int create_p)
GEN_READ_TABULATED reads FILE to update the Gen_tabulated_ table.
Definition: genClib.c:2334
list gfc2pips_args(gfc_namespace *ns)
Retrieve the list of names of every argument of the function, if any.
Definition: gfc2pips.c:847
#define EXIT_SUCCESS
NetBSD 5.0 mis-defines NULL.
Definition: stdlib.in.h:103
string get_resource_file_name(const char *rname, const char *oname)
allocate a full file name for the given resource.
Definition: lowlevel.c:187
#define exit(code)
Definition: misc-local.h:54
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410

References debug_off, debug_on, entity_domain, exit, EXIT_SUCCESS, file_name, fprintf(), free(), gen_read_tabulated(), gen_write_tabulated(), get_resource_file_name(), gfc2pips_args(), ifdebug, out, pips_debug, pips_user_error, safe_fclose(), and safe_fopen().

Referenced by pips_split_file().

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

◆ filter_file()

bool filter_file ( string  mod_name)

directory is set for finding includes.

Parameters
mod_nameod_name

Definition at line 501 of file source_file.c.

502 {
503  string name, new_name, dir_name, abs_name, abs_new_name;
504  name = db_get_memory_resource(DBR_INITIAL_FILE, mod_name, true);
505 
506  /* directory is set for finding includes. */
508  pips_dirname(db_get_memory_resource(DBR_USER_FILE, mod_name, true));
509  new_name = db_build_file_resource_name
510  (DBR_SOURCE_FILE, mod_name, FORTRAN_FILE_SUFFIX);
511 
513  abs_name = strdup(concatenate(dir_name, "/", name, NULL));
514  abs_new_name = strdup(concatenate(dir_name, "/", new_name, NULL));
515  free(dir_name);
516 
517  if (!pips_process_file(abs_name, abs_new_name))
518  {
519  pips_user_warning("initial file filtering of %s failed\n", mod_name);
520  safe_unlink(abs_new_name);
521  free(abs_new_name); free(abs_name);
522  return false;
523  }
524  free(abs_new_name); free(abs_name);
526 
527  DB_PUT_NEW_FILE_RESOURCE(DBR_SOURCE_FILE, mod_name, new_name);
528  return true;
529 }
some path to file suffix some path to *char * pips_dirname(char *fullpath)
Definition: file.c:837
void safe_unlink(const char *file_name)
Delete the given file.
Definition: file.c:852
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_NEW_FILE_RESOURCE(res_name, own_name, res_val)
Put a new file resource into the current workspace database.
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 pips_user_warning
Definition: misc-local.h:146
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
static bool pips_process_file(string file_name, string new_name)
Definition: source_file.c:487
static string user_file_directory
Definition: source_file.c:194

References concatenate(), db_build_file_resource_name(), db_get_current_workspace_directory(), db_get_memory_resource(), DB_PUT_NEW_FILE_RESOURCE, free(), pips_dirname(), pips_process_file(), pips_user_warning, safe_unlink(), strdup(), and user_file_directory.

+ Here is the call graph for this function:

◆ find_eol_coding()

int find_eol_coding ( string  name)

Returns the newly allocated name if preprocessing succeeds.

Returns NULL if preprocessing fails.

Parameters
nameame

Definition at line 721 of file source_file.c.

722 {
723  FILE * f = safe_fopen(name, "r");
724  int state =0;
725  int eol_code = -1;
726  int c;
727 
728  while((c=getc(f))!=EOF) {
729  if(c=='\n') {
730  if(state==1)
731  eol_code = 1; // DOS
732  else
733  eol_code = 0; // UNIX
734  break;
735  }
736  else if(c=='\r')
737  state = 1;
738  else {
739  if(state==1) {
740  eol_code = 2; // ISO22
741  break;
742  }
743  }
744  }
745 
746  safe_fclose(f, name);
747 
748  return eol_code;
749 }
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15

References f(), safe_fclose(), and safe_fopen().

Referenced by process_thru_C_pp().

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

◆ flag_as_stub()

bool flag_as_stub ( const  string)
Parameters
stringodule_name

Definition at line 1334 of file source_file.c.

1334  {
1335  if (!db_resource_p(DBR_STUBS, ""))
1336  pips_internal_error("stubs not initialized");
1337  callees stubs=(callees)db_get_memory_resource(DBR_STUBS,"",true);
1339  DB_PUT_MEMORY_RESOURCE(DBR_STUBS,"",stubs);
1340  return true;
1341 
1342 }
#define STRING(x)
Definition: genC.h:87
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
struct _newgen_struct_callees_ * callees
Definition: ri.h:55
#define callees_callees(x)
Definition: ri.h:675

References callees_callees, CONS, db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, db_resource_p(), module_name(), pips_internal_error, strdup(), and STRING.

Referenced by generic_initializer().

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

◆ force_reset_preprocessor_scope_stack()

void force_reset_preprocessor_scope_stack ( void  )

To be used by an error handler.

Definition at line 297 of file splitc.c.

298  {
302  }
304  return;
305  }
#define stack_undefined
Definition: newgen_stack.h:55
void stack_free(stack *)
type, bucket_size, policy
Definition: stack.c:292
static int c_preprocessor_scope_number
Definition: splitc.c:271
static stack c_preprocessor_scope_stack
Definition: splitc.c:272
#define SCOPE_UNDEFINED
Each scope in the compilation unit has its own number.
Definition: splitc.c:270

References c_preprocessor_scope_number, c_preprocessor_scope_stack, SCOPE_UNDEFINED, stack_free(), and stack_undefined.

+ Here is the call graph for this function:

◆ ForceResetTypedefStack()

void ForceResetTypedefStack ( void  )

Definition at line 259 of file splitc.c.

260 {
263 }
static stack TypedefStack
to know if this is a typedef name or not
Definition: splitc.c:227

References stack_free(), stack_undefined, and TypedefStack.

Referenced by csplit_close_files().

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

◆ fsplit()

char* fsplit ( char *  dir_name,
char *  file_name,
FILE *  out 
)

output file

1 if got card in output file, 0 otherwise

1 if got name of subprog., 0 otherwise

??? 20 -> 80 because not checked... smaller than a line is ok ? FC

MALLOC STRINGS

look for a temp file that doesn't correspond to an existing file

FC

if no name yet, try and find one

FC: some hack to deal with entry...

FC again

now we gave it a name!

a new module name is appended to the current line...

look for an 'end' statement

while

no lines in file, forget the file

rename the file

out?

for(;;)

Parameters
dir_nameir_name
file_nameile_name
outut

Definition at line 474 of file split_file.c.

475 {
476  FILE *ofp; /* output file */
477  int rv; /* 1 if got card in output file, 0 otherwise */
478  int nflag, /* 1 if got name of subprog., 0 otherwise */
479  someentry, newname;
480  /* ??? 20 -> 80 because not checked... smaller than a line is ok ? FC */
481  char name[80];
482  char tmpname[80];
483 
484  /* MALLOC STRINGS
485  */
486  char * main_list = full_name(dir_name, MAIN_FILE_NAMES);
487  x = full_name(dir_name, "###000.f");
488  mainp = full_name(dir_name, "main000.f");
489  blkp = full_name(dir_name, "data000.f");
490 
492 
493  if ((ifp = fopen(file_name, "r")) == NULL) {
494  fprintf(stderr, "fsplit: cannot open %s\n", file_name);
495  FREE_STRINGS;
496  return "cannot open file";
497  }
498 
499  for(;;) {
500 
501  /* look for a temp file that doesn't correspond to an existing file */
502  get_name(x);
503  ofp = fopen(x, "w");
504  if (ofp==NULL) {
505  fprintf(stderr, "%s %s -> %s\n", dir_name, file_name, x);
506  fprintf(stderr, "fopen(\"%s\", ...) failed\n", x);
507  abort();
508  }
509 
510  nflag = 0;
511  rv = 0;
512  newname = 0;
513  someentry = 0;
514 
515  while (GetLine() > 0)
516  {
517  char * error = hollerith_and_bangcomments(buf); /* FC */
518  if (error) {
519  fclose(ofp);
520  fclose(ifp);
521  FREE_STRINGS;
522  return error;
523  }
524 
525  if (nflag == 0) /* if no name yet, try and find one */
526  nflag = lname(name, 0), newname=nflag;
527  else { /* FC: some hack to deal with entry... */
528  lname(tmpname, 1);
529  newname = it_is_an_entry;
530  someentry = it_is_an_entry;
531  implicit_program = 0;
532  it_is_a_main = 0;
533  it_is_an_entry = 0;
534  }
535 
536  if (it_is_a_main) {
537  FILE * fm = fopen(main_list, "a");
538  if (fm==NULL) {
539  fprintf(stderr, "fopen(\"%s\", ...) failed\n", main_list);
540  // FI: not user friendly...
541  abort();
542  }
544  print_name(fm, name, 7, 1);
545  else
547  putc('\n', fm);
548  fclose(fm);
549  it_is_a_main = 0;
550  }
551 
552  if (implicit_program==1) /* FC again */
553  {
554  fprintf(ofp,
555  "! next line added by fsplit() in pips\n"
556  " PROGRAM ");
557  print_name(ofp, name, 7, 0);
558  putc('\n', ofp);
559  implicit_program = 0; /* now we gave it a name! */
560  }
561 
563  {
564  fprintf(ofp,
565  "! next line modified by fsplit() in pips\n"
566  " %s ",
567  implicit_program_name==1? "PROGRAM": "BLOCK DATA");
568  print_name(ofp, name, 7, 0);
569  putc('\n', ofp);
572  }
573  else
574  fprintf(ofp, "%s", buf);
575 
576  /* a new module name is appended to the current line... */
577  if (newname)
578  {
579  if ((someentry && tmpname[0]) || (!someentry && name[0]))
580  {
582  (someentry? tmpname: name, out);
583  putc(' ', out);
584  }
585  newname = 0;
586  someentry = 0;
587  tmpname[0] = '\0';
588  }
589 
590  rv = 1;
591 
592  if (lend()) /* look for an 'end' statement */
593  break;
594  } /* while */
595 
596  if (fclose(ofp)) {
597  fprintf(stderr, "fclose(ofp) failed\n");
598  exit(2);
599  }
600  if (rv == 0) { /* no lines in file, forget the file */
601  safe_unlink(x);
602  if (fclose(ifp)) {
603  fprintf(stderr, "fclose(ifp) failed\n");
604  exit(2);
605  }
606  FREE_STRINGS; return NULL;
607  }
608  if (nflag) /* rename the file */
609  {
610  if (strncmp(dir_name, name, strlen(dir_name))!=0)
611  {
612  char * full = full_name(dir_name, name);
613  strcpy(name, full);
614  free(full);
615  }
616  if (strcmp(name, x) == 0) {
617  printf(/* out? */ "%s\n", x);
618  }
619  else if (stat(name, &sbuf) < 0 )
620  {
621  int ok = link(x, name);
622  // FC: link() may fail but it is ok?
623  if (ok != 0 && ok != -1) abort();
624  safe_unlink(x);
625  fprintf(out, "%s\n", name);
626  }
627  else
628  printf("%s already exists, put in %s\n", name, x);
629  continue;
630  }
631  fprintf(out, "%s\n", x);
632  } /* for(;;) */
633 
634  if (fclose(ifp)) {
635  fprintf(stderr, "fclose(ifp) failed\n");
636  exit(2);
637  }
638  FREE_STRINGS;
639  return "bad fsplit() terminaison.";
640 }
#define error(fun, msg)
NewGen interface with C3 type Psysteme for PIPS project.
Definition: Psc.c:78
int printf()
static bool ok
static void put_upper_from_slash_till_dot_or_end(char *what, FILE *where)
Definition: split_file.c:452
static int lend()
return 1 for 'end' alone on card (up to col.
Definition: split_file.c:242
static char * hollerith_and_bangcomments(char *)
Definition: split_file.c:673
static int lname(char *s, int look_for_entry)
check for keywords for subprograms return 0 if comment card, 1 if found name and put in arg string.
Definition: split_file.c:283
static int it_is_an_entry
FC.
Definition: split_file.c:277
static char * mainp
Definition: split_file.c:159
static int current_line_number
Definition: split_file.c:200
static FILE * ifp
Definition: split_file.c:158
static void print_name(FILE *o, char *name, int n, int upper)
FC.
Definition: split_file.c:462
static char * x
Definition: split_file.c:159
static int implicit_program_name
FC.
Definition: split_file.c:275
static char buf[BSZ]
Definition: split_file.c:157
static void get_name()
static int implicit_blockdata_name
FC.
Definition: split_file.c:274
static char * blkp
Definition: split_file.c:159
static int it_is_a_main
FC.
Definition: split_file.c:276
static char * full_name(char *dir, char *name)
Definition: split_file.c:171
static struct stat sbuf
Definition: split_file.c:163
static int implicit_program
Definition: split_file.c:273
static int GetLine()
getline does not handle continuations...
Definition: split_file.c:204
#define FREE_STRINGS
Definition: split_file.c:468
@ full
Definition: union-local.h:65

Referenced by pips_split_file().

+ Here is the caller graph for this function:

◆ get_csplit_current_beginning()

int get_csplit_current_beginning ( void  )

Definition at line 1190 of file lexer.c.

1191 {
1192  return csplit_current_beginning;
1193 }
static int csplit_current_beginning
Definition: lexer.c:1134

References csplit_current_beginning.

◆ get_csplit_file_offset_beginning()

size_t get_csplit_file_offset_beginning ( void  )

Get the file position in the file to split where the current function begins:

Definition at line 1205 of file lexer.c.

1205  {
1207 }
size_t csplit_file_offset_beginning
Definition: lexer.c:1093

References csplit_file_offset_beginning.

◆ get_current_csplit_file_offset()

size_t get_current_csplit_file_offset ( void  )

Get the current file position in the file to split:

Definition at line 1211 of file lexer.c.

1211  {
1213 }
size_t current_csplit_file_offset
Definition: lexer.c:1092

References current_csplit_file_offset.

◆ get_preprocessor_current_scope()

string get_preprocessor_current_scope ( void  )

Definition at line 327 of file splitc.c.

328  {
329  string sn = string_undefined;
331  // We are at the global level: no scope has been entered yet
332  sn = "";
333  }
334  else
336  return sn;
337  }
void * stack_head(const stack)
returns the item on top of stack s
Definition: stack.c:420
char * string
STRING.
Definition: newgen_types.h:39
bool preprocessor_scope_stack_empty_p()
Definition: splitc.c:322

References c_preprocessor_scope_stack, preprocessor_scope_stack_empty_p(), stack_head(), and string_undefined.

Referenced by is_c_preprocessor_keyword_typedef(), and keep_track_of_typedef().

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

◆ get_preprocessor_nth_scope()

string get_preprocessor_nth_scope ( int  n)

Definition at line 339 of file splitc.c.

340  {
341  string sn = (string) stack_nth(c_preprocessor_scope_stack, n);
342  return sn;
343  }
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_preprocessor_scope_stack, and stack_nth().

Referenced by is_c_preprocessor_keyword_typedef().

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

◆ get_splitc_input_file_name()

string get_splitc_input_file_name ( void  )

Definition at line 84 of file csplit_file.c.

85 {
87 }

References splitc_input_file_name.

◆ get_user_current_beginning()

int get_user_current_beginning ( void  )

Get the current line number in the file to split from the user point of view (before preprocessor expansion):

Definition at line 1198 of file lexer.c.

1198  {
1199  return user_current_beginning;
1200 }
static int user_current_beginning
Definition: lexer.c:1135

References user_current_beginning.

◆ hpfc_generate_path_name_of_file_name()

string hpfc_generate_path_name_of_file_name ( const char *  file_name)

Return the path of an HPFC file name relative to the current PIPS directory.

Can be freed by the caller.

Parameters
file_nameile_name

Definition at line 97 of file source_file.c.

98 {
99  string dir_name = db_get_current_workspace_directory(),
100  name = strdup(concatenate(
101  dir_name, "/", HPFC_COMPILED_FILE_DIR, "/", file_name, NULL));
102  free(dir_name);
103  return name;
104 }

References concatenate(), db_get_current_workspace_directory(), file_name, free(), and strdup().

Referenced by notify_hpfc_file_view().

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

◆ hpfc_get_file_list()

int hpfc_get_file_list ( gen_array_t  file_names,
char **  hpfc_directory_name 
)

Where is the output of HPFC:

generated files start with upercases

Plain files only:

Parameters
file_namesile_names
hpfc_directory_namepfc_directory_name

Definition at line 106 of file source_file.c.

108 {
109  // some static but dynamic buffer.
110  static int hpfc_bsz = 0;
111  static char * hpfc_dir = NULL;
112 
113  int return_code, len;
115 
116  len = strlen(dir) + strlen(HPFC_COMPILED_FILE_DIR) + 5;
117 
118  if (hpfc_bsz<len) {
119  if (hpfc_dir) free(hpfc_dir), hpfc_dir=NULL;
120  hpfc_bsz = len;
121  hpfc_dir = (char*) malloc(hpfc_bsz);
122  message_assert("malloc succeeded", hpfc_dir);
123  }
124 
125  // Get the HPFC file name list:
126  sprintf(hpfc_dir, "%s/%s", dir, HPFC_COMPILED_FILE_DIR);
127 
128  return_code = safe_list_files_in_directory(
129  file_names,
130  hpfc_dir, /* Where is the output of HPFC: */
131  "^[A-Z].*\\.[fh]$", /* generated files start with upercases */
132  file_exists_p /* Plain files only: */);
133  *hpfc_directory_name = hpfc_dir;
134 
135  return return_code;
136 }
bool file_exists_p(const char *name)
Definition: file.c:321
int safe_list_files_in_directory(gen_array_t files, string dir, string re, bool(*file_name_predicate)(const char *))
returns a sorted arg list of files matching regular expression re in directory 'dir' and with file_na...
Definition: file.c:250
void * malloc(YYSIZE_T)
#define message_assert(msg, ex)
Definition: newgen_assert.h:47
#define build_pgmwd
string db_get_current_workspace_name(void)
the function is used to check that there is some current workspace...
Definition: workspace.c:82

References build_pgmwd, db_get_current_workspace_name(), file_exists_p(), free(), malloc(), message_assert, and safe_list_files_in_directory().

Referenced by generate_a_menu_with_HPF_output_files().

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

◆ init_module_name_list()

void init_module_name_list ( void  )

Definition at line 58 of file csplit_file.c.

59 {
60  pips_assert("module_name_list is undefined",
63 }

References list_undefined_p, module_name_list, NIL, and pips_assert.

◆ init_preprocessor_scope_stack()

void init_preprocessor_scope_stack ( void  )

Definition at line 274 of file splitc.c.

275  {
278  }
@ string_domain
Definition: genC.h:170
stack stack_make(int, int, int)
allocation
Definition: stack.c:246

References c_preprocessor_scope_number, c_preprocessor_scope_stack, stack_make(), and string_domain.

Referenced by csplit().

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

◆ init_processed_include_cache()

void init_processed_include_cache ( void  )

Definition at line 272 of file source_file.c.

273 {
274  // Since these functions are called in different context, the
275  // conventional pips_debug() is not well suitable, so revert to plain
276  // old fprintf for debug...
277  //fprintf(stderr, "[init_processed_include_cache] Entering\n");
280 }
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
@ hash_string
Definition: newgen_hash.h:32

References hash_string, hash_table_make(), hash_table_undefined_p, pips_assert, and processed_cache.

Referenced by create_workspace(), and open_workspace().

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

◆ keep_track_of_typedef()

void keep_track_of_typedef ( string  type_name)
Parameters
type_nameype_name

Definition at line 517 of file csplit_file.c.

518 {
519  string sn = get_preprocessor_current_scope();
520  string scoped_type_name = same_string_p(sn,"")? strdup(type_name)
521  : strdup(concatenate(type_name, "%", sn, NULL));
522  hash_put(keyword_typedef_table, scoped_type_name, (void *) TK_NAMED_TYPE);
523  pips_debug(2,"Add typedef name \"%s\" to hash table\n", scoped_type_name);
524  if(strcmp(type_name, "v1")==0) {
525  pips_debug(1, "v1 added as typedef\n");
526  }
527  // FI: should we free "name"?
528 }
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
string get_preprocessor_current_scope(void)
Definition: splitc.c:327
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
#define TK_NAMED_TYPE
Definition: splitc.c:760

References concatenate(), get_preprocessor_current_scope(), hash_put(), keyword_typedef_table, pips_debug, same_string_p, strdup(), and TK_NAMED_TYPE.

+ Here is the call graph for this function:

◆ MakeTypedefStack()

void MakeTypedefStack ( )

Define some functions from the .l or .y since cproto cannot dig them out:

Definition at line 243 of file splitc.c.

244  {
245  pips_assert("TypedefStack is undefined", stack_undefined_p(TypedefStack));
247 }
@ int_domain
Definition: genC.h:166
#define stack_undefined_p(s)
Definition: newgen_stack.h:56

◆ pips_change_directory()

string pips_change_directory ( const char *  dir)

Change to the given directory if it exists and return a canonical name.

Return NULL if it does not exist, or fails

Parameters
dirir

Definition at line 142 of file source_file.c.

143 {
144  if (directory_exists_p(dir))
145  {
146  int status = chdir(dir);
147  if (status==-1)
148  {
149  perror("chdir");
150  return NULL;
151  }
152  // should check status...
153  return get_cwd();
154  }
155  return NULL;
156 }
char * get_cwd(void)
returns the current working directory name.
Definition: file.c:486
bool directory_exists_p(const char *name)
Definition: file.c:314

References directory_exists_p(), and get_cwd().

Referenced by end_directory_notify().

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

◆ pips_get_fortran_list()

void pips_get_fortran_list ( gen_array_t  array)

Select the true file with names ending in ".[fF]" and return a sorted arg list:

Parameters
arrayrray

Definition at line 89 of file source_file.c.

90 {
91  list_files_in_directory(array, ".", "^.*\\.[fF]$", file_exists_p);
92 }
void list_files_in_directory(gen_array_t files, string dir, string re, bool(*file_name_predicate)(const char *))
The same as the previous safe_list_files_in_directory() but with no return code and a call to user er...
Definition: file.c:299
static entity array

References array, file_exists_p(), and list_files_in_directory().

Referenced by continue_create_workspace_notify().

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

◆ pips_get_workspace_list()

void pips_get_workspace_list ( gen_array_t  array)

cproto-generated files

source_file.c

cproto-generated files

(For each name, there is a name.database directory in the current directory):

Parameters
arrayrray

Definition at line 74 of file source_file.c.

75 {
76  int i, n;
77  // Find all directories with name ending with ".database":
78  list_files_in_directory(array, ".", "^.*\\.database$", directory_exists_p);
80  // Remove the ".database":
81  for (i = 0; i < n; i++) {
82  *strchr(gen_array_item(array, i), '.') = '\0';
83  }
84 }
size_t gen_array_nitems(const gen_array_t a)
Definition: array.c:131
void * gen_array_item(const gen_array_t a, size_t i)
Definition: array.c:143

References array, directory_exists_p(), gen_array_item(), gen_array_nitems(), and list_files_in_directory().

Referenced by generate_workspace_menu(), open_or_create_workspace(), open_workspace_notify(), and start_delete_workspace_notify().

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

◆ pips_srcpath_append()

string pips_srcpath_append ( string  pathtoadd)

returns an allocated pointer to the old value

Strdup the string since it is returned and use later in many other places

Parameters
pathtoaddathtoadd

Definition at line 177 of file source_file.c.

178 {
179  string old_path, new_path;
180  old_path = getenv(SRCPATH);
181  if (old_path)
182  /* Strdup the string since it is returned and use later in many other
183  places */
184  old_path = strdup(old_path);
185  new_path = concatenate(old_path? old_path: "", old_path? ":": "",
186  pathtoadd, NULL);
187  pips_srcpath_set(new_path);
188  return old_path;
189 }
#define SRCPATH
Preprocessing and splitting of Fortran and C files.
void pips_srcpath_set(string path)
Set the PIPS source path.
Definition: source_file.c:167

References concatenate(), pips_srcpath_set(), SRCPATH, and strdup().

Referenced by parse_arguments(), and step_analyse_init().

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

◆ pips_srcpath_set()

void pips_srcpath_set ( string  path)

Set the PIPS source path.

Parameters
pathis used to set the search path or to unset if path is NULL

Strangely this environment variable is set many times in PIPS to pass some information...

Parameters
pathath

Definition at line 167 of file source_file.c.

168 {
169  if (path)
170  setenv(SRCPATH, path, true);
171  else
172  unsetenv(SRCPATH);
173 }

References SRCPATH.

Referenced by parse_arguments(), pips_srcpath_append(), pop_path(), and safe_pop_path().

+ Here is the caller graph for this function:

◆ pop_preprocessor_scope()

void pop_preprocessor_scope ( void  )

Definition at line 316 of file splitc.c.

317  {
319  return;
320  }
void * stack_pop(stack)
POPs one item from stack s.
Definition: stack.c:399

References c_preprocessor_scope_stack, and stack_pop().

+ Here is the call graph for this function:

◆ preprocessed_to_user_file()

string preprocessed_to_user_file ( string  preprocessed_user_file)

Allocate a new string containing the user file name, before preprocessing.

No preprocessing has occured

Parameters
preprocessed_user_filereprocessed_user_file

Definition at line 617 of file source_file.c.

618 {
619  string user_file = strdup(preprocessed_user_file);
620  string suffix = string_undefined;
621 
622  if ((suffix = find_suffix(user_file, PP_FORTRAN_ED)) != NULL) {
623  strcpy(suffix, FORTRAN_FILE_SUFFIX);
624  }
625  else if((suffix = find_suffix(user_file, PP_C_ED)) != NULL) {
626  strcpy(suffix, C_FILE_SUFFIX);
627  }
628  else {
629  /* No preprocessing has occured */
630  ;
631  }
632  return user_file;
633 }
static FILE * user_file
These functions implements the writing of objects.
Definition: genClib.c:1485

References find_suffix(), strdup(), string_undefined, and user_file.

Referenced by get_new_user_file().

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

◆ preprocessor_init_keyword_typedef_table()

void preprocessor_init_keyword_typedef_table ( void  )

FI: keyword_typedef_table is also a global variable. I am trying to move towards some kind of functional wrapping around the global variable, which I would like to declare static in ri-util/static.c.

GNU predefined type(s), expecting no conflict with user named type

AM: en attendant mieux...

typedef names are added later when encoutered.

Definition at line 567 of file csplit_file.c.

568 {
569  /* FI: keyword_typedef_table is also a global variable. I am trying
570  * to move towards some kind of functional wrapping around the
571  * global variable, which I would like to declare static in
572  * ri-util/static.c.
573  */
575  hash_put(keyword_typedef_table,"auto", (char *) TK_AUTO);
576  hash_put(keyword_typedef_table,"break", (char *) TK_BREAK);
577  hash_put(keyword_typedef_table,"case", (char *) TK_CASE);
578  hash_put(keyword_typedef_table,"char", (char *) TK_CHAR);
579  hash_put(keyword_typedef_table,"const", (char *) TK_CONST);
580  hash_put(keyword_typedef_table,"__const", (char *) TK_CONST);
581  hash_put(keyword_typedef_table,"continue", (char *) TK_CONTINUE);
582  hash_put(keyword_typedef_table,"default", (char *) TK_DEFAULT);
583  hash_put(keyword_typedef_table,"do", (char *) TK_DO);
584  hash_put(keyword_typedef_table,"double", (char *) TK_DOUBLE);
585  hash_put(keyword_typedef_table,"else", (char *) TK_ELSE);
586  hash_put(keyword_typedef_table,"enum", (char *) TK_ENUM);
587  hash_put(keyword_typedef_table,"extern", (char *) TK_EXTERN);
588  hash_put(keyword_typedef_table,"float", (char *) TK_FLOAT);
589  hash_put(keyword_typedef_table,"for", (char *) TK_FOR);
590  hash_put(keyword_typedef_table,"goto", (char *) TK_GOTO);
591  hash_put(keyword_typedef_table,"if", (char *) TK_IF);
592  hash_put(keyword_typedef_table,"inline", (char *) TK_INLINE);
593  hash_put(keyword_typedef_table,"int", (char *) TK_INT);
594  hash_put(keyword_typedef_table,"__int128_t", (char *) TK_INT128);
595  hash_put(keyword_typedef_table,"__uint128_t", (char *) TK_UINT128);
596  hash_put(keyword_typedef_table,"_Complex", (char *) TK_COMPLEX);
597  hash_put(keyword_typedef_table,"long", (char *) TK_LONG);
598  hash_put(keyword_typedef_table,"register", (char *) TK_REGISTER);
599  hash_put(keyword_typedef_table,"restrict", (char *) TK_RESTRICT);
600  hash_put(keyword_typedef_table,"__restrict", (char *) TK_RESTRICT);
601  hash_put(keyword_typedef_table,"__restrict__", (char *) TK_RESTRICT);
602  hash_put(keyword_typedef_table,"return", (char *) TK_RETURN);
603  hash_put(keyword_typedef_table,"short", (char *) TK_SHORT);
604  hash_put(keyword_typedef_table,"signed", (char *) TK_SIGNED);
605  hash_put(keyword_typedef_table,"sizeof", (char *) TK_SIZEOF);
606  hash_put(keyword_typedef_table,"static", (char *) TK_STATIC);
607  hash_put(keyword_typedef_table,"struct", (char *) TK_STRUCT);
608  hash_put(keyword_typedef_table,"switch", (char *) TK_SWITCH);
609  hash_put(keyword_typedef_table,"__thread", (char *) TK_THREAD);
610  hash_put(keyword_typedef_table,"typedef", (char *) TK_TYPEDEF);
611  hash_put(keyword_typedef_table,"union", (char *) TK_UNION);
612  hash_put(keyword_typedef_table,"unsigned", (char *) TK_UNSIGNED);
613  hash_put(keyword_typedef_table,"void", (char *) TK_VOID);
614  hash_put(keyword_typedef_table,"volatile", (char *) TK_VOLATILE);
615  hash_put(keyword_typedef_table,"while", (char *) TK_WHILE);
616  hash_put(keyword_typedef_table,"__builtin_va_arg", (char *) TK_BUILTIN_VA_ARG);
617  hash_put(keyword_typedef_table,"asm", (char *) TK_ASM);
618  hash_put(keyword_typedef_table,"__asm__", (char *) TK_ASM);
619  hash_put(keyword_typedef_table,"__volatile__", (char *) TK_VOLATILE);
620 
621  /* GNU predefined type(s), expecting no conflict with user named type */
622 
623  hash_put(keyword_typedef_table,"__builtin_va_list", (char *) TK_NAMED_TYPE);
624  hash_put(keyword_typedef_table,"_Bool", (char *) TK_NAMED_TYPE);
625 
626  /* AM: en attendant mieux... */
627  hash_put(keyword_typedef_table,"STEP_ARG", (char *) TK_NAMED_TYPE);
628 
629  /* typedef names are added later when encoutered. */
630 }
hash_table make_keyword_typedef_table(int)
Definition: static.c:256
#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_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

References hash_put(), keyword_typedef_table, make_keyword_typedef_table(), TK_ASM, TK_AUTO, TK_BREAK, TK_BUILTIN_VA_ARG, TK_CASE, TK_CHAR, TK_COMPLEX, TK_CONST, TK_CONTINUE, TK_DEFAULT, TK_DO, TK_DOUBLE, TK_ELSE, TK_ENUM, TK_EXTERN, TK_FLOAT, TK_FOR, TK_GOTO, TK_IF, TK_INLINE, TK_INT, TK_INT128, TK_LONG, TK_NAMED_TYPE, TK_REGISTER, TK_RESTRICT, TK_RETURN, TK_SHORT, TK_SIGNED, TK_SIZEOF, TK_STATIC, TK_STRUCT, TK_SWITCH, TK_THREAD, TK_TYPEDEF, TK_UINT128, TK_UNION, TK_UNSIGNED, TK_VOID, TK_VOLATILE, and TK_WHILE.

Referenced by csplit().

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

◆ preprocessor_scope_number()

int preprocessor_scope_number ( void  )

Definition at line 345 of file splitc.c.

346  {
348  return n;
349  }
int stack_size(const stack)
observers

References c_preprocessor_scope_stack, and stack_size().

Referenced by is_c_preprocessor_keyword_typedef().

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

◆ preprocessor_scope_stack_empty_p()

bool preprocessor_scope_stack_empty_p ( void  )

Definition at line 322 of file splitc.c.

323 {
325 }
bool stack_empty_p(const stack)

References c_preprocessor_scope_stack, and stack_empty_p().

Referenced by get_preprocessor_current_scope().

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

◆ process_bang_comments_and_hollerith()

char* process_bang_comments_and_hollerith ( FILE *  in,
FILE *  out 
)

processing extracted for includes...

Parameters
inn
outut

Definition at line 836 of file split_file.c.

837 {
838  char * error;
839  ifp = in;
841  while (GetLine()>0)
842  {
844  if (error) return error;
845  fputs(buf, out);
846  }
847  ifp = NULL;
848  return NULL;
849 }

References buf, current_line_number, error, GetLine(), hollerith_and_bangcomments(), ifp, and out.

Referenced by handle_include_file().

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

◆ process_user_file()

bool process_user_file ( string  file)

The file is looked for in the pips source path.

Do not check the syntax in the input file: quite dangerous in case it is wrong because PIPS is not designed to work on damaged source codes. But this may be useful is the input file is a validation file or if the input file has already been checked.

If two modules have the same name, the first splitted wins and the other one is hidden by the call since fsplit gives it a zzz00n.f name Let's hope no user module is called ###???.f

The newly created module files are registered in the database The file_list allows split to communicate with this function.

a_line: "MODULE1 ... MODULEn file_name"

The list modules comes from entries that might be included in the subroutine.

For each Fortran module in the line, put the initial_file and user_file resource. In C, line should have only one entry and a C source file and a user file resources are created.

hey, that's cleaning!

Seems to be recorded as a resource, causes problems later when closing the workspace...

unlink(nfile);

Parameters
fileile

Definition at line 1090 of file source_file.c.

1091 {
1092  bool success_p = false, cpp_processed_p;
1093  string dir_name = db_get_current_workspace_directory();
1094 
1095  // FC: hmmm this function is not very strict,
1096  // and sometime we need clean user errors...
1097  bool generate_user_error =
1098  get_bool_property("ABORT_ON_USER_ERROR") ||
1099  get_bool_property("CLOSE_WORKSPACE_AND_QUIT_ON_ERROR");
1100 
1101  static int number_of_files = 0;
1102  static int number_of_modules = 0;
1103  static int resource_name_conflicts = 0;
1104 
1105  number_of_files++;
1106  pips_debug(1, "file %s (number %d)\n", file, number_of_files);
1107 
1108  /* The file is looked for in the pips source path.
1109  */
1110  string nfile = find_file_in_directories(file, getenv(SRCPATH));
1111 
1112  if (!nfile)
1113  {
1114  pips_user_error("Cannot open file: \"%s\"", file);
1115  return false;
1116  }
1117 
1118  string initial_file = nfile;
1120 
1121  // The new file is registered (well, not really...) in the database.
1122  user_log("Registering file %s\n", file);
1123 
1124  bool syntax_ok_p = true;
1125  if ((dot_F_file_p(nfile) || dot_f_file_p(nfile)) && pips_check_fortran())
1126  {
1127  // Note: a Fortran compiler is required on the machine.
1128  syntax_ok_p = check_fortran_syntax_before_pips(nfile);
1129  }
1130  else if (dot_c_file_p(nfile) && pips_check_c()) {
1131  // Note: a C compiler is required on the machine. Run it.
1132  syntax_ok_p = check_c_file_syntax(nfile);
1133  }
1134  else
1135  {
1136  /* Do not check the syntax in the input file: quite dangerous in
1137  case it is wrong because PIPS is not designed to work on
1138  damaged source codes. But this may be useful is the input file
1139  is a validation file or if the input file has already been
1140  checked. */
1141  pips_debug(1, "No syntactic check on file \"%s\"\n", nfile);
1142  }
1143 
1144  if (!syntax_ok_p)
1145  {
1146  if (generate_user_error)
1147  pips_user_error("Syntax check failed on \"%s\"", nfile);
1148  // It is up to the caller to decide if the syntax must be checked
1149  // for other files as well
1150  return false;
1151  }
1152 
1153  // CPP if file extension is .F or .c
1154  // (assumes string_equal_p(nfile, initial_file))
1155  cpp_processed_p = dot_F_file_p(nfile) || dot_c_file_p(nfile);
1156 
1157  if (cpp_processed_p)
1158  {
1159  user_log("Preprocessing file %s\n", initial_file);
1160  nfile = process_thru_cpp(initial_file);
1161  if (nfile==NULL)
1162  {
1163  if (generate_user_error)
1164  pips_user_error("Cannot preprocess file \"%s\"", initial_file);
1165  else
1166  pips_user_warning("Cannot preprocess file: %s\n", initial_file);
1167  return false;
1168  }
1169  }
1170  else if ( !dot_f_file_p( nfile ) && !dot_f90_file_p( nfile )
1171  && !dot_f95_file_p( nfile ) ) {
1172  pips_user_error("Unexpected file extension\n");
1173  }
1174 
1175  /* If two modules have the same name, the first splitted wins
1176  * and the other one is hidden by the call since fsplit gives
1177  * it a zzz00n.f name
1178  * Let's hope no user module is called ###???.f
1179  */
1180  string file_list =
1181  strdup(concatenate(dir_name,
1182  dot_c_file_p(nfile)?
1183  "/.csplit_file_list" : "/.fsplit_file_list", NULL));
1184  unlink(file_list);
1185 
1186  user_log("Splitting file %s\n", nfile);
1187  if (pips_split_file(nfile, file_list))
1188  {
1189  if (generate_user_error)
1190  pips_user_error("error while splitting file \"%s\"", nfile);
1191  return false;
1192  }
1193 
1194  /* The newly created module files are registered in the database
1195  * The file_list allows split to communicate with this function.
1196  */
1197  FILE * fd = safe_fopen(file_list, "r");
1198  string a_line;
1199  while ((a_line = safe_readline(fd)) && resource_name_conflicts == 0)
1200  {
1201  string mod_name = NULL, res_name = NULL;
1202  list modules = NIL;
1203  bool renamed=false;
1204 
1205  /* a_line: "MODULE1 ... MODULEn file_name"
1206  *
1207  * The list modules comes from entries that might be included
1208  * in the subroutine.
1209  */
1210  string file_name = extract_last_name(a_line);
1211  success_p = true;
1212  number_of_modules++;
1213  pips_debug(2, "module %s (number %d)\n", file_name, number_of_modules);
1214 
1215  while (mod_name!=a_line && (mod_name = extract_last_name(a_line)))
1216  modules = CONS(STRING, mod_name, modules);
1217 
1218  /* For each Fortran module in the line, put the initial_file and
1219  user_file resource. In C, line should have only one entry and a C
1220  source file and a user file resources are created. */
1221  FOREACH(STRING, mod_name, modules)
1222  {
1223  user_log(" Module %s\n", mod_name);
1224 
1225  if (!renamed)
1226  {
1227  FILE * rf = NULL;
1228 
1229  if (dot_c_file_p(nfile)) {
1230  res_name = db_build_file_resource_name
1231  (DBR_C_SOURCE_FILE, mod_name, C_FILE_SUFFIX);
1232  }
1233  else {
1234  res_name = db_build_file_resource_name
1235  (DBR_INITIAL_FILE, mod_name, FORTRAN_INITIAL_FILE_SUFFIX);
1236  }
1237 
1238  string abs_res = strdup(concatenate(dir_name, "/", res_name, NULL));
1239 
1240  if ((rf = fopen(abs_res, "r"))!=NULL)
1241  { // Resource name conflict
1242  string ofile =
1243  db_get_memory_resource(DBR_USER_FILE, mod_name, true);
1244 
1245  fclose(rf);
1246  pips_user_warning("Duplicate module name \"%s\""
1247  " from files \"%s\" and \"%s\".\n",
1248  res_name, ofile, nfile);
1249  resource_name_conflicts++;
1250  break;
1251  }
1252 
1253  if (rename(file_name, abs_res))
1254  pips_internal_error("mv %s %s failed", file_name, res_name);
1255  renamed = true;
1256  free(abs_res);
1257  }
1258 
1259  if(dot_c_file_p(nfile)) {
1260  DB_PUT_NEW_FILE_RESOURCE(DBR_C_SOURCE_FILE, mod_name,
1261  strdup(res_name));
1262  DB_PUT_NEW_FILE_RESOURCE(DBR_INPUT_FILE_NAME, mod_name,
1263  strdup(initial_file));
1264  }
1265  else {
1266  DB_PUT_NEW_FILE_RESOURCE(DBR_INITIAL_FILE, mod_name,
1267  strdup(res_name));
1268  }
1269  // from which file the initial source was derived.
1270  // absolute path to the file so that db moves should be ok?
1271  DB_PUT_NEW_FILE_RESOURCE(DBR_USER_FILE, mod_name, strdup(nfile));
1272 
1273  if ( dot_f90_file_p( nfile ) || dot_f95_file_p( nfile ) )
1274  {
1275  char *parsedcode_filename =
1276  get_resource_file_name(DBR_PARSED_CODE, mod_name);
1277  FILE *parsedcode_file = safe_fopen( parsedcode_filename, "r" );
1278  DB_PUT_NEW_FILE_RESOURCE(DBR_PARSED_CODE, mod_name,
1279  gen_read( parsedcode_file ));
1280  safe_fclose( parsedcode_file, parsedcode_filename );
1281  char *callees_filename =
1282  get_resource_file_name( DBR_CALLEES, mod_name );
1283  FILE *callees_file = safe_fopen( callees_filename, "r" );
1284  DB_PUT_NEW_FILE_RESOURCE(DBR_CALLEES, mod_name,
1285  gen_read( callees_file ) );
1286  safe_fclose( callees_file, callees_filename );
1287  string source_file_name =
1288  strdup(concatenate(dir_name, "/", mod_name, "/", mod_name, ".f90",
1289  NULL));
1290  DB_PUT_NEW_FILE_RESOURCE( DBR_SOURCE_FILE, mod_name, source_file_name );
1291  }
1292  }
1293 
1294  gen_free_list(modules), modules=NIL;
1295 
1296  if (res_name) free(res_name), res_name = NULL;
1297  free(a_line);
1298  }
1299 
1300  safe_fclose(fd, file_list);
1301  unlink(file_list);
1302  free(file_list);
1303  free(dir_name);
1304 
1305  if (cpp_processed_p) {
1306  free(initial_file); /* hey, that's cleaning! */
1308  }
1309 
1310  if (!success_p)
1311  {
1312  // empty file... ???
1313  pips_user_warning("No module was found when splitting file %s.\n", nfile);
1314  }
1315 
1316  if (cpp_processed_p) {
1317  // nfile is not the initial file
1318  pips_debug(1, "Remove output of preprocessing: %s\n", nfile);
1319  /* Seems to be recorded as a resource, causes problems later when
1320  closing the workspace... */
1321  /* unlink(nfile); */
1322  }
1323  free(nfile);
1324 
1325  // well, returns ok whether modules were found or not,
1326  // but do not accept name conflicts.
1327  return resource_name_conflicts==0;
1328 }
void user_log(const char *format,...)
Definition: message.c:234
char * find_file_in_directories(const char *file_name, const char *dir_path)
returns an allocated string pointing to the file, possibly with an additional path taken from colon-s...
Definition: file.c:399
char * safe_readline(FILE *file)
returns the allocated line read, whatever its length.
Definition: file.c:497
gen_chunk * gen_read(FILE *file)
GEN_READ reads any object from the FILE stream.
Definition: genClib.c:2323
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
static string process_thru_cpp(string name)
Process a file through a C or Fortran preprocessor according to its type.
Definition: source_file.c:916
bool dot_c_file_p(string name)
Test if a name ends with .c.
Definition: source_file.c:661
static bool check_c_file_syntax(string file_name)
Verify that the C syntax of a source file is correct by compiling it.
Definition: source_file.c:1034
bool dot_f_file_p(string name)
Test if a name ends with .f.
Definition: source_file.c:643
static char * extract_last_name(char *line)
"foo bla fun ./e.database/foo.f" -> "./e.database/foo.f"
Definition: source_file.c:1050
static bool check_fortran_syntax_before_pips(string file_name)
Verify that the Fortran syntax of a source file is correct by compiling it.
Definition: source_file.c:1020
bool dot_f90_file_p(string name)
Test if a name ends with .f90.
Definition: source_file.c:649
string preprocessor_current_initial_file_name
The digestion of a user file by PIPS begins here.
Definition: source_file.c:1088
static bool pips_check_fortran(void)
A Fortran compiler must be run or not before launching the PIPS Fortran parser, according to the envi...
Definition: source_file.c:955
bool dot_f95_file_p(string name)
Test if a name ends with .f95.
Definition: source_file.c:655
static bool pips_split_file(string name, string tempfile)
Definition: source_file.c:586
static bool pips_check_c(void)
A C compiler must be run or not before launching the PIPS C parser, according to the environment vari...
Definition: source_file.c:968
bool dot_F_file_p(string name)
Test if a name ends with .F.
Definition: source_file.c:637
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References check_c_file_syntax(), check_fortran_syntax_before_pips(), concatenate(), CONS, db_build_file_resource_name(), db_get_current_workspace_directory(), db_get_memory_resource(), DB_PUT_NEW_FILE_RESOURCE, dot_c_file_p(), dot_f90_file_p(), dot_f95_file_p(), dot_F_file_p(), dot_f_file_p(), extract_last_name(), file_name, find_file_in_directories(), FOREACH, free(), gen_free_list(), gen_read(), get_bool_property(), get_resource_file_name(), NIL, pips_check_c(), pips_check_fortran(), pips_debug, pips_internal_error, pips_split_file(), pips_user_error, pips_user_warning, preprocessor_current_initial_file_name, process_thru_cpp(), safe_fclose(), safe_fopen(), safe_readline(), SRCPATH, strdup(), STRING, string_undefined, and user_log().

Referenced by add_a_file(), ask_a_missing_file(), create_workspace(), retrieve_a_missing_file_using_external_resolver(), and retrieve_a_missing_file_using_internal_resolver().

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

◆ push_new_preprocessor_scope()

void push_new_preprocessor_scope ( void  )

Definition at line 307 of file splitc.c.

308  {
310  string sn = string_undefined;
311  (void) asprintf(&sn, "%d", c_preprocessor_scope_number);
313  return;
314  }
#define asprintf
Definition: misc-local.h:225
void stack_push(void *, stack)
stack use
Definition: stack.c:373

References asprintf, c_preprocessor_scope_number, c_preprocessor_scope_stack, stack_push(), and string_undefined.

+ Here is the call graph for this function:

◆ reset_csplit_current_beginning()

void reset_csplit_current_beginning ( void  )

This function is called at the end of any top-level C construct:

Snapshot the current file position as a potential function begin:

Aggregate following spaces and comments on the sameline to the previous top-level construct:

FI: I'm not ready to abort() here...

Definition at line 1152 of file lexer.c.

1153 {
1154  int leaked = 0;
1155 
1156  csplit_current_beginning = 1000000;
1157  user_current_beginning = 1000000;
1158  csplit_is_static_p = false;
1159 
1160  /* Snapshot the current file position as a potential function begin: */
1162 
1163  /* Aggregate following spaces and comments on the sameline to the
1164  previous top-level construct: */
1166 
1167 
1171 
1175 
1179 
1183 
1184  if((leaked=check_signature_balance())!=0) {
1185  /* FI: I'm not ready to abort() here... */
1186  pips_debug(5, "Likely memory leaks: %d\n", leaked);
1187  }
1188 }
enum gather_comment_state_t gather_comment_state_machine
Indeed it does not work since csplit_copy() is called from splitc.y when a function definition is fou...
Definition: lexer.c:1113
@ GATHER_COMMENT
We gather comments in the previous top-level construct.
Definition: lexer.c:1107
string csplit_current_function_name
to know if this is the declaration of a function or not, to distinguish between a static variable and...
Definition: splitc.c:123
bool csplit_is_static_p
static int enum_counter = 0;
Definition: splitc.c:143
string csplit_definite_function_signature
Definition: splitc.c:126
string csplit_definite_function_name
Definition: splitc.c:125
int check_signature_balance(void)
Definition: splitc.c:524
string csplit_current_function_name2
Definition: splitc.c:124

References check_signature_balance(), csplit_current_beginning, csplit_current_function_name, csplit_current_function_name2, csplit_definite_function_name, csplit_definite_function_signature, csplit_file_offset_beginning, csplit_is_static_p, current_csplit_file_offset, free(), GATHER_COMMENT, gather_comment_state_machine, pips_debug, string_undefined, string_undefined_p, and user_current_beginning.

+ Here is the call graph for this function:

◆ reset_csplit_line_number()

void reset_csplit_line_number ( void  )

Reinitialise global position numbers for a new file.

Definition at line 1124 of file lexer.c.

1125 {
1126  csplit_line_number = 1;
1127  user_line_number = 1;
1131  bracket_depth = 0;
1132 }
static int bracket_depth
To track nesting in brackets.
Definition: lexer.c:1096
int csplit_line_number
To be exported to the parser for splitting the preprocessed file.
Definition: lexer.c:1085
int user_line_number
To be exported to the parser for error messages related to the user file.
Definition: lexer.c:1087
@ PUT_IN_NEXT_TOP_LEVEL_CONSTRUCT
Normal mode: comments and spaces are associated to the top-level construct to encounter:
Definition: lexer.c:1102

References bracket_depth, csplit_file_offset_beginning, csplit_line_number, current_csplit_file_offset, gather_comment_state_machine, PUT_IN_NEXT_TOP_LEVEL_CONSTRUCT, and user_line_number.

Referenced by csplit_error_handler(), and csplit_reset().

+ Here is the caller graph for this function:

◆ reset_current_input_line()

void reset_current_input_line ( void  )

In file just above.

Definition at line 93 of file csplit_file.c.

94 {
96 }

References current_input_line.

Referenced by csplit_error_handler(), and csplit_reset().

+ Here is the caller graph for this function:

◆ reset_module_name_list()

void reset_module_name_list ( void  )

Definition at line 65 of file csplit_file.c.

66 {
67  pips_assert("module_name_list is not undefined",
71 }
#define list_undefined
Undefined list definition :-)
Definition: newgen_list.h:69

References gen_free_list(), list_undefined, list_undefined_p, module_name_list, and pips_assert.

Referenced by error_reset_module_name_list().

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

◆ reset_preprocessor_scope_stack()

void reset_preprocessor_scope_stack ( void  )

Definition at line 280 of file splitc.c.

281  {
286  }
287  else {
288  // pips_internal_error? Could be a bad input C file...
289  pips_user_warning("Preprocessor scope stack is not empty.\n");
290  }
291  }
293  return;
294  }

References c_preprocessor_scope_number, c_preprocessor_scope_stack, pips_user_warning, SCOPE_UNDEFINED, stack_empty_p(), stack_free(), and stack_undefined.

Referenced by csplit_close_compilation_unit().

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

◆ ResetTypedefStack()

void ResetTypedefStack ( )

Definition at line 249 of file splitc.c.

250  {
254  }
255  else
256  pips_internal_error("TypedefStack is not empty");
257  }

◆ splitc_alloc()

void* splitc_alloc ( yy_size_t  )

◆ splitc_error()

void splitc_error ( const char *  )

◆ splitc_free()

void splitc_free ( void *  )

◆ splitc_get_debug()

int splitc_get_debug ( void  )

◆ splitc_get_in()

FILE* splitc_get_in ( void  )

◆ splitc_get_leng()

int splitc_get_leng ( void  )

◆ splitc_get_lineno()

int splitc_get_lineno ( void  )

◆ splitc_get_out()

FILE* splitc_get_out ( void  )

◆ splitc_get_text()

char* splitc_get_text ( void  )

◆ splitc_lex()

int splitc_lex ( )

◆ splitc_lex_destroy()

int splitc_lex_destroy ( )

◆ splitc_parse()

int splitc_parse ( )

◆ splitc_pop_buffer_state()

void splitc_pop_buffer_state ( void  )

◆ splitc_realloc()

void* splitc_realloc ( void *  ,
yy_size_t   
)

◆ splitc_restart()

void splitc_restart ( FILE *  )

◆ splitc_set_debug()

void splitc_set_debug ( int  )

◆ splitc_set_in()

void splitc_set_in ( FILE *  )

◆ splitc_set_lineno()

void splitc_set_lineno ( int  )

◆ splitc_set_out()

void splitc_set_out ( FILE *  )

◆ splitc_wrap()

int splitc_wrap ( void  )

◆ update_csplit_file_offset_information()

void update_csplit_file_offset_information ( void  )

Function called each time a token is read to trac file position information:

Definition at line 1218 of file lexer.c.

1218  {
1220 }
#define yyleng
Definition: lexer.c:22

References current_csplit_file_offset, and yyleng.

◆ workspace_language()

language workspace_language ( gen_array_t  files)

Choose a language if all filenames in "files" have the same C or Fortran extensions.

Parameters
filesiles

Definition at line 667 of file source_file.c.

668 {
669  int i, argc = gen_array_nitems(files);
671  int n_fortran = 0;
672  int n_fortran95 = 0;
673  int n_c = 0;
674 
675  for (i = 0; i < argc; i++) {
676  string fn = gen_array_item(files, i);
677  if(dot_F_file_p(fn) || dot_f_file_p(fn))
678  n_fortran++;
679  else if(dot_c_file_p(fn))
680  n_c++;
681  else if(dot_f90_file_p(fn) || dot_f95_file_p(fn)){
682  n_fortran95++;
683  } else {
684  ;
685  }
686  }
687 
688  if(n_fortran>0 && n_fortran95==0 && n_c==0) {
689  l = make_language_fortran();
690  } else if(n_fortran==0 && n_fortran95>0 && n_c==0) {
692  } else if(n_fortran==0 && n_fortran95==0 && n_c>0) {
693  l = make_language_c();
694  } else {
695  l = make_language_unknown();
696  }
697 
698  return l;
699 }
language make_language_fortran95(void)
Definition: ri.c:1256
language make_language_fortran(void)
Definition: ri.c:1250
language make_language_unknown(void)
Definition: ri.c:1259
language make_language_c(void)
Definition: ri.c:1253
#define language_undefined
Definition: ri.h:1551

References dot_c_file_p(), dot_f90_file_p(), dot_f95_file_p(), dot_F_file_p(), dot_f_file_p(), gen_array_item(), gen_array_nitems(), language_undefined, make_language_c(), make_language_fortran(), make_language_fortran95(), and make_language_unknown().

Referenced by add_a_file(), and create_workspace().

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

Variable Documentation

◆ csplit_current_function_name

string csplit_current_function_name
extern

to know if this is the declaration of a function or not, to distinguish between a static variable and a static function

Shared with the lexical analyzer

Definition at line 123 of file splitc.c.

Referenced by reset_csplit_current_beginning(), and reset_csplit_current_function_name().

◆ csplit_current_function_name2

string csplit_current_function_name2
extern

Definition at line 124 of file splitc.c.

Referenced by reset_csplit_current_beginning(), and reset_csplit_current_function_name().

◆ csplit_definite_function_name

string csplit_definite_function_name
extern

Definition at line 125 of file splitc.c.

Referenced by reset_csplit_current_beginning().

◆ csplit_definite_function_signature

string csplit_definite_function_signature
extern

Definition at line 126 of file splitc.c.

Referenced by reset_csplit_current_beginning().

◆ csplit_file_offset_beginning

size_t csplit_file_offset_beginning
extern

◆ csplit_is_external

int csplit_is_external
extern

splitc.c

splitc.c

For the moment, block scope is not considered. CurrentScope can be File, Module, File'FILE_SEP_STRING'Module or TOP-LEVEL static string CurrentScope = NULL; static string CurrentDerivedName = NULL; to remember the name of a struct and add it to the member prefix name static int CurrentMode = 0; to know the mode of the formal parameter : by value or by reference

Definition at line 119 of file splitc.c.

◆ csplit_is_function

int csplit_is_function
extern

to know if the variable is declared inside or outside a function

Definition at line 120 of file splitc.c.

◆ csplit_is_static_p

bool csplit_is_static_p
extern

static int enum_counter = 0;

Shared with the lexical analyzer

Definition at line 143 of file splitc.c.

Referenced by reset_csplit_current_beginning().

◆ csplit_line_number

int csplit_line_number
extern

To be exported to the parser for splitting the preprocessed file.

Definition at line 1085 of file lexer.c.

Referenced by csplit_parser_warning_alist(), reset_csplit_line_number(), and update_csplit_current_beginning().

◆ current_csplit_file_offset

◆ current_file_name

string current_file_name
extern

Split a C file into one file per module (function or procedure) plus.

Parameters
dir_namethe directory name where the input file is to pick
file_namethe C input file name to split
outfile opened to record module and compilation unit names
Returns
an error message or NULL if no error has occurred.

Definition at line 640 of file csplit_file.c.

Referenced by csplit(), and csplit_parser_error().

◆ current_file_path

char* current_file_path
extern

Definition at line 52 of file csplit_file.c.

Referenced by csplit(), and csplit_close_files().

◆ current_include_file_path

char* current_include_file_path
extern

csplit_file.c

csplit_file.c

Definition at line 51 of file csplit_file.c.

Referenced by csplit(), csplit_close_files(), and csplit_copy().

◆ fsplit_copyright

char fsplit_copyright[]
extern

split_file.c

Definition at line 114 of file split_file.c.

◆ fsplit_sccsid

char fsplit_sccsid[]
extern

not lint

Definition at line 120 of file split_file.c.

◆ gather_comment_state_machine

enum gather_comment_state_t gather_comment_state_machine
extern

Indeed it does not work since csplit_copy() is called from splitc.y when a function definition is found and thus we cannot gather the comment in it...

:-(

Definition at line 1096 of file lexer.c.

Referenced by reset_csplit_current_beginning(), reset_csplit_line_number(), and update_csplit_current_beginning().

◆ preprocessor_current_initial_file_name

string preprocessor_current_initial_file_name
extern

The digestion of a user file by PIPS begins here.

The file is searched in the SRCPATH directories.

Definition at line 1088 of file source_file.c.

Referenced by csplit_copy(), csplit_parser_warning_alist(), and process_user_file().

◆ preprocessor_current_split_file_name

string preprocessor_current_split_file_name
extern

Split a C or Fortran file into as many files as modules.

Definition at line 584 of file source_file.c.

Referenced by csplit_parser_warning_alist(), and pips_split_file().

◆ splitc__flex_debug

int splitc__flex_debug
extern

◆ splitc_char

int splitc_char
extern

◆ splitc_in

FILE* splitc_in
extern

Definition at line 174 of file preprocessor.h.

◆ splitc_leng

int splitc_leng
extern

lexer.c

◆ splitc_lineno

int splitc_lineno
extern

◆ splitc_nerrs

int splitc_nerrs
extern

◆ splitc_out

FILE* splitc_out
extern

◆ splitc_text

char* splitc_text
extern

Definition at line 178 of file preprocessor.h.

◆ user_line_number

int user_line_number
extern

To be exported to the parser for error messages related to the user file.

Definition at line 1087 of file lexer.c.

Referenced by c_parser_error(), reset_csplit_line_number(), and update_csplit_current_beginning().