2 #include "defines-local.h"
4 static statement current_statement = statement_undefined;
6 static char *directive_txt = NULL;
7 static char *comment_txt = NULL;
9 static void directive_start(int type);
10 static void directive_reset(void);
11 static void append(char **buffer);
12 static void clean_buffer(char **buffer);
13 static void end_directive(void);
14 static void end_comment(void);
16 static int directive_syntaxe = -1;
17 static int directive_type = -1;
19 #define DIRECTIVE_STEP 0
20 #define DIRECTIVE_OMP 1
29 Attention PIPS supprime les blancs en début de commentaire en syntaxe libre, et insÚre un saut de ligne supplémentaire :
40 comment_libre [:blank:]+!
42 continuation_fixe [^[:blank:]0]
43 continuation_libre ([:blank:]*&[:blank:]*)?
45 sentinelle_step $(?i:step)
46 sentinelle_omp $(?i:omp)
47 sentinelle {sentinelle_step}|{sentinelle_omp}
50 %x comment_fixe directive_fixe directive_fixe_comment directive_fixe_continuation
51 %x comment_libre directive_libre directive_libre_comment directive_libre_continuation
57 Directive à syntaxe libre
59 <directive_libre>[^&!\n]* {
60 append(&directive_txt); // ajout du texte de la directive
61 BEGIN(directive_libre_comment);
64 <directive_libre_comment>&[^!\n]* { // détection d'une continuation du texte de la directive sur la ligne suivante
65 BEGIN(directive_libre_continuation);
68 <directive_libre_continuation>{ // controle de la continuation
69 \n{comment_libre}{sentinelle_omp}{continuation_libre} {
70 if (directive_type != DIRECTIVE_OMP)
71 yy_fatal_error("erreur continuation omp libre\n");
72 BEGIN(directive_libre);
74 \n{comment_libre}{sentinelle_step}{continuation_libre} {
75 if (directive_type != DIRECTIVE_STEP)
76 yy_fatal_error("erreur continuation omp libre\n");
77 BEGIN(directive_libre);
82 Directive à syntaxe fixe
84 <directive_fixe>[^!\n]* {
85 append(&directive_txt); // ajout du texte de la directive
86 BEGIN(directive_fixe_comment);
89 <directive_fixe_comment>\n{comment_fixe}/({sentinelle}{continuation_fixe}) { // détection d'une continuation du texte de la directive sur la ligne suivante
90 BEGIN(directive_fixe_continuation);
93 <directive_fixe_continuation>{ // controle de la continuation
94 {sentinelle_omp}{continuation_fixe} {
95 if (directive_type != DIRECTIVE_OMP)
96 yy_fatal_error("erreur continuation omp fixe\n");
97 BEGIN(directive_fixe);
99 {sentinelle_step}{continuation_fixe} {
100 if (directive_type != DIRECTIVE_STEP)
101 yy_fatal_error("erreur continuation step fixe\n");
102 BEGIN(directive_fixe);
107 Collecte d'un commentaire porté par une directive
109 <directive_fixe_comment,directive_libre_comment,directive_libre_continuation>!.* {
110 append(&comment_txt);
114 Détection de la fin d'une directive et de son commentaire associé éventuel
116 <directive_fixe_comment,directive_libre_comment>\n {
117 append(&comment_txt);
126 Identification d'une nouvelle directive
128 <comment_fixe,comment_libre>{
129 {sentinelle_omp}[[:blank:]0] {
130 directive_start(DIRECTIVE_OMP);
132 {sentinelle_step}[[:blank:]0] {
133 directive_start(DIRECTIVE_STEP);
138 Identification des commentaires et autres lignes
140 <comment_fixe,comment_libre>\n|([^$\n].*\n) {
141 append(&comment_txt);
143 clean_buffer(&comment_txt);
147 append(&comment_txt);
149 clean_buffer(&comment_txt);
160 BEGIN(comment_libre);
164 append(&comment_txt);
166 clean_buffer(&comment_txt);
176 static void directive_start(int type)
178 directive_type = type;
183 directive_syntaxe = directive_fixe;
184 BEGIN(directive_fixe);
187 directive_syntaxe = directive_libre;
188 BEGIN(directive_libre);
191 yy_fatal_error("erreur syntaxe\n");
195 static void directive_reset(void)
197 clean_buffer(&directive_txt);
198 clean_buffer(&comment_txt);
199 directive_syntaxe = -1;
203 static void append(char **buffer)
206 *buffer = strdup(yytext);
209 *buffer = realloc(*buffer, sizeof(*buffer) * (strlen(*buffer) + yyleng));
210 *buffer = strncat(*buffer, yytext, yyleng);
214 static void clean_buffer(char **buffer)
223 static void remove_blank(void)
228 dest = directive_txt;
229 for(src=directive_txt; *src !='\0'; src++)
230 if (*src != ' ' && *src != '\t')
238 static char *get_directive_type(void)
240 switch (directive_type)
243 return strdup("step");
246 return strdup("omp");
255 static void end_comment(void)
257 if (!statement_undefined_p(current_statement))
259 pips_debug(2,"COMMENTAIRE_TXT-> \"%s\"\n", comment_txt);
260 append_comments_to_statement(current_statement, comment_txt);
266 if (comment_txt !=NULL)
267 pips_debug(1,"%s :%s",(YY_START==other_line)?"OTHER_LINE":"COMMENT", comment_txt);
274 static void end_directive(void)
276 string directive_type = get_directive_type();
278 // suppression du saut de ligne
279 comment_txt[strlen(comment_txt)-1]='\0';
281 if (directive_syntaxe == directive_fixe)
284 pips_debug(2,"DIRECTIVE-> %s \"%s\"\n", directive_type, directive_txt);
285 pips_debug(2,"\tCOMMENTAIRE_DIR-> \"%s\"\n", comment_txt);
287 if(!statement_undefined_p(current_statement))
289 extensions_extension(statement_extensions(current_statement))=gen_nreverse(extensions_extension(statement_extensions(current_statement)));
290 add_pragma_str_to_statement(current_statement, strdup(concatenate(directive_type,directive_txt,NULL)), false);
291 extensions_extension(statement_extensions(current_statement))=gen_nreverse(extensions_extension(statement_extensions(current_statement)));
293 if (strlen(comment_txt))
295 if (!empty_comments_p(statement_comments(current_statement)))
297 free(statement_comments(current_statement));
298 statement_comments(current_statement) = string_undefined;
300 append_comments_to_statement(current_statement, comment_txt);
305 pips_debug(1, "DIRECTIVE in decls_txt\n");
308 free(directive_type);
312 * For fortran programs
313 * converting comments into pragmas
317 void step_comment2pragma_handle(statement stmt)
319 pips_debug(1,"begin\n");
320 if(!statement_undefined_p(stmt))
322 string comment = statement_comments(stmt);
324 if (!empty_comments_p(comment))
326 pips_assert("statement undefined", statement_undefined_p(current_statement));
327 current_statement = stmt;
328 statement_comments(stmt) = string_undefined;
330 pips_debug(1,"Comment txt : begin scan\n");
331 yy_scan_string(comment);
333 pips_debug(1,"Comment txt : end scan\n");
336 current_statement = statement_undefined;
340 pips_debug(1,"Comment txt : Empty\n");
345 string decls_txt = code_decls_text(entity_code(get_current_module_entity()));
346 if (!empty_comments_p(decls_txt))
348 pips_debug(1,"Declaration txt : begin scan\n");
349 yy_scan_string(decls_txt);
351 pips_debug(1,"Declaration txt : end scan\n");
355 pips_debug(1,"Declaration txt : Empty\n");
358 pips_debug(1,"end\n");