PIPS
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "genC.h"
#include "parser_private.h"
#include "linear.h"
#include "ri.h"
#include "misc.h"
#include "ri-util.h"
#include "syntax.h"
#include "keywtbl.h"
#include "properties.h"
Go to the source code of this file.
Data Structures | |
struct | Skeyword |
Macros | |
#define | IS_QUOTED(c) (c>=256) |
#define | QUOTE(c) (c+256) |
#define | UNQUOTE(c) (IS_QUOTED(c) ? (c)-256 : (c)) |
#define | LOCAL static |
#define | UNDEF -2 |
#define | FIRST_LINE 100 |
#define | CONTINUATION_LINE 101 |
#define | EOF_LINE 102 |
#define | INITIAL_BUFFER_SIZE (128) |
Comm contains the comments for the current statement in ReadStmt(). More... | |
#define | SIZE_UNDEF ((size_t) UNDEF) |
#define | NONINQUOTES 1 |
#define | INQUOTES 2 |
#define | INQUOTEQUOTE 3 |
#define | INQUOTEBACKSLASH 4 |
Functions | |
static void | init_comment_buffers (void) |
lazy initialization of the comment buffer More... | |
static void | resize_comment_buffers (void) |
static void | init_getchar_buffer (void) |
number of elements in the array More... | |
static void | resize_getchar_buffer (void) |
static void | init_stmt_buffer (void) |
static void | resize_stmt_buffer (void) |
static void | init_line_buffer (void) |
static void | resize_line_buffer (void) |
void | append_data_current_stmt_buffer_to_declarations (void) |
void | parser_reset_all_reader_buffers (void) |
void | init_parser_reader_properties () |
void | CheckParenthesis () |
void | FindIf () |
void | FindAutre () |
void | FindPoints () |
int | syn_wrap (void) |
void | ScanNewFile (void) |
La fonction a appeler pour l'analyse d'un nouveau fichier. More... | |
int | IsCapKeyword (char *s) |
Fonction appelee par sslex sur la reduction de la regle de reconnaissance des mot clefs. More... | |
int | PipsGetc (FILE *fp) |
Routine de lecture pour l'analyseur lexical, lex ou flex. More... | |
int | GetChar (FILE *fp) |
Routine de lecture physique. More... | |
int | ReadLine (FILE *fp) |
All physical lines of a statement are put together in a unique buffer called "line_buffer". More... | |
int | ReadStmt (FILE *fp) |
regroupement des lignes du statement en une unique ligne sans continuation More... | |
int | FindDoWhile (void) |
This function is redundant with FindDo() but much easier to understand. More... | |
int | FindDo (void) |
int | FindImplicit (void) |
int | FindIfArith (void) |
int | FindAssign (void) |
size_t | FindProfZero (int c) |
size_t | FindMatchingPar (size_t i) |
int | StmtEqualString (char *s, int i) |
int | CapitalizeStmt (char s[], int i) |
int | NeedKeyword (void) |
void | dump_current_statement () |
int | get_statement_number () |
eturn the line number of the statement being parsed More... | |
Variables | |
char * | Comm = NULL |
reader.c More... | |
char * | PrevComm = NULL |
char * | CurrComm |
int | iComm = 0 |
int | iPrevComm = 0 |
int | iCurrComm = 0 |
static int | CommSize = 0 |
static int | EofSeen = false |
static int * | getchar_buffer = NULL |
static int | getchar_buffer_size = 0 |
static int | i_getchar = UNDEF |
static int | l_getchar = UNDEF |
static int * | stmt_buffer = NULL |
le buffer contenant le statement courant, l'indice courant et la longueur. More... | |
static size_t | stmt_buffer_size = 0 |
static size_t | iStmt = 0 |
indexes in the buffer... More... | |
static size_t | lStmt = 0 |
static int * | line_buffer = NULL |
le buffer contenant la ligne que l'on doit lire en avance pour se rendre compte qu'on a finit de lire un statement, l'indice courant et la longueur. More... | |
static int | line_buffer_size = 0 |
static int | iLine = 0 |
static int | lLine = 0 |
static int | EtatQuotes |
LOCAL int | LineNumber |
LOCAL int | Column |
LOCAL int | StmtLineNumber |
LOCAL int | ProfZeroVirg |
LOCAL int | ProfZeroEgal |
static char * | OperateurPoints [] |
La table des operateurs du type '.XX. More... | |
static int | keywidx [26] |
Une table pour accelerer les recherche des keywords. More... | |
static int | tmp_b_I |
Variables qui serviront a mettre a jour les numeros de la premiere et de la derniere ligne de commentaire, et les numeros de la premiere et de la derniere ligne du statement. More... | |
static int | tmp_e_I |
static int | tmp_b_C |
static int | tmp_e_C |
static char | tmp_lab_I [6] |
static bool | parser_warn_for_columns_73_80 = true |
memoization des properties 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 [] |
#define INITIAL_BUFFER_SIZE (128) |
Comm contains the comments for the current statement in ReadStmt().
PrevComm contains the comments for the previous statement in ReadStmt(), which is currently being parsed. CurrComm contains the comments attached to the current line in ReadLine()
void append_data_current_stmt_buffer_to_declarations | ( | void | ) |
int[]
Definition at line 276 of file reader.c.
References code_decls_text, concatenate(), EntityCode(), free(), get_current_module_entity(), lStmt, malloc(), stmt_buffer, and strdup().
la 1ere lettre n'est pas modifiee
Definition at line 1308 of file reader.c.
References lStmt, ParserError(), and stmt_buffer.
Referenced by FindAssign(), FindAutre(), FindDo(), FindDoWhile(), FindIf(), FindIfArith(), FindImplicit(), and NeedKeyword().
void CheckParenthesis | ( | void | ) |
Warning("CheckParenthesis",
Definition at line 1032 of file reader.c.
References IS_QUOTED, lStmt, ParserError(), ProfZeroEgal, ProfZeroVirg, and stmt_buffer.
Referenced by PipsGetc().
void dump_current_statement | ( | void | ) |
Preprocessed statement: Spaces have been eliminated as well as continuation lines, keyword have been emphasized and variables capitalized.
Skip the initial lines
line_b_I, line_e_I
Copy the data lines
Definition at line 1354 of file reader.c.
References CurrentFN, line_b_I, line_e_I, pips_assert, safe_fclose(), safe_fopen(), and syn_in.
int FindAssign | ( | void | ) |
Definition at line 1197 of file reader.c.
References CapitalizeStmt(), iStmt, lStmt, ProfZeroEgal, stmt_buffer, and StmtEqualString().
Referenced by PipsGetc().
void FindAutre | ( | void | ) |
Definition at line 1169 of file reader.c.
References CapitalizeStmt(), iStmt, NeedKeyword(), ProfZeroEgal, stmt_buffer, and StmtEqualString().
Referenced by PipsGetc().
int FindDo | ( | void | ) |
Let's skip a loop label to look for a while construct
Definition at line 1087 of file reader.c.
References CapitalizeStmt(), iStmt, ProfZeroEgal, ProfZeroVirg, stmt_buffer, and StmtEqualString().
Referenced by PipsGetc().
int FindDoWhile | ( | void | ) |
This function is redundant with FindDo() but much easier to understand.
I leave it as documentation. FI.
Definition at line 1073 of file reader.c.
References CapitalizeStmt(), iStmt, ProfZeroEgal, and StmtEqualString().
void FindIf | ( | void | ) |
Definition at line 1150 of file reader.c.
References CapitalizeStmt(), FindMatchingPar(), iStmt, stmt_buffer, and StmtEqualString().
Referenced by PipsGetc().
int FindIfArith | ( | void | ) |
Definition at line 1134 of file reader.c.
References CapitalizeStmt(), FindMatchingPar(), iStmt, stmt_buffer, and StmtEqualString().
Referenced by PipsGetc().
int FindImplicit | ( | void | ) |
Definition at line 1114 of file reader.c.
References CapitalizeStmt(), FindProfZero(), iStmt, lStmt, NeedKeyword(), ProfZeroEgal, SIZE_UNDEF, and StmtEqualString().
Referenced by PipsGetc().
Definition at line 1267 of file reader.c.
References IS_QUOTED, lStmt, pips_assert, SIZE_UNDEF, and stmt_buffer.
Referenced by FindIf(), and FindIfArith().
void FindPoints | ( | void | ) |
Definition at line 1220 of file reader.c.
References iStmt, lStmt, OperateurPoints, stmt_buffer, and StmtEqualString().
Referenced by PipsGetc().
Definition at line 1248 of file reader.c.
References IS_QUOTED, iStmt, lStmt, SIZE_UNDEF, and stmt_buffer.
Referenced by FindImplicit().
int get_statement_number | ( | void | ) |
eturn the line number of the statement being parsed
Definition at line 1392 of file reader.c.
References StmtLineNumber.
Referenced by GenerateReturn(), make_get_rc_statement(), MakeArithmIfInst(), MakeAssignedOrComputedGotoInst(), MakeCallInst(), MakeLogicalIfInst(), MakeNewLabelledStatement(), MakeReturn(), MakeStatement(), and ReuseLabelledStatement().
int GetChar | ( | FILE * | fp | ) |
Routine de lecture physique.
In case an error occurs, buffer must be emptied. Since i_getchar and l_getchar cannot be touched by the error handling routine, changes of fp are tracked in GetChar() and dynamically tested. Kludge suggested by Fabien Coelho to avoid adding more global variables. (FI)
Empty (or rather invisible) lines made of TAB and SPACE characters are replaced by the string "\n".
This section (probably) is made obsolete by the new function parser_reset_all_reader_buffers(). The user_warning() is replaced by a pips_error(). Test: Cachan/bug10
If a file has just been opened
if the buffer is not empty, which may never occur if previous_fp == NULL, perform a buffer reset
A whole input line is read to process TABs and empty lines
large for expansion
Fortran has a limited character set. See standard section 3.1. This cannot be handled here as you do not know if you are in a string constant or not. You cannot convert the double quote into a simple quote because you may generate an illegal string constant. Maybe the best would be to uncomment the next test. FI, 21 February 1992 if( c == '"') FatalError("GetChar","Illegal double quote character"); "
FI: let's delay and do it in ReadLine: if (islower(c)) c = toupper(c);
for (i = 0; i < (8-Column%8); i++) {
Ignore carriage returns introduced by VMS, MSDOS or MACOS...
buffer[l_getchar++] = (col > 72) ? ' ' : c;
buffer[l_getchar++] = (col > 72) ? '
' : c;
last columns cannot be copied because we might be inside a character string
i_getchar = l_getchar = UNDEF;
LineNumber += 1;
fp | p |
Definition at line 614 of file reader.c.
References Column, debug(), getchar_buffer, getchar_buffer_size, i_getchar, ifdebug, init_getchar_buffer(), l_getchar, LineNumber, parser_warn_for_columns_73_80, pips_internal_error, resize_getchar_buffer(), START_COMMENT_LINE, UNDEF, and user_warning.
Referenced by ReadLine().
|
static |
lazy initialization of the comment buffer
if needed
Definition at line 160 of file reader.c.
References Comm, CommSize, CurrComm, INITIAL_BUFFER_SIZE, malloc(), pips_assert, pips_debug, and PrevComm.
Referenced by init_parser_reader_properties().
|
static |
number of elements in the array
if needed
Definition at line 190 of file reader.c.
References getchar_buffer, getchar_buffer_size, INITIAL_BUFFER_SIZE, malloc(), pips_assert, and pips_debug.
Referenced by GetChar().
|
static |
if needed
Definition at line 255 of file reader.c.
References INITIAL_BUFFER_SIZE, line_buffer, line_buffer_size, malloc(), pips_assert, and pips_debug.
Referenced by ReadLine().
void init_parser_reader_properties | ( | void | ) |
Definition at line 434 of file reader.c.
References get_bool_property(), init_comment_buffers(), and parser_warn_for_columns_73_80.
Referenced by init_parser_properties().
|
static |
if needed
Definition at line 222 of file reader.c.
References INITIAL_BUFFER_SIZE, malloc(), pips_assert, pips_debug, stmt_buffer, and stmt_buffer_size.
Referenced by ReadStmt().
int IsCapKeyword | ( | char * | s | ) |
Fonction appelee par sslex sur la reduction de la regle de reconnaissance des mot clefs.
Elle recherche si le mot 's' est un mot clef, retourne sa valeur si oui, et indique une erreur si non.
la chaine s est mise en majuscules
just to avoid a gcc warning
OTREACHED
Definition at line 515 of file reader.c.
References buffer, debug(), int, keywidx, keywtbl, ParserError(), pips_assert, UNDEF, and user_warning.
int NeedKeyword | ( | void | ) |
just to avoid a gcc warning
OTREACHED
Definition at line 1329 of file reader.c.
References CapitalizeStmt(), int, iStmt, keywidx, keywtbl, ParserError(), stmt_buffer, StmtEqualString(), and UNDEF.
Referenced by FindAutre(), and FindImplicit().
void parser_reset_all_reader_buffers | ( | void | ) |
int PipsGetc | ( | FILE * | fp | ) |
Routine de lecture pour l'analyseur lexical, lex ou flex.
fp | p |
Definition at line 557 of file reader.c.
References CheckParenthesis(), FindAssign(), FindAutre(), FindDo(), FindIf(), FindIfArith(), FindImplicit(), FindPoints(), iStmt, lStmt, ReadStmt(), SIZE_UNDEF, stmt_buffer, and UNQUOTE.
int ReadLine | ( | FILE * | fp | ) |
All physical lines of a statement are put together in a unique buffer called "line_buffer".
Each character in each physical line is retrieved with GetChar().
on entre dans ReadLine avec Column = 1
Read all comment lines you can
Read label
Check continuation character
Keep track of the first and last comment lines and of the first and last statement lines. These two intervals may intersect.
Append current comment CurrComm to Comm if it is a continuation. Save Comm in PrevComm and CurrComm in Comm if it is a first statement line.
FI: this is all wrong
Why destroy comments because there are continuation lines?
tmp_b_C = tmp_e_C = UNDEF;
Read the rest of the line, skipping SPACEs but handling string constants
fp | p |
Definition at line 765 of file reader.c.
References Column, Comm, CommSize, CONTINUATION_LINE, CurrComm, debug(), EOF_LINE, EtatQuotes, FIRST_LINE, GetChar(), iComm, iCurrComm, ifdebug, init_line_buffer(), INQUOTEBACKSLASH, INQUOTEQUOTE, INQUOTES, iPrevComm, line_buffer, line_buffer_size, LineNumber, lLine, NONINQUOTES, ParserError(), pips_assert, pips_debug, pips_user_warning, PrevComm, QUOTE, resize_comment_buffers(), resize_line_buffer(), START_COMMENT_LINE, tmp_b_C, tmp_b_I, tmp_e_C, tmp_lab_I, and UNDEF.
Referenced by ReadStmt().
int ReadStmt | ( | FILE * | fp | ) |
regroupement des lignes du statement en une unique ligne sans continuation
It would be nice to move the current comments from Comm to PrevComm, but it is just too late because of the repeat until control structure down: ReadLine() has already been called and read the first line of the next statement. Hence, CurrComm is needed.
Memorize the line number before to find next Statement
Update the current final lines for instruction and comments
Initialize temporary beginning and end line numbers
fp | p |
Definition at line 942 of file reader.c.
References CONTINUATION_LINE, EOF_LINE, EofSeen, FIRST_LINE, ifdebug, iLine, init_stmt_buffer(), iStmt, lab_I, line_b_C, line_b_I, line_buffer, line_e_C, line_e_I, LineNumber, lLine, lStmt, ParserError(), pips_debug, ReadLine(), resize_stmt_buffer(), stmt_buffer, stmt_buffer_size, StmtLineNumber, tmp_b_C, tmp_b_I, tmp_e_C, tmp_e_I, tmp_lab_I, and UNDEF.
Referenced by PipsGetc().
|
static |
Definition at line 172 of file reader.c.
References Comm, CommSize, CurrComm, pips_assert, pips_debug, and PrevComm.
Referenced by ReadLine().
|
static |
Definition at line 200 of file reader.c.
References getchar_buffer, getchar_buffer_size, pips_assert, and pips_debug.
Referenced by GetChar().
|
static |
Definition at line 265 of file reader.c.
References line_buffer, line_buffer_size, pips_assert, and pips_debug.
Referenced by ReadLine().
|
static |
Definition at line 232 of file reader.c.
References pips_assert, pips_debug, stmt_buffer, and stmt_buffer_size.
Referenced by ReadStmt().
void ScanNewFile | ( | void | ) |
La fonction a appeler pour l'analyse d'un nouveau fichier.
on initialise la table keywidx
on met a jour la table keywidx en fonction des keywords
premier keyword commencant par keywcour[0]
on initialise les variables externes locales et non locales
Definition at line 474 of file reader.c.
References Column, EtatQuotes, iLine, int, iStmt, keywidx, keywtbl, LineNumber, lLine, lStmt, NONINQUOTES, SIZE_UNDEF, StmtLineNumber, and UNDEF.
Referenced by the_actual_parser().
Definition at line 1290 of file reader.c.
References false, lStmt, and stmt_buffer.
Referenced by FindAssign(), FindAutre(), FindDo(), FindDoWhile(), FindIf(), FindIfArith(), FindImplicit(), FindPoints(), and NeedKeyword().
Definition at line 365 of file reader.c.
Referenced by GetChar(), ReadLine(), and ScanNewFile().
char* Comm = NULL |
Definition at line 152 of file reader.c.
Referenced by init_comment_buffers(), ReadLine(), and resize_comment_buffers().
|
static |
Definition at line 154 of file reader.c.
Referenced by init_comment_buffers(), ReadLine(), and resize_comment_buffers().
char * CurrComm |
Definition at line 152 of file reader.c.
Referenced by init_comment_buffers(), ReadLine(), and resize_comment_buffers().
Definition at line 155 of file reader.c.
Referenced by parser_reset_all_reader_buffers(), and ReadStmt().
|
static |
Definition at line 356 of file reader.c.
Referenced by ReadLine(), and ScanNewFile().
|
static |
Definition at line 186 of file reader.c.
Referenced by GetChar(), init_getchar_buffer(), and resize_getchar_buffer().
|
static |
Definition at line 187 of file reader.c.
Referenced by GetChar(), init_getchar_buffer(), and resize_getchar_buffer().
Definition at line 211 of file reader.c.
Referenced by GetChar(), and parser_reset_all_reader_buffers().
int iComm = 0 |
Definition at line 153 of file reader.c.
Referenced by parser_reset_all_reader_buffers(), and ReadLine().
int iCurrComm = 0 |
Definition at line 153 of file reader.c.
Referenced by parser_reset_all_reader_buffers(), and ReadLine().
|
static |
Definition at line 274 of file reader.c.
Referenced by parser_reset_all_reader_buffers(), ReadStmt(), and ScanNewFile().
int iPrevComm = 0 |
Definition at line 153 of file reader.c.
Referenced by LinkInstToCurrentBlock(), MakeDataStatement(), MakeElseInst(), MakeEndifInst(), parser_reset_all_reader_buffers(), and ReadLine().
|
static |
indexes in the buffer...
Definition at line 243 of file reader.c.
Referenced by FindAssign(), FindAutre(), FindDo(), FindDoWhile(), FindIf(), FindIfArith(), FindImplicit(), FindPoints(), FindProfZero(), NeedKeyword(), parser_reset_all_reader_buffers(), PipsGetc(), ReadStmt(), and ScanNewFile().
|
static |
Une table pour accelerer les recherche des keywords.
keywidx[X] indique le rang dans keywtbl du premier mot clef commencant par X.
Definition at line 418 of file reader.c.
Referenced by IsCapKeyword(), NeedKeyword(), and ScanNewFile().
Definition at line 211 of file reader.c.
Referenced by GetChar(), and parser_reset_all_reader_buffers().
|
extern |
Definition at line 69 of file parser.c.
Referenced by ReadStmt().
int line_b_C |
Definition at line 452 of file reader.c.
Referenced by ReadStmt().
|
extern |
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 dump_current_statement(), and ReadStmt().
|
static |
le buffer contenant la ligne que l'on doit lire en avance pour se rendre compte qu'on a finit de lire un statement, l'indice courant et la longueur.
Definition at line 251 of file reader.c.
Referenced by init_line_buffer(), ReadLine(), ReadStmt(), resize_line_buffer(), text_pointer_value(), text_pointer_values(), text_points_to_relation(), text_points_to_relations(), and text_region_no_action().
|
static |
Definition at line 252 of file reader.c.
Referenced by init_line_buffer(), ReadLine(), and resize_line_buffer().
int line_e_C |
Definition at line 452 of file reader.c.
Referenced by ReadStmt().
int line_e_I |
Definition at line 452 of file reader.c.
Referenced by dump_current_statement(), and ReadStmt().
Definition at line 365 of file reader.c.
Referenced by GetChar(), ReadLine(), ReadStmt(), and ScanNewFile().
|
static |
Definition at line 274 of file reader.c.
Referenced by parser_reset_all_reader_buffers(), ReadLine(), ReadStmt(), and ScanNewFile().
|
static |
Definition at line 243 of file reader.c.
Referenced by append_data_current_stmt_buffer_to_declarations(), CapitalizeStmt(), CheckParenthesis(), FindAssign(), FindImplicit(), FindMatchingPar(), FindPoints(), FindProfZero(), parser_reset_all_reader_buffers(), PipsGetc(), ReadStmt(), ScanNewFile(), and StmtEqualString().
|
static |
La table des operateurs du type '.XX.
'.
Definition at line 381 of file reader.c.
Referenced by FindPoints().
memoization des properties
Definition at line 431 of file reader.c.
Referenced by GetChar(), and init_parser_reader_properties().
char * PrevComm = NULL |
Definition at line 152 of file reader.c.
Referenced by init_comment_buffers(), LinkInstToCurrentBlock(), MakeDataStatement(), ReadLine(), and resize_comment_buffers().
Definition at line 377 of file reader.c.
Referenced by CheckParenthesis(), FindAssign(), FindAutre(), FindDo(), FindDoWhile(), and FindImplicit().
Definition at line 377 of file reader.c.
Referenced by CheckParenthesis(), and FindDo().
|
static |
le buffer contenant le statement courant, l'indice courant et la longueur.
Definition at line 218 of file reader.c.
Referenced by append_data_current_stmt_buffer_to_declarations(), CapitalizeStmt(), CheckParenthesis(), FindAssign(), FindAutre(), FindDo(), FindIf(), FindIfArith(), FindMatchingPar(), FindPoints(), FindProfZero(), init_stmt_buffer(), NeedKeyword(), PipsGetc(), ReadStmt(), resize_stmt_buffer(), and StmtEqualString().
|
static |
Definition at line 219 of file reader.c.
Referenced by init_stmt_buffer(), ReadStmt(), and resize_stmt_buffer().
Definition at line 371 of file reader.c.
Referenced by get_statement_number(), ReadStmt(), and ScanNewFile().
|
static |
Definition at line 424 of file reader.c.
Referenced by ReadLine(), and ReadStmt().
|
static |
Variables qui serviront a mettre a jour les numeros de la premiere et de la derniere ligne de commentaire, et les numeros de la premiere et de la derniere ligne du statement.
Definition at line 424 of file reader.c.
Referenced by ReadLine(), and ReadStmt().
|
static |
Definition at line 424 of file reader.c.
Referenced by ReadLine(), and ReadStmt().
|
static |
Definition at line 424 of file reader.c.
Referenced by ReadStmt().
|
static |
Definition at line 425 of file reader.c.
Referenced by ReadLine(), and ReadStmt().