25 #include "pips_config.h"
56 #include "constants.h"
57 #include "resources.h"
66 #define skip_line_p(s) \
67 ((*(s))=='\0' || (*(s))=='!' || (*(s))=='*' || (*(s))=='c' || (*(s))=='C')
81 for (i = 0; i < n; i++) {
101 dir_name,
"/", HPFC_COMPILED_FILE_DIR,
"/",
file_name, NULL));
107 char ** hpfc_directory_name)
110 static int hpfc_bsz = 0;
111 static char * hpfc_dir = NULL;
113 int return_code, len;
116 len = strlen(dir) + strlen(HPFC_COMPILED_FILE_DIR) + 5;
119 if (hpfc_dir)
free(hpfc_dir), hpfc_dir=NULL;
121 hpfc_dir = (
char*)
malloc(hpfc_bsz);
126 sprintf(hpfc_dir,
"%s/%s", dir, HPFC_COMPILED_FILE_DIR);
133 *hpfc_directory_name = hpfc_dir;
179 string old_path, new_path;
184 old_path =
strdup(old_path);
185 new_path =
concatenate(old_path? old_path:
"", old_path?
":":
"",
201 (
"trap 'exit 123' 2; pips-process-module ",
file_name, NULL));
209 (
"Unexpected return code from pips-process-module: %d\n", err);
218 #define IMPLICIT_NONE_RX "^[ \t]*implicit[ \t]*none"
219 #define INCLUDE_FILE_RX "^[ \t]*include[ \t]*['\"]\\([^'\"]*\\)['\"]"
231 "^[^\t!*Cc].....[^\"']*[^a-zA-Z0-9_ \t][ \t]*\\((\\)[-+0-9eE\\. \t]*,[-+0-9eE\\. \t]*)"
234 "^[^\t!*Cc].....[ \t]*\\((\\)[-+0-9eE\\. \t]*,[-+0-9eE\\. \t]*)"
237 "^[^\t!*Cc].....[^\"']*[^a-zA-Z0-9_ \t][ \t]*" \
238 "\\((\\)[-+0-9dDeE\\. \t]*,[-+0-9dDeE\\. \t]*)"
241 "^[^\t!*Cc].....[ \t]*\\((\\)[-+0-9dDeE\\. \t]*,[-+0-9dDeE\\. \t]*)"
243 #define GOTO_RX "g[ \t]*o[ \t]*t[ \t]*o[ \t]*"
259 string srcpath = getenv(
SRCPATH), result;
261 srcpath? srcpath:
"",
":",
323 static int unique = 0;
327 len = strlen(dir_name)+20;
330 sprintf(
file_name,
"%s/cached.%d", dir_name, unique++);
355 "!! ERROR - include \"%s\" was not found\n"
360 pips_debug(2,
"including file \"%s\"\n", found);
394 FILE * tmp_hbc, * tmp_in;
419 free(cached), cached = NULL;
459 "! MIL-STD-1753 Fortran extension not in PIPS\n! ");
474 static bool done=
false;
503 string name, new_name, dir_name, abs_name, abs_new_name;
510 (DBR_SOURCE_FILE, mod_name, FORTRAN_FILE_SUFFIX);
537 int len = strlen(s)-1;
538 return len>=8 && s[len-8]==
'/' && s[len-7]==
'#' && s[len-6]==
'#' &&
539 s[len-5]==
'#' && s[len-1]==
'.' && s[len]==
'f';
547 char **
lines = (
char**)
malloc(
sizeof(
char*)*size);
557 lines = (
char**) realloc(
lines,
sizeof(
char*)*size);
607 fprintf(stderr,
"split error while extracting %s from %s: %s\n",
608 tempfile, name, err);
623 strcpy(suffix, FORTRAN_FILE_SUFFIX);
626 strcpy(suffix, C_FILE_SUFFIX);
650 return !!
find_suffix( name, FORTRAN90_FILE_SUFFIX );
656 return !!
find_suffix( name, FORTRAN95_FILE_SUFFIX );
675 for (i = 0; i < argc; i++) {
688 if(n_fortran>0 && n_fortran95==0 && n_c==0) {
690 }
else if(n_fortran==0 && n_fortran95>0 && n_c==0) {
692 }
else if(n_fortran==0 && n_fortran95==0 && n_c>0) {
707 static int colon_number(
string s)
709 int number = s? 1: 0;
714 if(c==
':' && new_s!=s+1 && *new_s!=
'\000')
728 while((c=getc(
f))!=EOF) {
754 string includes =
strdup(
"");
757 for(
int i = 0;; i++) {
759 string p =
nth_path(include_path, i);
763 string old_includes = includes;
779 string dir_name, new_name, simpler, cpp_options, cpp, cpp_err;
781 string include_path = getenv(
SRCPATH);
799 pips_debug(1,
"PIPS_SRCPATH=\"%s\"\n", include_path);
807 "EOL encoding for file \"%s\" is \"%s\" and not supported\n",
808 name, eol_code==1?
"dos" :
"iso22");
814 name,
"' > '", new_name,
"' 2> ", cpp_err, NULL));
839 (
concatenate(
"sed -i -e \"s/(long double __x) ;/(long double __y);/2g\" '",
840 new_name,
"' 2> ", cpp_err, NULL));
865 string dir_name, new_name, simpler, fpp_options, fpp, fpp_err;
895 " ", name,
" > ", new_name,
" 2> ", fpp_err,
897 " && test ! -s ", fpp_err,
898 " && rm -f ", fpp_err, NULL));
935 string v = getenv(
env);
937 if (v && (*v==
'o' || *v==
'y' || *v==
't' || *v==
'v' || *v==
'1' ||
938 *v==
'O' || *v==
'Y' || *v==
'T' || *v==
'V'))
941 if (v && (*v==
'n' || *v==
'f' || *v==
'0' || *v==
'N' || *v==
'F' ))
957 string env =
"PIPS_CHECK_FORTRAN";
958 string prop =
"CHECK_FORTRAN_SYNTAX_BEFORE_RUNNING_PIPS";
970 string env =
"PIPS_CHECK_C";
971 string prop =
"CHECK_C_SYNTAX_BEFORE_RUNNING_PIPS";
984 bool syntax_ok_p =
true;
987 string include_path = getenv(
SRCPATH);
995 (
concatenate(compiler,
" ", options, includes,
" ", pfile_name,
" ",
999 " -c -o /dev/null", NULL)))
1008 "Check source file and/or compilation and preprocessing flags.\n",
1010 syntax_ok_p =
false;
1023 string fortran = getenv(
"PIPS_FLINT");
1024 if (!fortran) fortran = getenv(
"PIPS_F77");
1027 string flags = getenv(
"PIPS_CPP_FLAGS");
1028 flags = flags? flags:
"";
1036 string comp = getenv(
"PIPS_CC");
1037 string flags = getenv(
"PIPS_CPP_FLAGS");
1038 bool syntax_ok_p =
true;
1055 for(
int i =2;i&&iter!=
line;--iter) {
1060 iter= strrchr(
line,
' ');
1073 int l = strlen(
line);
1075 while (l>=0 &&
line[l]!=
' ') l--;
1076 if (l>=0 &&
line[l]==
' ')
line[l]=
'\0';
1077 }
while (l>=0 && strlen(
line+l+1)==0);
1078 return l>=-1?
line+l+1: NULL;
1092 bool success_p =
false, cpp_processed_p;
1097 bool generate_user_error =
1101 static int number_of_files = 0;
1102 static int number_of_modules = 0;
1103 static int resource_name_conflicts = 0;
1106 pips_debug(1,
"file %s (number %d)\n", file, number_of_files);
1118 string initial_file = nfile;
1122 user_log(
"Registering file %s\n", file);
1124 bool syntax_ok_p =
true;
1141 pips_debug(1,
"No syntactic check on file \"%s\"\n", nfile);
1146 if (generate_user_error)
1157 if (cpp_processed_p)
1159 user_log(
"Preprocessing file %s\n", initial_file);
1163 if (generate_user_error)
1183 "/.csplit_file_list" :
"/.fsplit_file_list", NULL));
1186 user_log(
"Splitting file %s\n", nfile);
1189 if (generate_user_error)
1199 while ((a_line =
safe_readline(fd)) && resource_name_conflicts == 0)
1201 string mod_name = NULL, res_name = NULL;
1212 number_of_modules++;
1223 user_log(
" Module %s\n", mod_name);
1231 (DBR_C_SOURCE_FILE, mod_name, C_FILE_SUFFIX);
1235 (DBR_INITIAL_FILE, mod_name, FORTRAN_INITIAL_FILE_SUFFIX);
1240 if ((rf = fopen(abs_res,
"r"))!=NULL)
1247 " from files \"%s\" and \"%s\".\n",
1248 res_name, ofile, nfile);
1249 resource_name_conflicts++;
1275 char *parsedcode_filename =
1277 FILE *parsedcode_file =
safe_fopen( parsedcode_filename,
"r" );
1280 safe_fclose( parsedcode_file, parsedcode_filename );
1281 char *callees_filename =
1283 FILE *callees_file =
safe_fopen( callees_filename,
"r" );
1287 string source_file_name =
1296 if (res_name)
free(res_name), res_name = NULL;
1305 if (cpp_processed_p) {
1316 if (cpp_processed_p) {
1318 pips_debug(1,
"Remove output of preprocessing: %s\n", nfile);
1327 return resource_name_conflicts==0;
void user_log(const char *format,...)
language make_language_fortran95(void)
language make_language_fortran(void)
language make_language_unknown(void)
language make_language_c(void)
callees make_callees(list a)
bool db_resource_p(const char *rname, const char *oname)
true if exists and in loaded or stored state.
#define error(fun, msg)
NewGen interface with C3 type Psysteme for PIPS project.
size_t gen_array_nitems(const gen_array_t a)
void * gen_array_item(const gen_array_t a, size_t i)
string csplit(char *dir_name, char *file_name, FILE *out)
struct _newgen_struct_status_ * status
const char * module_name(const char *s)
Return the module part of an entity name.
char * f95split(char *dir_name, char *file_name, FILE **out)
f95split_file.c
FILE * safe_fopen(const char *filename, const char *what)
bool file_exists_p(const char *name)
char * pips_initial_filename(char *fullpath, char *suffix)
The source file name access path is shortened or not depending on the property.
string nth_path(const char *path_list, int n)
Returns the allocated nth path from colon-separated path string.
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...
char * get_cwd(void)
returns the current working directory name.
int safe_fclose(FILE *stream, const char *filename)
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...
bool directory_exists_p(const char *name)
char * strescape(const char *source)
protect a string, for example for use in a system call list of non escaped characters in the macro ab...
some path to file suffix some path to *char * pips_dirname(char *fullpath)
char * safe_readline(FILE *file)
returns the allocated line read, whatever its length.
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...
char * pips_basename(char *fullpath, char *suffix)
void safe_unlink(const char *file_name)
Delete the given file.
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
void safe_cat(FILE *out, FILE *in)
static FILE * user_file
These functions implements the writing of objects.
gen_chunk * gen_read(FILE *file)
GEN_READ reads any object from the FILE stream.
#define NIL
The empty list (nil in Lisp)
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
void gen_free_list(list l)
free the spine of the list
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
#define DB_PUT_NEW_FILE_RESOURCE(res_name, own_name, res_val)
Put a new file resource into the current workspace database.
static GtkWidget * lines[HELP_LINES]
hash_table hash_table_make(hash_key_type key_type, size_t size)
void * hash_get(const hash_table htp, const void *key)
this function retrieves in the hash table pointed to by htp the couple whose key is equal to key.
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.
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
string db_build_file_resource_name(const char *rname, const char *oname, const char *suffix)
returns an allocated file name for a file resource.
string get_resource_file_name(const char *rname, const char *oname)
allocate a full file name for the given resource.
string db_get_directory_name_for_module(const char *name)
returns the allocated and mkdir'ed directory for module name
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
#define pips_user_warning
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
#define pips_internal_error
int safe_system_no_abort(string)
the command to be executed
#define message_assert(msg, ex)
string find_suffix(const string, const string)
Find if a string s end with a suffix.
string concatenate(const char *,...)
Return the concatenation of the given strings.
#define HASH_MAP(k, v, code, ht)
#define HASH_UNDEFINED_VALUE
value returned by hash_get() when the key is not found; could also be called HASH_KEY_NOT_FOUND,...
#define hash_table_undefined_p(h)
#define hash_table_undefined
Value of an undefined hash_table.
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
#define WORKSPACE_TMP_SPACE
string db_get_current_workspace_directory(void)
string db_get_current_workspace_name(void)
the function is used to check that there is some current workspace...
#define FPP_CPPFLAGS
The default preprocessor flags to use with Fortran files.
#define FPP_CPP
The preprocessor to use for Fortran files.
#define FPP_PIPS_OPTIONS_ENV
#define SRCPATH
Preprocessing and splitting of Fortran and C files.
#define DEFAULT_PIPS_CC_FLAGS
#define CPP_CPP
default preprocessor and basic options -C: do not discard comments...
#define CPP_PIPS_ENV
pre-processor and added options from environment
#define CPP_PIPS_OPTIONS_ENV
#define CPP_CPPFLAGS
#define CPP_CPPFLAGS " -P -D__PIPS__ -D__HPFC__ "
#define DEFAULT_PIPS_FLINT
#define DEFAULT_PIPS_CC
See necessary definitions in pipsmake-rc.tex.
char * fsplit(char *, char *, FILE *)
char * process_bang_comments_and_hollerith(FILE *, FILE *)
processing extracted for includes...
struct _newgen_struct_callees_ * callees
#define callees_callees(x)
#define language_undefined
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
static int line
FLEX_SCANNER.
static hash_table matches
static void init_rx(void)
static string process_thru_cpp(string name)
Process a file through a C or Fortran preprocessor according to its type.
static void clean_file(string name)
static regex_t implicit_none_rx
void pips_get_fortran_list(gen_array_t array)
Select the true file with names ending in ".[fF]" and return a sorted arg list:
static bool pips_check_syntax(string env, string prop)
Why return an int rather than a bool?
string preprocessed_to_user_file(string preprocessed_user_file)
Allocate a new string containing the user file name, before preprocessing.
bool dot_c_file_p(string name)
Test if a name ends with .c.
bool filter_file(string mod_name)
#define CMPLX_RX
not recognized: print *, "i = ", (0.,1.) to avoid modifying a character constant.....
static string process_thru_C_pp(string name)
Process a file name.c through the C preprocessor to generate a name.cpp_processed....
static bool check_c_file_syntax(string file_name)
Verify that the C syntax of a source file is correct by compiling it.
bool dot_f_file_p(string name)
Test if a name ends with .f.
static string include_path_to_include_flags(string include_path)
static bool handle_file(FILE *, FILE *)
double recursion (handle_file/handle_file_name) => forwarded declaration.
static regex_t some_goto_rx
static bool handle_file_name(FILE *out, char *file_name, bool included)
static char * extract_last_name(char *line)
"foo bla fun ./e.database/foo.f" -> "./e.database/foo.f"
static bool check_fortran_syntax_before_pips(string file_name)
Verify that the Fortran syntax of a source file is correct by compiling it.
string preprocessor_current_split_file_name
Split a C or Fortran file into as many files as modules.
static regex_t dcomplex_cst_rx
language workspace_language(gen_array_t files)
Choose a language if all filenames in "files" have the same C or Fortran extensions.
static string get_new_tmp_file_name(void)
return an allocated unique cache file name.
bool dot_f90_file_p(string name)
Test if a name ends with .f90.
bool flag_as_stub(const string module_name)
void pips_get_workspace_list(gen_array_t array)
Return a sorted arg list of workspace names.
static bool pips_process_file(string file_name, string new_name)
static regex_t complex_cst2_rx
string preprocessor_current_initial_file_name
The digestion of a user file by PIPS begins here.
void init_processed_include_cache(void)
static bool pips_check_fortran(void)
A Fortran compiler must be run or not before launching the PIPS Fortran parser, according to the envi...
static bool zzz_file_p(string s)
is the file name of the form .../zzz???.f
#define skip_line_p(s)
include "pipsmake.h"
int find_eol_coding(string name)
Returns the newly allocated name if preprocessing succeeds.
static bool check_input_file_syntax(string file_name, string compiler, string options, string language)
Verify that the syntax of a program is correct by running a real compiler on it.
static string find_file(string name)
tries several path for a file to include...
string pips_change_directory(const char *dir)
Change to the given directory if it exists and return a canonical 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.
static string get_cached(string s)
Returns the processed cached file name, or null if none.
bool bootstrap_stubs(const string module_name)
bool dot_f95_file_p(string name)
Test if a name ends with .f95.
void close_processed_include_cache(void)
static bool handle_include_file(FILE *out, char *file_name)
static regex_t dcomplex_cst2_rx
static bool pips_split_file(string name, string tempfile)
static string process_thru_fortran_pp(string name)
Process a ratfor file name.F through the C preprocessor to generate a name.fpp_processed....
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...
static hash_table processed_cache
cache of preprocessed includes
string pips_srcpath_append(string pathtoadd)
returns an allocated pointer to the old value
bool dot_F_file_p(string name)
Test if a name ends with .F.
static regex_t include_file_rx
void pips_srcpath_set(string path)
Set the PIPS source path.
bool process_user_file(string file)
int hpfc_get_file_list(gen_array_t file_names, char **hpfc_directory_name)
static string user_file_directory
static regex_t complex_cst_rx
The structure used to build lists in NewGen.