25 #include "pips_config.h"
52 #define INITIAL_STMTHEAP_BUFFER_SIZE 10
116 int MustStop =
false;
122 user_warning(
"CheckAndInitializeStmt",
"Undefined label \"%s\"\n",
128 ParserError(
"CheckAndInitializeStmt",
"Undefined label(s)\n");
147 pips_assert(
"The empty label is not associated to a statement",
226 ParserError(
"PushBlock",
"top of stack reached\n");
241 ParserError(
"PopBlock",
"bottom of stack reached\n");
261 static char *name = NULL ;
266 debug(5,
"MakeLabel",
"\"%s\"\n", s);
276 debug(5,
"MakeLabel",
"%s\n", name);
283 debug(5,
"MakeLabel",
"%s already exists\n", name);
295 debug(9,
"MakeNewLabelledStatement",
"begin for label \"%s\" and instruction %s\n",
331 debug(9,
"MakeNewLabelledStatement",
"end for label \"%s\"\n",
344 debug(9,
"ReuseLabelledStatement",
"begin for label \"%s\"\n",
349 pips_assert(
"The statement instruction should be undefined",
379 pips_assert(
"The first statement of the block is not a block",
397 pips_assert(
"The first statement of block s1 must be s\n",
414 debug(9,
"ReuseLabelledStatement",
"end for label \"%s\"\n",
437 debug(5,
"MakeStatement",
"Begin for label %s and instruction %s\n",
468 "DO loop reachable by GO TO via label %s "
469 "cannot be parallelized by PIPS\n",
500 user_warning(
"MakeStatement",
"Label %s may be used twice\n",
502 ParserError(
"MakeStatement",
"Same label used twice\n");
537 pips_debug(8,
"Begin for instruction %s with label \"%s\"\n",
544 ParserError(
"LinkInstToCurrentBlock",
"no current block\n");
612 user_log(
"Current comment of chosen statement: \"%s\"\n",
614 user_log(
"Block comment to be carried by first statement: \"%s\"\n",
646 pips_debug(8,
"End for instruction %s with label \"%s\"\n",
802 statement may_stop = (assigned && (cl==ll)) ?
894 " SUBSTITUTED\n", 0));
904 "bad lhs (function call or undeclared array)"
905 " or PIPS unsupported Fortran macro\n"
906 "you might consider switching the "
907 "PARSER_EXPAND_STATEMENT_FUNCTIONS property,\n"
908 "in the latter, at your own risk...\n");
914 user_warning(
"MakeAssignInst",
"PARAMETER %s appears as lhs\n",
920 FatalError(
"MakeAssignInst",
"Unexpected syntax tag\n");
946 "Formal functional parameters are not yet supported\n");
956 pips_assert(
"result type is variable or unkown or void or undefined",
986 for (pc = l; pc != NULL; pc =
CDR(pc)) {
997 "Functional arguments are not yet suported by PIPS\n",
1020 bool warning_p =
false;
1037 "Functional arguments are not yet suported by PIPS\n",
1058 user_warning(
"update_functional_type_with_actual_arguments",
1059 "incompatible %d%s actual argument and type in call to %s "
1060 "between lines %d and %d. Current type is not updated\n",
1075 user_warning(
"update_functional_type_with_actual_arguments",
1076 "inconsistent arg. list lengths for %s:\n"
1077 " %d args according to type and %d actual arguments\n"
1078 "between lines %d and %d. Current type is not updated\n",
1177 FatalError(
"MakeDoInst",
"function call as DO variable\n");
1180 FatalError(
"MakeDoInst",
"variable reference as DO variable\n");
1187 dolab =
MakeLabel((strcmp(l,
"BLOCKDO") == 0) ?
"" : l);
1273 pips_user_warning(
"WHILE condition between lines %d and %d is not a logical expression.\n",
1280 dolab =
MakeLabel((strcmp(l,
"BLOCKDO") == 0) ?
"" : l);
1303 pips_user_warning(
"IF condition between lines %d and %d is not a logical expression.\n",
1307 ParserError(
"MakeBlockIfInst",
"IF condition is neither logical nor integer.\n");
1341 FatalError(
"MakeLogicalIfInst",
"bad instruction\n");
1415 if(strcmp(l1,l2)==0) {
1416 if(strcmp(l2,l3)==0) {
1444 else if(strcmp(l1,l3)==0) {
1454 else if(strcmp(l2,l3)==0) {
1531 ParserError(
"MakeElseInst",
"unexpected ELSE statement\n");
1537 ParserError(
"MakeElseInst",
"block if statement badly nested\n");
1539 if (has_comments_p) {
1562 FatalError(
"MakeElseInst",
"no block if statement\n");
1583 ParserError(
"MakeEndifInst",
"unexpected ENDIF statement\n");
1598 ParserError(
"MakeEndifInst",
"block if statement badly nested\n");
1607 }
while( elsifs-- != 0 ) ;
1614 ParserError(
"MakeEnddoInst",
"Unexpected ENDDO statement\n");
1619 ParserError(
"MakeEnddoInst",
"block do statement badly nested\n");
1676 FatalError(
"NameOfToken",
"unknown token\n");
1727 for (l = lci; l != NULL; l =
CDR(
CDR(l))) {
1745 for (l = lci; l != NULL; l =
CDR(
CDR(l))) {
1755 pips_assert(
"constant is not int (thus litteral or call)",
1881 "Illegal syntax in IO statement, "
1882 "Parentheses and arguments required");
1893 ParserError(
"Syntax",
"Unexpected token in IO statement");
1920 "Illegal syntax in IO statement, Parentheses are required");
1923 ParserError(
"Syntax",
"Unexpected token in IO statement");
1957 debug(8,
"set_first_format_statement",
"line_b_C=%d, line_b_I=%d\n",
1980 "Declaration appears after executable statement");
1986 "analyze this code, "
1987 "please set property PRETTYPRINT_ALL_DECLARATIONS "
1988 "or move this FORMAT down in executable code.\n");
1989 ParserError(
"Syntax",
"Source cannot be parsed with current properties");
2006 int line_start =
true;
2007 int in_comment =
false;
2008 int out_of_constant_string =
true;
2009 int in_constant_string =
false;
2010 int end_of_constant_string =
false;
2011 char string_sep =
'\000';
2016 int cpt = 0, ibuffer = 0, c;
2031 debug(8,
"check_first_statement",
"line_b_C=%d, line_b_I=%d\n",
2037 while ((c = getc(fd)) != EOF) {
2038 if(line_start ==
true)
2046 if(out_of_constant_string) {
2047 if(c==
'\'' || c ==
'"') {
2049 out_of_constant_string =
false;
2050 in_constant_string =
true;
2054 buffer[ibuffer++] = toupper(c);
2058 if(in_constant_string) {
2060 in_constant_string =
false;
2061 end_of_constant_string =
true;
2066 if(end_of_constant_string) {
2068 in_constant_string =
true;
2069 end_of_constant_string =
false;
2073 out_of_constant_string =
true;
2074 end_of_constant_string =
false;
2075 buffer[ibuffer++] = toupper(c);
2101 buffer[ibuffer++] =
'\0';
void user_log(const char *format,...)
bool instruction_consistent_p(instruction p)
execution make_execution(enum execution_utype tag, void *val)
evaluation make_evaluation_before(void)
call make_call(entity a1, list a2)
parameter make_parameter(type a1, mode a2, dummy a3)
expression make_expression(syntax a1, normalized a2)
whileloop make_whileloop(expression a1, statement a2, entity a3, evaluation a4)
loop make_loop(entity a1, range a2, statement a3, entity a4, execution a5, list a6)
basic make_basic(enum basic_utype tag, void *val)
storage make_storage_rom(void)
type copy_type(type p)
TYPE.
expression copy_expression(expression p)
EXPRESSION.
value make_value(enum value_utype tag, void *val)
reference make_reference(entity a1, list a2)
bool statement_consistent_p(statement p)
test make_test(expression a1, statement a2, statement a3)
statement make_statement(entity a1, intptr_t a2, intptr_t a3, string a4, instruction a5, list a6, string a7, extensions a8, synchronization a9)
variable make_variable(basic a1, list a2, list a3)
void free_expression(expression p)
instruction make_instruction(enum instruction_utype tag, void *val)
constant make_constant_litteral(void)
void free_syntax(syntax p)
dummy make_dummy_unknown(void)
synchronization make_synchronization_none(void)
sequence make_sequence(list a)
type make_type(enum type_utype tag, void *val)
stack BlockStack
Attention, the null statement in C is represented as the continue statement in Fortran (make_continue...
expression MakeCharacterConstantExpression(string s)
END_EOLE.
void DeclareVariable(entity e, type t, list d, storage s, value v)
void DeclareVariable(e, t, d, s, v): update entity e description as declaration statements are encoun...
string make_entity_fullname(const char *module_name, const char *local_name)
END_EOLE.
FILE * safe_fopen(const char *filename, const char *what)
int safe_fclose(FILE *stream, const char *filename)
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define call_constant_p(C)
statement make_block_statement(list body)
Make a block statement from a list of statement.
statement instruction_to_statement(instruction instr)
Build a statement from a give instruction.
statement make_empty_block_statement()
Build an empty statement (block/sequence)
entity get_current_module_entity(void)
Get the entity of the current module.
instruction make_instruction_block(list statements)
Build an instruction block from a list of statements.
instruction make_continue_instruction()
Creates a CONTINUE instruction, that is the FORTRAN nop, the ";" in C or the "pass" in Python for exa...
instruction make_assign_instruction(expression l, expression r)
#define ENDP(l)
Test if a list is empty.
#define POP(l)
Modify a list pointer to point on the next element of the list.
#define NIL
The empty list (nil in Lisp)
size_t gen_length(const list l)
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
#define CAR(pcons)
Get the value of the first element of a list.
#define CDR(pcons)
Get the list less its first element.
list gen_append(list l1, const list l2)
#define list_undefined
Undefined list definition :-)
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
bool statement_loop_p(statement s)
statement make_assign_statement(expression l, expression r)
bool stop_statement_p(statement s)
Test if a statement is a Fortran STOP.
bool continue_statement_p(statement s)
Test if a statement is a CONTINUE, that is the FORTRAN nop, the ";" in C or the "pass" in Python....
instruction make_simple_Fortran_io_instruction(bool is_read_p, expression f, list io_list)
Derived from the Fortran parser code.
statement make_continue_statement(entity l)
string instruction_identification(instruction i)
Return a constant string representing symbolically the instruction type.
static expression s_init
must take care not to substitute in an inserted expression
void parser_add_a_macro(call c, expression e)
#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
#define user_warning(fn,...)
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
#define LIST_DIRECTED_FORMAT_NAME
#define TOP_LEVEL_MODULE_NAME
Module containing the global variables in Fortran and C.
#define STATEMENT_ORDERING_UNDEFINED
mapping.h inclusion
string concatenate(const char *,...)
Return the concatenation of the given strings.
void * gen_find_tabulated(const char *, int)
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
entity MakeExternalFunction(entity e, type r)
void update_called_modules(entity e)
int get_statement_number()
eturn the line number of the statement being parsed
#define instruction_block_p(i)
#define IO_EFFECTS_PACKAGE_NAME
Implicit variables to handle IO effetcs.
#define SUBSTRING_FUNCTION_NAME
#define EQUAL_OPERATOR_NAME
#define NORMALIZE_EXPRESSION(e)
#define statement_block_p(stat)
#define STATEMENT_NUMBER_UNDEFINED
default values
#define IO_EOF_ARRAY_NAME
array of end of file codes
#define IO_ERROR_ARRAY_NAME
array of error codes for LUNs
#define STOP_FUNCTION_NAME
#define LABEL_SIZE
constant sizes
#define instruction_block(i)
#define empty_comments
Empty comments (i.e.
#define ASSIGN_SUBSTRING_FUNCTION_NAME
#define NON_EQUAL_OPERATOR_NAME
#define make_empty_statement
An alias for make_empty_block_statement.
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
entity FindEntity(const char *package, const char *name)
Retrieve an entity from its package/module name and its local name.
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
entity FindOrCreateEntity(const char *package, const char *local_name)
Problem: A functional global entity may be referenced without parenthesis or CALL keyword in a functi...
entity entity_empty_label(void)
const char * module_local_name(entity e)
Returns the module local user name.
bool entity_empty_label_p(entity e)
code EntityCode(entity e)
this function checks that e has an initial value code.
entity CreateIntrinsic(string name)
this function does not create an intrinsic function because they must all be created beforehand by th...
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
const char * label_local_name(entity e)
END_EOLE.
expression reference_to_expression(reference r)
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
expression MakeBinaryCall(entity f, expression eg, expression ed)
Creates a call expression to a function with 2 arguments.
expression int_to_expression(_int i)
transform an int into an expression and generate the corresponding entity if necessary; it is not cle...
bool logical_expression_p(expression e)
bool integer_expression_p(expression e)
expression MakeNullaryCall(entity f)
Creates a call expression to a function with zero arguments.
expression MakeUnaryCall(entity f, expression a)
Creates a call expression to a function with one argument.
bool expression_reference_p(expression e)
Test if an expression is a reference.
reference expression_reference(expression e)
Short cut, meaningful only if expression_reference_p(e) holds.
extensions empty_extensions(void)
extension.c
basic basic_of_expression(expression)
basic basic_of_expression(expression exp): Makes a basic of the same basic as the expression "exp".
mode MakeModeReference(void)
bool type_equal_p(type, type)
type MakeTypeStatement(void)
entity make_new_scalar_variable_with_prefix(const char *, entity, basic)
Create a new scalar variable of type b in the given module.
#define type_functional_p(x)
#define normalized_undefined
#define syntax_reference_p(x)
#define functional_result(x)
#define storage_formal_p(x)
#define parameter_type(x)
#define value_constant(x)
#define syntax_reference(x)
#define type_unknown_p(x)
#define normalized_linear_p(x)
#define instruction_loop_p(x)
#define reference_variable(x)
#define statement_ordering(x)
#define type_functional(x)
#define parameter_undefined
#define entity_storage(x)
#define type_statement_p(x)
#define instruction_undefined_p(x)
#define range_increment(x)
#define value_constant_p(x)
#define basic_overloaded_p(x)
#define EXPRESSION(x)
EXPRESSION.
#define instruction_undefined
#define statement_label(x)
#define type_undefined_p(x)
#define constant_int_p(x)
#define expression_undefined
@ is_instruction_whileloop
@ is_instruction_sequence
#define value_symbolic_p(x)
#define functional_parameters(x)
#define PARAMETER(x)
PARAMETER.
#define reference_indices(x)
#define expression_undefined_p(x)
#define type_varargs_p(x)
#define code_decls_text(x)
#define statement_instruction(x)
#define constant_litteral_p(x)
#define statement_comments(x)
@ is_execution_sequential
#define instruction_test_p(x)
#define call_arguments(x)
#define instruction_test(x)
#define statement_undefined_p(x)
#define statement_number(x)
#define instruction_goto_p(x)
#define expression_syntax(x)
#define type_variable_p(x)
#define storage_undefined_p(x)
#define functional_undefined
#define entity_domain
newgen_syntax_domain_defined
#define variable_basic(x)
#define statement_undefined
#define STATEMENT(x)
STATEMENT.
#define storage_undefined
#define entity_initial(x)
static size_t buffer_size
string l
the instruction that contains this block
cons * c
the expected statement which will end this block
int elsifs
the list of statements contained in this block
The structure used to build lists in NewGen.
statement s
the name of the label
#define START_COMMENT_LINE
Legal characters to start a comment line.
void set_current_label_string(string ln)
char * CurrentFN
Pre-parser for Fortran syntax idiosyncrasy.
int line_b_I
Indicates where the current instruction (in fact statement) starts and ends in the input file and giv...
string get_current_label_string()
bool empty_current_label_string_p()
bool ParserError(const char *f, const char *m)
void reset_current_label_string()
const char * CurrentPackage
the name of the current package, i.e.
bool SubstituteAlternateReturnsP()
list add_actual_return_code(list apl)
instruction generate_return_code_checks(list labels)
list get_alternate_returns()
void check_first_statement()
This function is called each time an executable statement is encountered but is effective the first t...
statement ReuseLabelledStatement(statement s, instruction i)
void update_functional_type_with_actual_arguments(entity e, list l)
statement MakeStatement(entity l, instruction i)
This function makes a statement.
void PushBlock(instruction i, string l)
statement make_check_io_statement(string n, expression u, entity l)
Generate a test to jump to l if flag f is TRUE Used to implement control effects of IO's due to ERR= ...
void set_first_format_statement()
void check_in_declarations()
instruction MakeZeroOrOneArgCallInst(char *s, expression e)
this function creates a simple Fortran statement such as RETURN, CONTINUE, ...
entity MakeLabel(char *s) const
This functions creates a label.
instruction MakeAssignedOrComputedGotoInst(list ll, expression ce, bool assigned)
#define INITIAL_STMTHEAP_BUFFER_SIZE
the purpose of the following data structure is to associate labels to instructions.
instruction MakeArithmIfInst(expression e, string l1, string l2, string l3)
this function transforms an arithmetic if statement into a set of regular tests.
instruction MakeEmptyInstructionBlock()
this function creates an empty block
static void init_StmtHeap_buffer(void)
static int StmtHeap_buffer_size
bool first_format_statement_seen()
instruction MakeCallInst(entity e, cons *l)
this function creates a call statement.
expression fix_if_condition(expression e)
void update_functional_type_result(entity f, type nt)
Update of the type returned by function f.
void CheckAndInitializeStmt(void)
this function looks for undefined labels.
void MakeDoInst(syntax s, range r, string l)
this function creates a do loop statement.
instruction MakeComputedGotoInst(list ll, expression e)
void parser_reset_StmtHeap_buffer(void)
statement.c
instruction MakeGotoInst(string n)
this function creates a goto instruction.
instruction MakeIoInstB(int keyword, expression e1, expression e2, expression e3, expression e4)
this function creates a BUFFER IN or BUFFER OUT io statement.
static void resize_StmtHeap_buffer(void)
statement LabelToStmt(string l)
this functions looks up in table StmtHeap for the statement s whose label is l.
bool first_executable_statement_seen()
instruction MakeSimpleIoInst2(int keyword, expression f, list io_list)
void MakeBlockIfInst(expression e, int elsif)
this function and the two next ones create a block if statement.
string NameOfToken(int token)
instruction MakeAssignedGotoInst(list ll, entity i)
#define MAXBLOCK
The purpose of the following data structure is to build the control structure of the procedure being ...
void LinkInstToCurrentBlock(instruction i, bool number_it)
this function links the instruction i to the current block of statements.
instruction MakeLogicalIfInst(expression e, instruction i)
this function creates a logical if statement.
void MakeWhileDoInst(expression c, string l)
This function creates a while do loop statement.
instruction MakeIoInstA(int keyword, list lci, list lio)
this function creates an IO statement.
static int seen
Are we in the declaration or in the executable part? Have we seen a FORMAT statement before an execut...
void reset_first_statement()
#define UNDEF
Well, some constant defined in reader.c and not deserving a promotion in syntax-local....
statement MakeNewLabelledStatement(entity l, instruction i)
void NewStmt(entity e, statement s)
this function stores a new association in table StmtHeap: the label of statement s is e.
instruction make_goto_instruction(entity l)
In a "go to" instruction, the label does not appear explictly.
static stmt * StmtHeap_buffer
instruction MakeAssignInst(syntax l, expression e)
this function creates an affectation statement.
instruction MakeSimpleIoInst1(int keyword, expression unit)
static int declaration_lines
int MakeElseInst(bool is_else_p)
This function is used to handle either an ELSE or an ELSEIF construct.