PIPS
parser.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "ri-util.h"
#include "parser_private.h"
#include "syntax.h"
#include "resources.h"
#include "database.h"
#include "misc.h"
#include "pipsdbm.h"
+ Include dependency graph for parser.c:

Go to the source code of this file.

Functions

void reset_current_label_string ()
 
string get_current_label_string ()
 
void set_current_label_string (string ln)
 
bool empty_current_label_string_p ()
 
static void reset_parser_recursive_call ()
 Safety for recursive calls of parser required to process entries. More...
 
static void set_parser_recursive_call ()
 
bool ParserError (const char *f, const char *m)
 
void BeginingOfParsing ()
 this function is called for each new file (FI: once?) FI: I do not understand how this works. More...
 
static bool the_actual_parser (string module, string dbr_file)
 parse "module.dbr_file" More...
 
bool hpfc_parser (const string module)
 parser for HPFC. More...
 
bool parser (const string module)
 
void init_parser_properties (void)
 

Variables

char * CurrentFN = NULL
 Pre-parser for Fortran syntax idiosyncrasy. More...
 
consFormalParameters = NIL
 the current function More...
 
const char * CurrentPackage = NULL
 the name of the current package, i.e. More...
 
int line_b_I
 Indicates where the current instruction (in fact statement) starts and ends in the input file and gives its label. More...
 
int line_e_I
 
int line_b_C
 
int line_e_C
 
char lab_I [6]
 
char FormatValue [FORMATLENGTH]
 a string that will contain the value of the format in case of format statement More...
 
static bool parser_recursive_call = false
 
bool InParserError = false
 Parser error handling. More...
 

Function Documentation

◆ BeginingOfParsing()

void BeginingOfParsing ( void  )

this function is called for each new file (FI: once?) FI: I do not understand how this works.

It has an effect only once during a pips process lifetime. The error handling routine resets CurrentPackage to NULL, as it is when the pips process is started.

Should I:

A modify the error handling routine to reset CurrentPackage to TOP_LEVEL_MODULE_NAME?

B reset CurrentPackage to TOP_LEVEL_MODULE_NAME each time the parser is entered?

I choose A.

the current package is initialized

Definition at line 208 of file parser.c.

209 {
210  static bool called = false;
211 
212  if (called)
213  return;
214 
215  /* the current package is initialized */
217  called = true;
218 }
#define TOP_LEVEL_MODULE_NAME
Module containing the global variables in Fortran and C.
Definition: naming-local.h:101
const char * CurrentPackage
the name of the current package, i.e.
Definition: parser.c:58

References CurrentPackage, and TOP_LEVEL_MODULE_NAME.

Referenced by the_actual_parser().

+ Here is the caller graph for this function:

◆ empty_current_label_string_p()

bool empty_current_label_string_p ( void  )

Definition at line 87 of file parser.c.

88 {
89  bool empty_p = same_string_p(lab_I, "");
90 
91  return empty_p;
92 }
#define same_string_p(s1, s2)
char lab_I[6]
Definition: parser.c:69

References lab_I, and same_string_p.

Referenced by MakeElseInst().

+ Here is the caller graph for this function:

◆ get_current_label_string()

string get_current_label_string ( void  )

Definition at line 76 of file parser.c.

77 {
78  return lab_I;
79 }

References lab_I.

Referenced by MakeElseInst().

+ Here is the caller graph for this function:

◆ hpfc_parser()

bool hpfc_parser ( const string  module)

parser for HPFC.

just a different input file not to touch the original source file. this parser should be selected/activated automatically.

Parameters
moduleodule

Definition at line 286 of file parser.c.

287 {
288  return the_actual_parser(module, DBR_HPFC_FILTERED_FILE);
289 }
static char * module
Definition: pips.c:74
static bool the_actual_parser(string module, string dbr_file)
parse "module.dbr_file"
Definition: parser.c:223

References module, and the_actual_parser().

+ Here is the call graph for this function:

◆ init_parser_properties()

void init_parser_properties ( void  )

Definition at line 296 of file parser.c.

297 {
299 }
void init_parser_reader_properties()
Definition: reader.c:434

References init_parser_reader_properties().

Referenced by the_actual_parser().

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

◆ parser()

bool parser ( const string  module)
Parameters
moduleodule

Definition at line 291 of file parser.c.

292 {
293  return the_actual_parser(module, DBR_SOURCE_FILE);
294 }

References module, and the_actual_parser().

+ Here is the call graph for this function:

◆ ParserError()

bool ParserError ( const char *  f,
const char *  m 
)

Maybe a routine called by ParserError() may call ParserError() e.g. AbortOfProcedure() thru remove_ghost_variables()

Get rid of partly declared variables...

Callers may already have pointers towards this function. The prettyprinter core dumps if entity_initial is destroyed. Maybe, I should clean the declarations field in code, as well as decls_text.

The error may occur before the current module entity is defined

GetChar() will reinitialize its own buffer when called

Because of the strange behavior of BeginingOfParsing

CurrentPackage = NULL;

Too bad for memory leak...

FI: let catch_error() take care of this in pipsmake since debug_on() was not activated in ParserError

debug_off();

Should never be executed

Definition at line 116 of file parser.c.

117 {
119 
120  /* Maybe a routine called by ParserError() may call ParserError()
121  * e.g. AbortOfProcedure() thru remove_ghost_variables()
122  */
123  if(InParserError)
124  return false;
125 
126  InParserError = true;
127 
128  uses_alternate_return(false);
131 
132  syn_reset_lex();
133 
134  ResetBlockStack();
135 
136  /* Get rid of partly declared variables... */
137  if(mod!=entity_undefined) {
138  /* Callers may already have pointers towards this function.
139  * The prettyprinter core dumps if entity_initial is
140  * destroyed. Maybe, I should clean the declarations field
141  * in code, as well as decls_text.
142  */
143  /*
144  entity_type(mod) = type_undefined;
145  entity_storage(mod) = storage_undefined;
146  entity_initial(mod) = value_undefined;
147  */
148  value v = entity_initial(mod);
149  code c = value_code(v);
150  code_declarations(c) = NIL;
152 
153  CleanLocalEntities(mod);
154  }
155 
156  /* The error may occur before the current module entity is defined */
159  free(CurrentFN);
160  CurrentFN = NULL;
161 
162  /* GetChar() will reinitialize its own buffer when called */
163 
164  /* Because of the strange behavior of BeginingOfParsing*/
165  /* CurrentPackage = NULL; */
167  /* Too bad for memory leak... */
176  ResetChains();
177  AbortEntries();
179 
180  InParserError = false;
181 
182  /* FI: let catch_error() take care of this in pipsmake since debug_on()
183  was not activated in ParserError */
184  /* debug_off(); */
185  user_error(f,"Parser error between lines %d and %d\n%s\n",
186  line_b_I,line_e_I,m);
187 
188  /* Should never be executed */
189  return true;
190 }
entity DynamicArea
These global variables are declared in ri-util/util.c.
Definition: area.c:57
entity HeapArea
Definition: area.c:59
entity StaticArea
Definition: area.c:58
void CleanLocalEntities(entity function)
Fortran version.
Definition: clean.c:140
void reset_common_size_map_on_error()
Definition: declaration.c:972
void ResetChains()
undefine chains between two successives calls to parser
Definition: equivalence.c:65
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
void free(void *)
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define user_error(fn,...)
Definition: misc-local.h:265
#define string_undefined
Definition: newgen_types.h:40
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
void AbortEntries()
Definition: procedure.c:1473
void AbortOfProcedure()
Definition: procedure.c:386
void parser_reset_all_reader_buffers(void)
Definition: reader.c:313
void error_reset_current_module_entity(void)
To be called by an error management routine only.
Definition: static.c:109
#define code_declarations(x)
Definition: ri.h:784
#define entity_undefined
Definition: ri.h:2761
#define value_code(x)
Definition: ri.h:3067
#define code_decls_text(x)
Definition: ri.h:786
#define entity_initial(x)
Definition: ri.h:2796
FILE * syn_in
lex yacc interface
Definition: syntax.h:325
void syn_reset_lex()
char * CurrentFN
Pre-parser for Fortran syntax idiosyncrasy.
Definition: parser.c:49
static void reset_parser_recursive_call()
Safety for recursive calls of parser required to process entries.
Definition: parser.c:101
bool InParserError
Parser error handling.
Definition: parser.c:113
int line_e_I
Definition: parser.c:68
int line_b_I
Indicates where the current instruction (in fact statement) starts and ends in the input file and giv...
Definition: parser.c:68
void soft_reset_alternate_returns()
ParserError() cannot guess if it has been performed or not, because it is reinitialized before and af...
Definition: return.c:284
void SubstituteAlternateReturns(const char *option)
return.c
Definition: return.c:59
void uses_alternate_return(bool use)
Definition: return.c:171
void ResetReturnCodeVariable()
Definition: return.c:151
void ResetBlockStack()
Definition: statement.c:203
void parser_reset_StmtHeap_buffer(void)
statement.c
Definition: statement.c:85

References AbortEntries(), AbortOfProcedure(), CleanLocalEntities(), code_declarations, code_decls_text, CurrentFN, CurrentPackage, DynamicArea, entity_initial, entity_undefined, error_reset_current_module_entity(), f(), free(), get_current_module_entity(), HeapArea, InParserError, line_b_I, line_e_I, NIL, parser_reset_all_reader_buffers(), parser_reset_StmtHeap_buffer(), reset_common_size_map_on_error(), reset_parser_recursive_call(), ResetBlockStack(), ResetChains(), ResetReturnCodeVariable(), safe_fclose(), soft_reset_alternate_returns(), StaticArea, string_undefined, SubstituteAlternateReturns(), syn_in, syn_reset_lex(), TOP_LEVEL_MODULE_NAME, user_error, uses_alternate_return(), and value_code.

Referenced by AddVariableToCommon(), AnalyzeData(), CapitalizeStmt(), check_in_declarations(), CheckAndInitializeStmt(), CheckParenthesis(), ComputeAddresses(), DeclareExternalFunction(), DeclarePointer(), DeclareVariable(), EndOfProcedure(), EvalCall(), EvalSyntax(), expression_reference_number(), find_target_position(), fix_if_condition(), fix_storage(), FortranExpressionList(), IsCapKeyword(), LinkInstToCurrentBlock(), make_Fortran_constant_entity(), MakeAssignInst(), MakeAtom(), MakeCurrentFunction(), MakeDataValueSet(), MakeElseInst(), MakeEnddoInst(), MakeEndifInst(), MakeEntryCommon(), MakeEquivAtom(), MakeFormalParameter(), MakeFortranBinaryCall(), MakeFortranType(), MakeFortranUnaryCall(), MakeParameter(), MakeSimpleIoInst1(), MakeSimpleIoInst2(), MakeStatement(), MakeVariableStatic(), NeedKeyword(), NewStmt(), parser_add_a_macro(), PopBlock(), process_static_initialization(), process_value_list(), PushBlock(), ReadLine(), ReadStmt(), remove_ghost_variable_entities(), reset_common_size_map(), SafeSizeOfArray(), SaveChains(), SaveEntity(), store_initial_value(), SubstituteAlternateReturns(), TypeFunctionalEntity(), update_called_modules(), update_functional_type_result(), uses_alternate_return(), and ValueOfIthLowerBound().

+ Here is the call graph for this function:

◆ reset_current_label_string()

void reset_current_label_string ( void  )

Definition at line 71 of file parser.c.

72 {
73  strcpy(lab_I, "");
74 }

References lab_I.

Referenced by LinkInstToCurrentBlock(), and MakeElseInst().

+ Here is the caller graph for this function:

◆ reset_parser_recursive_call()

static void reset_parser_recursive_call ( )
static

Safety for recursive calls of parser required to process entries.

Definition at line 101 of file parser.c.

102 {
103  parser_recursive_call = false;
104 }
static bool parser_recursive_call
Definition: parser.c:98

References parser_recursive_call.

Referenced by ParserError(), and the_actual_parser().

+ Here is the caller graph for this function:

◆ set_current_label_string()

void set_current_label_string ( string  ln)
Parameters
lnn

Definition at line 81 of file parser.c.

82 {
83  pips_assert("Label name is at most 5 characters long", strlen(ln)<=5);
84  strcpy(lab_I, ln);
85 }
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172

References lab_I, and pips_assert.

Referenced by MakeElseInst().

+ Here is the caller graph for this function:

◆ set_parser_recursive_call()

static void set_parser_recursive_call ( )
static

Definition at line 106 of file parser.c.

107 {
108  parser_recursive_call = false;
109 }

References parser_recursive_call.

Referenced by the_actual_parser().

+ Here is the caller graph for this function:

◆ the_actual_parser()

static bool the_actual_parser ( string  module,
string  dbr_file 
)
static

parse "module.dbr_file"

set up parser properties

parser is initialized

scanner is initialized

yacc parser is called

Handle the special case for entries without looping forever

The requested parsed code may have been an entry code. Then it is not yet computed because the parsed code for the module was produced and only a file resource was produced for the entry code.

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.

Definition at line 223 of file parser.c.

225 {
226  string dir;
227  debug_on("SYNTAX_DEBUG_LEVEL");
228 
229  /* set up parser properties */
232 
233  /* parser is initialized */
235 
236  /* scanner is initialized */
237  ScanNewFile();
238 
239  pips_assert("CurrentFN is NULL", CurrentFN==NULL);
241  CurrentFN =
242  strdup(concatenate(dir, "/",
243  db_get_file_resource(dbr_file, module, true), 0));
244  free(dir);
245 
246  /* yacc parser is called */
247  syn_in = safe_fopen(CurrentFN, "r");
248  syn_parse();
250  free(CurrentFN);
251  CurrentFN = NULL;
252 
253  /* Handle the special case for entries without looping forever */
254  if(!parser_recursive_call) {
255  if(!EmptyEntryListsP()) {
256  /* The requested parsed code may have been an entry code. Then it
257  * is not yet computed because the parsed code for the module was
258  * produced and only a file resource was produced for the entry code.
259  */
260  ResetEntries();
261  if(!db_resource_p(DBR_PARSED_CODE, module)) {
263  the_actual_parser(module, dbr_file);
265  }
266  }
267  }
268  else {
269  if(!EmptyEntryListsP()) {
270  pips_internal_error("Unexpected entry handling in parser recursive call");
271  }
272  }
273 
274  /* This debug_off() occurs too late since pipsdbm has been called
275  * before. Initially, the parser was designed to parse more than
276  * one subroutine/function/program at a time. */
277  debug_off();
278 
279  return true;
280 }
bool db_resource_p(const char *rname, const char *oname)
true if exists and in loaded or stored state.
Definition: database.c:524
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
void parser_init_macros_support(void)
next available chunk
Definition: macros.c:57
#define debug_on(env)
Definition: misc-local.h:157
#define pips_internal_error
Definition: misc-local.h:149
#define debug_off()
Definition: misc-local.h:160
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
#define db_get_file_resource
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
void ResetEntries()
Definition: procedure.c:1458
bool EmptyEntryListsP()
Definition: procedure.c:1506
void ScanNewFile(void)
La fonction a appeler pour l'analyse d'un nouveau fichier.
Definition: reader.c:474
char * strdup()
int syn_parse(void)
static void set_parser_recursive_call()
Definition: parser.c:106
void BeginingOfParsing()
this function is called for each new file (FI: once?) FI: I do not understand how this works.
Definition: parser.c:208
void init_parser_properties(void)
Definition: parser.c:296

References BeginingOfParsing(), concatenate(), CurrentFN, db_get_current_workspace_directory(), db_get_file_resource, db_resource_p(), debug_off, debug_on, EmptyEntryListsP(), free(), init_parser_properties(), module, parser_init_macros_support(), parser_recursive_call, pips_assert, pips_internal_error, reset_parser_recursive_call(), ResetEntries(), safe_fclose(), safe_fopen(), ScanNewFile(), set_parser_recursive_call(), strdup(), syn_in, and syn_parse().

Referenced by hpfc_parser(), and parser().

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

Variable Documentation

◆ CurrentFN

char* CurrentFN = NULL

Pre-parser for Fortran syntax idiosyncrasy.

parser.c

name of the current file

Definition at line 49 of file parser.c.

Referenced by check_first_statement(), dump_current_statement(), ParserError(), and the_actual_parser().

◆ CurrentPackage

const char* CurrentPackage = NULL

the name of the current package, i.e.

TOP-LEVEL or a module name?

Definition at line 58 of file parser.c.

Referenced by BeginingOfParsing(), EndOfProcedure(), get_use_entities_list(), gfc2pips_add_to_callees(), InitAreas(), MakeCurrentFunction(), MakeLabel(), NameToFunctionalEntity(), ParserError(), and update_common_sizes().

◆ FormalParameters

cons* FormalParameters = NIL

the current function

entity CurrentFunction; list of formal parameters of the current function

Definition at line 55 of file parser.c.

Referenced by EndOfProcedure(), and ScanFormalParameters().

◆ FormatValue

char FormatValue[FORMATLENGTH]

a string that will contain the value of the format in case of format statement

Definition at line 95 of file parser.c.

◆ InParserError

bool InParserError = false

Parser error handling.

Definition at line 113 of file parser.c.

Referenced by ParserError().

◆ lab_I

◆ line_b_C

int line_b_C

Definition at line 68 of file parser.c.

Referenced by check_first_statement(), and set_first_format_statement().

◆ line_b_I

int line_b_I

Indicates where the current instruction (in fact statement) starts and ends in the input file and gives its label.

Temporary versions of these variables are used because of the pipeline existing between the reader and the actual parser. The names of the temporary variables are prefixed with "tmp_". The default and reset values of these variables and their temporary versions (declared in reader.c) must be consistent.

Definition at line 68 of file parser.c.

Referenced by add_alternate_return(), AddVariableToCommon(), check_first_statement(), DeclarePointer(), DeclareVariable(), dump_current_statement(), fix_if_condition(), implied_do_reference_number(), MakeReturn(), MakeWhileDoInst(), ParserError(), ReadStmt(), set_first_format_statement(), update_functional_type_with_actual_arguments(), and uses_alternate_return().

◆ line_e_C

int line_e_C

Definition at line 68 of file parser.c.

◆ line_e_I

◆ parser_recursive_call

bool parser_recursive_call = false
static