PIPS
top-level.h File Reference
#include <setjmp.h>
#include "constants.h"
+ Include dependency graph for top-level.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void default_update_props (void)
 Warning! Do not modify this file that is automatically generated! More...
 
bool open_module (const char *)
 tpips used to convert lower cases into upper cases for all module names, but this is no longer possible with C functions. More...
 
bool open_module_if_unique (void)
 Open the module of a workspace if there is only one. More...
 
bool create_workspace (gen_array_t)
 FI: should be called "initialize_workspace()"; a previous call to db_create_workspace() is useful to create the log file between the two calls says RK. More...
 
bool lazy_open_module (const char *)
 Do not open a module already opened : More...
 
bool open_workspace (const char *)
 should be: success (cf wpips.h) More...
 
bool close_workspace (bool)
 
bool delete_workspace (const char *)
 
bool check_delete_workspace (const char *, bool)
 
void compile_f90_module (string)
 
gen_array_t get_stubs (void)
 Get all stubs. More...
 
void get_help_topics (gen_array_t)
 help.c More...
 
void get_help_topic (string, gen_array_t)
 
void pips_checks (void)
 add checkings here (FI: why in help.c?) SG : PIPS_ROOT should not be required :) More...
 

Variables

void(* pips_update_props_handler )(void)
 default assignment of pips_update_props_handler is default_update_props. More...
 

Function Documentation

◆ check_delete_workspace()

bool check_delete_workspace ( const char *  wname,
bool  check 
)

Yes but at least close the LOGFILE if we delete the current workspace since it will fail on NFS because of the open file descriptor (creation of .nfs files). RK

reset_entity_to_size();

Parameters
wnamename
checkheck

Definition at line 375 of file dbm.c.

376 {
377  int failure;
379 
380  /* Yes but at least close the LOGFILE if we delete the current
381  workspace since it will fail on NFS because of the open file
382  descriptor (creation of .nfs files). RK */
383 
384  if (check)
385  {
386  if (current && same_string_p(wname, current))
387  pips_user_error("Cannot delete current workspace, close it first!\n");
388  }
389  else
390  {
391  string name = strdup(current);
392  (void) close_makefile(name);
393  free(name);
394  close_log_file();
396  /* reset_entity_to_size(); */
398  }
399 
400  char *escaped_wname = strescape(wname);
401  if ((failure=safe_system_no_abort(concatenate("Delete ", escaped_wname, NULL))))
402  pips_user_warning("exit code for Delete is %d\n", failure);
403  free(escaped_wname);
404 
405  return !failure;
406 }
void close_log_file(void)
Definition: message.c:162
void close_warning_file(void)
Definition: message.c:293
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...
Definition: file.c:334
void free(void *)
static int failure(Pproblem XX, Pproblem UU, Pproblem VV, struct rproblem *RR)
Definition: isolve.c:1964
#define pips_user_warning
Definition: misc-local.h:146
#define pips_user_error
Definition: misc-local.h:147
int safe_system_no_abort(string)
the command to be executed
Definition: system.c:47
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
#define same_string_p(s1, s2)
string db_get_current_workspace_name(void)
the function is used to check that there is some current workspace...
Definition: workspace.c:82
bool close_makefile(const char *)
void close_processed_include_cache(void)
Definition: source_file.c:283
char * strdup()
static size_t current
Definition: string.c:115

References close_log_file(), close_makefile(), close_processed_include_cache(), close_warning_file(), concatenate(), current, db_get_current_workspace_name(), failure(), free(), pips_user_error, pips_user_warning, safe_system_no_abort(), same_string_p, strdup(), and strescape().

Referenced by delete_workspace(), and quit_notify().

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

◆ close_workspace()

bool close_workspace ( bool  is_quit)

It is useless to save on disk some non up to date resources:

lear_props();

Parameters
is_quits_quit

Definition at line 346 of file dbm.c.

347 {
348  bool success;
349 
351  pips_user_error("No workspace to close!\n");
352 
353  /* It is useless to save on disk some non up to date resources:
354  */
356  success = make_close_workspace(is_quit);
357  close_log_file();
363  safe_pop_path();
364  return success;
365  /*clear_props();*/
366 }
static void safe_pop_path(void)
In case an error has been detected, both create_workspace and close_workspace may attempt to clean up...
Definition: dbm.c:81
bool success
Definition: gpips-local.h:59
bool make_close_workspace(bool is_quit)
FI->GO: could be in top-level, no?
Definition: openclose.c:102
void delete_some_resources(void)
this is quite ugly, but I wanted to put the enumeration down to pipsdbm.
Definition: pipsmake.c:1446
void reset_static_entities()
Definition: entity.c:146
void reset_label_counter()
Definition: entity.c:322
void safe_reset_entity_to_size(void)
In case of error handling, PIPS may try to reset this table twice.
Definition: size.c:647

References close_log_file(), close_processed_include_cache(), close_warning_file(), db_get_current_workspace_name(), delete_some_resources(), make_close_workspace(), pips_user_error, reset_label_counter(), reset_static_entities(), safe_pop_path(), and safe_reset_entity_to_size().

Referenced by close_workspace_if_opened(), close_workspace_notify(), pips_main(), quit_notify(), and tp_close_the_workspace().

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

◆ compile_f90_module()

void compile_f90_module ( string  filename)
Parameters
filenameilename

Definition at line 410 of file dbm.c.

410  {
411  string dir = db_get_current_workspace_directory( );
412 
413  // Create precompiled directory
414  char *compiled_dir_name = strdup( concatenate( dir, "/Precompiled", NULL ) );
415  mkdir( compiled_dir_name, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH );
416 
417  char *gfc_command = concatenate( "gfortran -fsyntax-only",
418  " -fcray-pointer -ffree-form",
419  " -x f95-cpp-input"
420  " -J ",
421  compiled_dir_name,
422  " ",
423  filename,
424  NULL );
425  if( 0 != system( gfc_command ) ) {
426  pips_user_warning("Precompilation failed : %s", gfc_command);
427  }
428 
429 }
string db_get_current_workspace_directory(void)
Definition: workspace.c:96

References concatenate(), db_get_current_workspace_directory(), pips_user_warning, and strdup().

Referenced by create_workspace().

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

◆ create_workspace()

bool create_workspace ( gen_array_t  files)

FI: should be called "initialize_workspace()"; a previous call to db_create_workspace() is useful to create the log file between the two calls says RK.

Parameters
filesiles

Definition at line 180 of file dbm.c.

181 {
182  int i, argc = gen_array_nitems(files);
183  string name, dir = db_get_current_workspace_directory();
184  bool success = true;
185 
186  // since db_create_workspace() must have been called before...
187  pips_assert("some current workspace", db_get_current_workspace_name());
188 
189  open_log_file(dir);
190  open_warning_file(dir);
191  free(dir);
192 
193  // although CREATE_WORKSPACE is not a pass, to avoid unknown[unknown]"
194  set_pips_current_computation("CREATE_WORKSPACE","Program");
197 
198  // pop_path() is too strict,
199  // let's push anyway since user errors are not caught below!
200  push_path();
201 
202  // Flag that check if there is F90 file
203  bool fortran_90_p = false;
204 
205  // Precompile F95/F90 files, necessary because of module
206  for ( i = 0; i < argc; i++ ) {
207  string filename = gen_array_item( files, i );
208  if ( dot_f90_file_p( filename ) || dot_f95_file_p( filename ) ) {
209  fortran_90_p = true;
210  compile_f90_module( filename );
211  }
212  }
213 
214  if (fortran_90_p) {
215  // Load entities (fortran95 need it)
216  bootstrap( NULL );
217  }
218 
219  for (i = 0; success && i < argc; i++)
220  {
222  {
223  success = false;
224  // cleanup???
225  if (!get_bool_property("CLOSE_WORKSPACE_AND_QUIT_ON_ERROR"))
226  {
227  // DB: free the hash_table, otherwise core dump during the next
228  // call to create_workspace.
232  close_log_file();
234  pop_path();
235  }
236  RETHROW();
237  }
238  TRY
239  {
242  }
243  }
244 
245  if (success)
246  {
247  (* pips_update_props_handler)();
249  user_log("Workspace %s created and opened.\n", name);
250 
251  // If there is only one function, make it the current module
253 
254  if (success)
256 
257  // set active phases
259  }
260 
261  if (success) {
262  // Try to select the source language
264 
265  l = workspace_language(files);
267  free_language(l);
268  }
269 
270  if (!success)
271  {
272  if (!get_bool_property("CLOSE_WORKSPACE_AND_QUIT_ON_ERROR"))
273  {
274  // DB: free the hash_table, otherwise core dump during the next
275  // call to create_workspace.
278  close_log_file();
280  pop_path();
281  }
282  }
283 
285  return success;
286 }
void open_warning_file(const char *dir)
Definition: message.c:286
void user_log(const char *format,...)
Definition: message.c:234
void open_log_file(const string dir)
Definition: message.c:171
void set_pips_current_computation(const char *rname, const char *oname)
message.c
Definition: message.c:65
void reset_pips_current_computation(void)
Definition: message.c:87
void free_language(language p)
Definition: ri.c:1205
bool activate_phases(void)
Use property ACTIVE_PHASES to active the phases required by the user.
Definition: activate.c:224
void activate_language(language l)
Choose the right combination of activate and setproperty for a given language.
Definition: activate.c:254
#define CATCH(what)
@ user_exception_error
#define UNCATCH(what)
#define RETHROW()
#define TRY
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
bool bootstrap(string workspace)
Definition: bootstrap.c:5619
bool open_module_if_unique(void)
Open the module of a workspace if there is only one.
Definition: dbm.c:144
void compile_f90_module(string filename)
Definition: dbm.c:410
static void pop_path(void)
Definition: dbm.c:71
static void push_path(void)
Definition: dbm.c:61
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
bool dot_f95_file_p(string)
Test if a name ends with .f95.
Definition: source_file.c:655
void init_processed_include_cache(void)
Definition: source_file.c:272
bool process_user_file(string)
Definition: source_file.c:1090
bool dot_f90_file_p(string)
Test if a name ends with .f90.
Definition: source_file.c:649
language workspace_language(gen_array_t)
Choose a language if all filenames in "files" have the same C or Fortran extensions.
Definition: source_file.c:667
void set_entity_to_size(void)
Definition: size.c:625
void reset_entity_to_size(void)
Definition: size.c:635
#define language_undefined
Definition: ri.h:1551

References activate_language(), activate_phases(), bootstrap(), CATCH, close_log_file(), close_warning_file(), compile_f90_module(), db_get_current_workspace_directory(), db_get_current_workspace_name(), dot_f90_file_p(), dot_f95_file_p(), free(), free_language(), gen_array_item(), gen_array_nitems(), get_bool_property(), init_processed_include_cache(), language_undefined, open_log_file(), open_module_if_unique(), open_warning_file(), pips_assert, pop_path(), process_user_file(), push_path(), reset_entity_to_size(), reset_pips_current_computation(), reset_static_entities(), RETHROW, set_entity_to_size(), set_pips_current_computation(), TRY, UNCATCH, user_exception_error, user_log(), and workspace_language().

Referenced by create(), end_create_workspace_notify(), execute_workspace_creation_and_so_on_given_with_options(), and pips_main().

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

◆ default_update_props()

void default_update_props ( void  )

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

Modify src/Libs/top-level/top-level-local.h instead, to add your own modifications. header file built by cproto top_level-local.h Top-level declares a extern jmp_buf pips_top_level : cproto-generated files dbm.c

Definition at line 46 of file dbm.c.

46 {}

◆ delete_workspace()

bool delete_workspace ( const char *  wname)
Parameters
wnamename

Definition at line 368 of file dbm.c.

369 {
370  int success = check_delete_workspace(wname,true);
371 
372  return success;
373 }
bool check_delete_workspace(const char *wname, bool check)
Definition: dbm.c:375

References check_delete_workspace().

Referenced by end_delete_workspace_notify().

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

◆ get_help_topic()

void get_help_topic ( string  topic,
gen_array_t  array 
)
Parameters
topicopic
arrayrray

Definition at line 64 of file help.c.

65 {
66  FILE *fd;
67  int selected = false, index=0;
68  int begin_length, end_length;
69 
70  char *line;
71 
72 
73  begin_length = strlen(BEGIN_STR);
74  end_length = strlen(END_STR);
75 
76  fd = fopen_config(XV_HELP_RC, NULL,NULL);
77  while ((line = safe_readline(fd)) != NULL)
78  {
79  if (strncmp(line, BEGIN_STR, begin_length) == 0 &&
80  strcmp(line + begin_length + 1, topic) == 0) {
81  selected = true;
82  } else if (strncmp(line, END_STR, end_length) == 0) {
83  if (selected) break;
84  }
85  else if (selected)
86  gen_array_dupaddto(array, index++, line);
87  free(line);
88  }
89 
90  if (! selected)
91  gen_array_dupaddto(array, index++, "Sorry: no help on this topic");
92 
93  fclose(fd);
94 }
void gen_array_dupaddto(gen_array_t a, size_t i, void *what)
Definition: array.c:111
char * safe_readline(FILE *file)
returns the allocated line read, whatever its length.
Definition: file.c:497
FILE * fopen_config(const char *canonical_name, const char *cproperty, const char *cenv)
Definition: file.c:952
#define END_STR
Definition: help.c:40
#define BEGIN_STR
Definition: help.c:39
static int line
FLEX_SCANNER.
Definition: scanner.c:852
static entity array

References array, BEGIN_STR, END_STR, fopen_config(), free(), gen_array_dupaddto(), line, and safe_readline().

Referenced by display_help().

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

◆ get_help_topics()

void get_help_topics ( gen_array_t  array)

help.c

Parameters
arrayrray

Definition at line 43 of file help.c.

44 {
45  int index = 0, begin_length;
46  FILE *fd;
47  char *line;
48 
49 
50  begin_length = strlen(BEGIN_STR);
51 
52  fd = fopen_config(XV_HELP_RC, NULL,NULL);
53 
54  while ((line = safe_readline(fd)) != NULL) {
55  if (strncmp(line, BEGIN_STR, begin_length) == 0)
56  gen_array_dupaddto(array, index++, line+begin_length+1);
57  free(line);
58  }
59 
60  fclose(fd);
61 }

References array, BEGIN_STR, fopen_config(), free(), gen_array_dupaddto(), line, and safe_readline().

+ Here is the call graph for this function:

◆ get_stubs()

gen_array_t get_stubs ( void  )

Get all stubs.

The returned value is allocated dynamically and needs to be freed by the caller of this function

Definition at line 433 of file dbm.c.

434 {
435  list stubs = NIL;
436 
437  // flag_as_stub pass specific
438 #ifdef DBR_STUBS
439  if (db_resource_p(DBR_STUBS, "")) {
440  callees r_stubs = (callees) db_get_memory_resource(DBR_STUBS, "", true);
441  stubs = callees_callees(r_stubs);
442  }
443 #endif // DBR_STUBS
444 
445  return gen_array_from_list(stubs);
446 }
bool db_resource_p(const char *rname, const char *oname)
true if exists and in loaded or stored state.
Definition: database.c:524
gen_array_t gen_array_from_list(list ls)
Definition: array.c:170
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
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
struct _newgen_struct_callees_ * callees
Definition: ri.h:55
#define callees_callees(x)
Definition: ri.h:675
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References callees_callees, db_get_memory_resource(), db_resource_p(), gen_array_from_list(), and NIL.

Referenced by pyps_get_stubs().

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

◆ lazy_open_module()

bool lazy_open_module ( const char *  name)

Do not open a module already opened :

Parameters
nameame

Definition at line 289 of file dbm.c.

290 {
291  bool success = true;
292 
293  pips_assert("lazy_open_module", db_get_current_workspace_name());
294  pips_assert("cannot lazy_open no module", name != NULL);
295 
298  if (strcmp(current_name, name) != 0)
299  success = open_module(name);
300  else
301  user_log ("Module %s already active.\n", name);
302  } else
303  success = open_module(name);
304 
305  return success;
306 }
string db_get_current_module_name(void)
Also used to check whether set...
Definition: database.c:1059
bool open_module(const char *name)
tpips used to convert lower cases into upper cases for all module names, but this is no longer possib...
Definition: dbm.c:95
static string current_name
Definition: tpips.c:73

References current_name, db_get_current_module_name(), db_get_current_workspace_name(), open_module(), pips_assert, and user_log().

Referenced by end_select_module_callback(), end_select_module_notify(), and tp_set_current_module().

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

◆ open_module()

bool open_module ( const char *  name)

tpips used to convert lower cases into upper cases for all module names, but this is no longer possible with C functions.

To make it easier for the user and for the validation, an upper case version of name is open if name cannot be open.

reset if needed

Parameters
nameame

Definition at line 95 of file dbm.c.

96 {
97  bool success = false;
98  char* upper_case_name = strupper(strdup(name), name);
99  char* module_name ;
100 
102  pips_user_error("No current workspace, open or create one first!\n");
103 
104  if (db_module_exists_p(name))
105  module_name = strdup(name);
106  else if(db_module_exists_p(upper_case_name)) {
107  module_name = upper_case_name;
108  pips_user_warning("Module \"%s\" selected instead of \"%s\""
109  " which was not found\n",
110  module_name, name);
111  }
112  else
113  module_name = NULL;
114 
115  if(module_name) {
116  if (db_get_current_module_name()) /* reset if needed */
118 
120  }
121 
122  if (success) {
124  user_log("Module %s selected\n", module_name);
125  }
126  else {
127  if(strcmp(name, upper_case_name)==0)
128  pips_user_warning("Could not open module %s\n", name);
129  else
130  pips_user_warning("Could not open module %s (nor %s)\n",
131  name, upper_case_name);
132  }
133 
134  if (upper_case_name != module_name)
135  free(upper_case_name);
136  return success;
137 }
void db_reset_current_module_name(void)
Definition: database.c:1064
bool db_set_current_module_name(const char *name)
Definition: database.c:1045
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
bool db_module_exists_p(const char *name)
Return whether name is a "valid" module.
Definition: database.c:1129
string strupper(string, const char *)
Definition: string.c:213
void reset_unique_variable_numbers(void)
Definition: variable.c:421

References db_get_current_module_name(), db_get_current_workspace_name(), db_module_exists_p(), db_reset_current_module_name(), db_set_current_module_name(), free(), module_name(), pips_user_error, pips_user_warning, reset_unique_variable_numbers(), strdup(), strupper(), and user_log().

Referenced by lazy_open_module(), open_module_if_unique(), and pips_main().

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

◆ open_module_if_unique()

bool open_module_if_unique ( void  )

Open the module of a workspace if there is only one.

Returns
true if all was OK or if nothing has been done (there is no single module).

Definition at line 144 of file dbm.c.

145 {
146  // Be optimistic:-)
147  bool success = true;
148  gen_array_t a;
149 
150  pips_assert("some current workspace", db_get_current_workspace_name());
151 
152  // First parse the makefile to avoid writing an empty one.
153  (void) parse_makefile();
154 
155  // this function returns various stuff that need to be filtered!
156  a = db_get_module_list();
157 
158  if (gen_array_nitems(a)==1) {
159  string mn = gen_array_item(a, 0);
160  if (!compilation_unit_p(mn))
161  success = open_module(mn);
162  }
163  else if (gen_array_nitems(a)==2) {
164  // In C, you cannot have fewer than two modules
165  // because of compilation units
166  string mn1 = gen_array_item(a, 0), mn2 = gen_array_item(a, 1);
167  bool mod1 = !compilation_unit_p(mn1), mod2 = !compilation_unit_p(mn2);
168  if (mod1 ^ mod2)
169  success = open_module(mod1? mn1: mod2? mn2: NULL);
170  }
172 
173  return success;
174 }
void gen_array_full_free(gen_array_t a)
Definition: array.c:77
bool compilation_unit_p(const char *module_name)
The names of PIPS entities carry information about their nature.
Definition: entity_names.c:56
gen_array_t db_get_module_list(void)
Get an array of all the modules (functions, procedures and compilation units) of a workspace.
Definition: database.c:1266
makefile parse_makefile(void)

References compilation_unit_p(), db_get_current_workspace_name(), db_get_module_list(), gen_array_full_free(), gen_array_item(), gen_array_nitems(), open_module(), parse_makefile(), and pips_assert.

Referenced by create_workspace(), open_workspace(), and pips_main().

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

◆ open_workspace()

bool open_workspace ( const char *  name)

should be: success (cf wpips.h)

should be show_message

FI: what happens since log_file is not open?

Parameters
nameame

Definition at line 309 of file dbm.c.

310 {
311  bool success;
312 
314  pips_user_error("Some current workspace, close it first!\n");
315 
316  if (!workspace_exists_p(name))
317  pips_user_error("Workspace %s does not exist!\n", name);
318 
319  if (!workspace_ok_p(name))
320  pips_user_error("Workspace %s not readable!\n", name);
321 
322  if (make_open_workspace(name) == NULL) {
323  /* should be show_message */
324  /* FI: what happens since log_file is not open? */
325  user_log("Cannot open workspace %s.\n", name);
326  success = false;
327  }
328  else {
329  string dir = db_get_current_workspace_directory();
330 
331  (* pips_update_props_handler)();
332 
333  open_log_file(dir);
334  open_warning_file(dir);
335  free(dir);
338  user_log("Workspace %s opened.\n", name);
341  push_path();
342  }
343  return success;
344 }
string make_open_workspace(const char *name)
Definition: openclose.c:72
bool workspace_exists_p(const char *)
Definition: workspace.c:266
bool workspace_ok_p(const char *)
Definition: workspace.c:274

References db_get_current_workspace_directory(), db_get_current_workspace_name(), free(), init_processed_include_cache(), make_open_workspace(), open_log_file(), open_module_if_unique(), open_warning_file(), pips_user_error, push_path(), reset_static_entities(), set_entity_to_size(), user_log(), workspace_exists_p(), and workspace_ok_p().

Referenced by end_open_workspace_notify(), execute_workspace_creation_and_so_on_given_with_options(), and pips_main().

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

◆ pips_checks()

void pips_checks ( void  )

add checkings here (FI: why in help.c?) SG : PIPS_ROOT should not be required :)

Definition at line 100 of file help.c.

101 {
102  /*
103  if (!getenv("PIPS_ROOT")) {
104  (void) fprintf(stderr, "PIPS_ROOT environment variable not set. \n"
105  "Set it properly and relaunch.\n");
106  exit(1);
107  }
108  */
109 }

Referenced by gpips_main(), pips_main(), tpips_init(), and wpips_main().

+ Here is the caller graph for this function:

Variable Documentation

◆ pips_update_props_handler

void(* pips_update_props_handler) (void) ( void  )
externdefault

default assignment of pips_update_props_handler is default_update_props.

Some top-level (eg. wpips) may need a special update_props proceedure; they should let pips_update_props_handler point toward it.

Definition at line 53 of file dbm.c.

Referenced by gpips_main(), and wpips_main().