2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006
3 Free Software Foundation, Inc.
4 Contributed by Andy Vaught
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
23 /* Set of subroutines to (ultimately) return the next character to the
24 various matching subroutines. This file's job is to read files and
25 build up lines that are parsed by the parser. This means that we
26 handle continuation lines and "include" lines.
28 The first thing the scanner does is to load an entire file into
29 memory. We load the entire file into memory for a couple reasons.
30 The first is that we want to be able to deal with nonseekable input
31 (pipes, stdin) and there is a lot of backing up involved during
34 The second is that we want to be able to print the locus of errors,
35 and an error on line 999999 could conflict with something on line
36 one. Given nonseekable input, we've got to store the whole thing.
38 One thing that helps are the column truncation limits that give us
39 an upper bound on the size of individual lines. We don't store the
42 From the scanner's viewpoint, the higher level subroutines ask for
43 new characters and do a lot of jumping backwards. */
50 /* Structure for holding module and include file search path. */
51 typedef struct gfc_directorylist
55 struct gfc_directorylist *next;
59 /* List of include file search directories. */
60 static gfc_directorylist *include_dirs, *intrinsic_modules_dirs;
62 static gfc_file *file_head, *current_file;
64 static int continue_flag, end_flag, openmp_flag;
65 static int continue_count, continue_line;
66 static locus openmp_locus;
68 gfc_source_form gfc_current_form;
69 static gfc_linebuf *line_head, *line_tail;
71 locus gfc_current_locus;
72 const char *gfc_source_file;
73 static FILE *gfc_src_file;
74 static char *gfc_src_preprocessor_lines[2];
78 /* Main scanner initialization. */
81 gfc_scanner_init_1 (void)
94 /* Main scanner destructor. */
97 gfc_scanner_done_1 (void)
102 while(line_head != NULL)
104 lb = line_head->next;
109 while(file_head != NULL)
112 gfc_free(file_head->filename);
120 /* Adds path to the list pointed to by list. */
123 add_path_to_list (gfc_directorylist **list, const char *path,
124 bool use_for_modules)
126 gfc_directorylist *dir;
130 while (*p == ' ' || *p == '\t') /* someone might do "-I include" */
136 dir = *list = gfc_getmem (sizeof (gfc_directorylist));
142 dir->next = gfc_getmem (sizeof (gfc_directorylist));
147 dir->use_for_modules = use_for_modules;
148 dir->path = gfc_getmem (strlen (p) + 2);
149 strcpy (dir->path, p);
150 strcat (dir->path, "/"); /* make '/' last character */
155 gfc_add_include_path (const char *path, bool use_for_modules)
157 add_path_to_list (&include_dirs, path, use_for_modules);
162 gfc_add_intrinsic_modules_path (const char *path)
164 add_path_to_list (&intrinsic_modules_dirs, path, true);
168 /* Release resources allocated for options. */
171 gfc_release_include_path (void)
173 gfc_directorylist *p;
175 gfc_free (gfc_option.module_dir);
176 while (include_dirs != NULL)
179 include_dirs = include_dirs->next;
184 gfc_free (gfc_option.module_dir);
185 while (intrinsic_modules_dirs != NULL)
187 p = intrinsic_modules_dirs;
188 intrinsic_modules_dirs = intrinsic_modules_dirs->next;
196 open_included_file (const char *name, gfc_directorylist *list, bool module)
199 gfc_directorylist *p;
202 f = gfc_open_file (name);
207 for (p = list; p; p = p->next)
209 if (module && !p->use_for_modules)
212 fullname = (char *) alloca(strlen (p->path) + strlen (name) + 1);
213 strcpy (fullname, p->path);
214 strcat (fullname, name);
216 f = gfc_open_file (fullname);
225 /* Opens file for reading, searching through the include directories
226 given if necessary. If the include_cwd argument is true, we try
227 to open the file in the current directory first. */
230 gfc_open_included_file (const char *name, bool include_cwd, bool module)
236 f = gfc_open_file (name);
241 return open_included_file (name, include_dirs, module);
245 gfc_open_intrinsic_module (const char *name)
247 return open_included_file (name, intrinsic_modules_dirs, true);
250 /* Test to see if we're at the end of the main source file. */
260 /* Test to see if we're at the end of the current file. */
269 if (line_head == NULL)
270 return 1; /* Null file */
272 if (gfc_current_locus.lb == NULL)
279 /* Test to see if we're at the beginning of a new line. */
287 return (gfc_current_locus.nextc == gfc_current_locus.lb->line);
291 /* Test to see if we're at the end of a line. */
300 return (*gfc_current_locus.nextc == '\0');
304 /* Advance the current line pointer to the next line. */
307 gfc_advance_line (void)
312 if (gfc_current_locus.lb == NULL)
318 gfc_current_locus.lb = gfc_current_locus.lb->next;
320 if (gfc_current_locus.lb != NULL)
321 gfc_current_locus.nextc = gfc_current_locus.lb->line;
324 gfc_current_locus.nextc = NULL;
330 /* Get the next character from the input, advancing gfc_current_file's
331 locus. When we hit the end of the line or the end of the file, we
332 start returning a '\n' in order to complete the current statement.
333 No Fortran line conventions are implemented here.
335 Requiring explicit advances to the next line prevents the parse
336 pointer from being on the wrong line if the current statement ends
344 if (gfc_current_locus.nextc == NULL)
347 c = *gfc_current_locus.nextc++;
350 gfc_current_locus.nextc--; /* Remain on this line. */
357 /* Skip a comment. When we come here the parse pointer is positioned
358 immediately after the comment character. If we ever implement
359 compiler directives withing comments, here is where we parse the
363 skip_comment_line (void)
377 /* Comment lines are null lines, lines containing only blanks or lines
378 on which the first nonblank line is a '!'.
379 Return true if !$ openmp conditional compilation sentinel was
383 skip_free_comments (void)
391 at_bol = gfc_at_bol ();
392 start = gfc_current_locus;
398 while (gfc_is_whitespace (c));
408 /* If -fopenmp, we need to handle here 2 things:
409 1) don't treat !$omp as comments, but directives
410 2) handle OpenMP conditional compilation, where
411 !$ should be treated as 2 spaces (for initial lines
412 only if followed by space). */
413 if (gfc_option.flag_openmp && at_bol)
415 locus old_loc = gfc_current_locus;
416 if (next_char () == '$')
419 if (c == 'o' || c == 'O')
421 if (((c = next_char ()) == 'm' || c == 'M')
422 && ((c = next_char ()) == 'p' || c == 'P')
423 && ((c = next_char ()) == ' ' || continue_flag))
425 while (gfc_is_whitespace (c))
427 if (c != '\n' && c != '!')
430 openmp_locus = old_loc;
431 gfc_current_locus = start;
435 gfc_current_locus = old_loc;
439 if (continue_flag || c == ' ')
441 gfc_current_locus = old_loc;
447 gfc_current_locus = old_loc;
449 skip_comment_line ();
456 if (openmp_flag && at_bol)
458 gfc_current_locus = start;
463 /* Skip comment lines in fixed source mode. We have the same rules as
464 in skip_free_comment(), except that we can have a 'c', 'C' or '*'
465 in column 1, and a '!' cannot be in column 6. Also, we deal with
466 lines with 'd' or 'D' in column 1, if the user requested this. */
469 skip_fixed_comments (void)
477 start = gfc_current_locus;
482 while (gfc_is_whitespace (c));
487 skip_comment_line ();
492 gfc_current_locus = start;
499 start = gfc_current_locus;
510 if (c == '!' || c == 'c' || c == 'C' || c == '*')
512 /* If -fopenmp, we need to handle here 2 things:
513 1) don't treat !$omp|c$omp|*$omp as comments, but directives
514 2) handle OpenMP conditional compilation, where
515 !$|c$|*$ should be treated as 2 spaces if the characters
516 in columns 3 to 6 are valid fixed form label columns
518 if (gfc_option.flag_openmp)
520 if (next_char () == '$')
523 if (c == 'o' || c == 'O')
525 if (((c = next_char ()) == 'm' || c == 'M')
526 && ((c = next_char ()) == 'p' || c == 'P'))
530 && ((openmp_flag && continue_flag)
531 || c == ' ' || c == '0'))
534 while (gfc_is_whitespace (c))
536 if (c != '\n' && c != '!')
538 /* Canonicalize to *$omp. */
541 gfc_current_locus = start;
551 for (col = 3; col < 6; col++, c = next_char ())
554 else if (c < '0' || c > '9')
559 if (col == 6 && c != '\n'
560 && ((continue_flag && !digit_seen)
561 || c == ' ' || c == '0'))
563 gfc_current_locus = start;
564 start.nextc[0] = ' ';
565 start.nextc[1] = ' ';
570 gfc_current_locus = start;
572 skip_comment_line ();
576 if (gfc_option.flag_d_lines != -1 && (c == 'd' || c == 'D'))
578 if (gfc_option.flag_d_lines == 0)
580 skip_comment_line ();
584 *start.nextc = c = ' ';
589 while (gfc_is_whitespace (c))
601 if (col != 6 && c == '!')
603 skip_comment_line ();
611 gfc_current_locus = start;
615 /* Skips the current line if it is a comment. */
618 gfc_skip_comments (void)
620 if (gfc_current_form == FORM_FREE)
621 skip_free_comments ();
623 skip_fixed_comments ();
627 /* Get the next character from the input, taking continuation lines
628 and end-of-line comments into account. This implies that comment
629 lines between continued lines must be eaten here. For higher-level
630 subroutines, this flattens continued lines into a single logical
631 line. The in_string flag denotes whether we're inside a character
635 gfc_next_char_literal (int in_string)
638 int i, c, prev_openmp_flag;
650 if (gfc_current_form == FORM_FREE)
652 bool openmp_cond_flag;
654 if (!in_string && c == '!')
657 && memcmp (&gfc_current_locus, &openmp_locus,
658 sizeof (gfc_current_locus)) == 0)
661 /* This line can't be continued */
668 /* Avoid truncation warnings for comment ending lines. */
669 gfc_current_locus.lb->truncated = 0;
677 /* If the next nonblank character is a ! or \n, we've got a
678 continuation line. */
679 old_loc = gfc_current_locus;
682 while (gfc_is_whitespace (c))
685 /* Character constants to be continued cannot have commentary
688 if (in_string && c != '\n')
690 gfc_current_locus = old_loc;
695 if (c != '!' && c != '\n')
697 gfc_current_locus = old_loc;
702 prev_openmp_flag = openmp_flag;
705 skip_comment_line ();
709 /* We've got a continuation line. If we are on the very next line after
710 the last continuation, increment the continuation line count and
711 check whether the limit has been exceeded. */
712 if (gfc_current_locus.lb->linenum == continue_line + 1)
714 if (++continue_count == gfc_option.max_continue_free)
716 if (gfc_notification_std (GFC_STD_GNU)
718 gfc_warning ("Limit of %d continuations exceeded in statement at %C",
719 gfc_option.max_continue_free);
722 continue_line = gfc_current_locus.lb->linenum;
724 /* Now find where it continues. First eat any comment lines. */
725 openmp_cond_flag = skip_free_comments ();
727 if (prev_openmp_flag != openmp_flag)
729 gfc_current_locus = old_loc;
730 openmp_flag = prev_openmp_flag;
735 /* Now that we have a non-comment line, probe ahead for the
736 first non-whitespace character. If it is another '&', then
737 reading starts at the next character, otherwise we must back
738 up to where the whitespace started and resume from there. */
740 old_loc = gfc_current_locus;
743 while (gfc_is_whitespace (c))
748 for (i = 0; i < 5; i++, c = next_char ())
750 gcc_assert (TOLOWER (c) == "!$omp"[i]);
752 old_loc = gfc_current_locus;
754 while (gfc_is_whitespace (c))
762 if (gfc_option.warn_ampersand)
763 gfc_warning_now ("Missing '&' in continued character constant at %C");
764 gfc_current_locus.nextc--;
766 /* Both !$omp and !$ -fopenmp continuation lines have & on the
767 continuation line only optionally. */
768 else if (openmp_flag || openmp_cond_flag)
769 gfc_current_locus.nextc--;
773 gfc_current_locus = old_loc;
780 /* Fixed form continuation. */
781 if (!in_string && c == '!')
783 /* Skip comment at end of line. */
790 /* Avoid truncation warnings for comment ending lines. */
791 gfc_current_locus.lb->truncated = 0;
797 prev_openmp_flag = openmp_flag;
799 old_loc = gfc_current_locus;
802 skip_fixed_comments ();
804 /* See if this line is a continuation line. */
805 if (openmp_flag != prev_openmp_flag)
807 openmp_flag = prev_openmp_flag;
808 goto not_continuation;
812 for (i = 0; i < 5; i++)
816 goto not_continuation;
819 for (i = 0; i < 5; i++)
822 if (TOLOWER (c) != "*$omp"[i])
823 goto not_continuation;
827 if (c == '0' || c == ' ' || c == '\n')
828 goto not_continuation;
830 /* We've got a continuation line. If we are on the very next line after
831 the last continuation, increment the continuation line count and
832 check whether the limit has been exceeded. */
833 if (gfc_current_locus.lb->linenum == continue_line + 1)
835 if (++continue_count == gfc_option.max_continue_fixed)
837 if (gfc_notification_std (GFC_STD_GNU)
839 gfc_warning ("Limit of %d continuations exceeded in statement at %C",
840 gfc_option.max_continue_fixed);
844 if (continue_line < gfc_current_locus.lb->linenum)
845 continue_line = gfc_current_locus.lb->linenum;
848 /* Ready to read first character of continuation line, which might
849 be another continuation line! */
854 gfc_current_locus = old_loc;
864 /* Get the next character of input, folded to lowercase. In fixed
865 form mode, we also ignore spaces. When matcher subroutines are
866 parsing character literals, they have to call
867 gfc_next_char_literal(). */
876 c = gfc_next_char_literal (0);
878 while (gfc_current_form == FORM_FIXED && gfc_is_whitespace (c));
890 old_loc = gfc_current_locus;
891 c = gfc_next_char ();
892 gfc_current_locus = old_loc;
898 /* Recover from an error. We try to get past the current statement
899 and get lined up for the next. The next statement follows a '\n'
900 or a ';'. We also assume that we are not within a character
901 constant, and deal with finding a '\'' or '"'. */
904 gfc_error_recovery (void)
913 c = gfc_next_char ();
914 if (c == '\n' || c == ';')
917 if (c != '\'' && c != '"')
946 /* Read ahead until the next character to be read is not whitespace. */
949 gfc_gobble_whitespace (void)
951 static int linenum = 0;
957 old_loc = gfc_current_locus;
958 c = gfc_next_char_literal (0);
959 /* Issue a warning for nonconforming tabs. We keep track of the line
960 number because the Fortran matchers will often back up and the same
961 line will be scanned multiple times. */
962 if (!gfc_option.warn_tabs && c == '\t')
964 #ifdef USE_MAPPED_LOCATION
965 int cur_linenum = LOCATION_LINE (gfc_current_locus.lb->location);
967 int cur_linenum = gfc_current_locus.lb->linenum;
969 if (cur_linenum != linenum)
971 linenum = cur_linenum;
972 gfc_warning_now ("Nonconforming tab character at %C");
976 while (gfc_is_whitespace (c));
978 gfc_current_locus = old_loc;
982 /* Load a single line into pbuf.
984 If pbuf points to a NULL pointer, it is allocated.
985 We truncate lines that are too long, unless we're dealing with
986 preprocessor lines or if the option -ffixed-line-length-none is set,
987 in which case we reallocate the buffer to fit the entire line, if
989 In fixed mode, we expand a tab that occurs within the statement
990 label region to expand to spaces that leave the next character in
992 load_line returns whether the line was truncated.
994 NOTE: The error machinery isn't available at this point, so we can't
995 easily report line and column numbers consistent with other
996 parts of gfortran. */
999 load_line (FILE * input, char **pbuf, int *pbuflen)
1001 static int linenum = 0, current_line = 1;
1002 int c, maxlen, i, preprocessor_flag, buflen = *pbuflen;
1003 int trunc_flag = 0, seen_comment = 0;
1004 int seen_printable = 0, seen_ampersand = 0;
1007 /* Determine the maximum allowed line length. */
1008 if (gfc_current_form == FORM_FREE)
1009 maxlen = gfc_option.free_line_length;
1010 else if (gfc_current_form == FORM_FIXED)
1011 maxlen = gfc_option.fixed_line_length;
1017 /* Allocate the line buffer, storing its length into buflen.
1018 Note that if maxlen==0, indicating that arbitrary-length lines
1019 are allowed, the buffer will be reallocated if this length is
1020 insufficient; since 132 characters is the length of a standard
1021 free-form line, we use that as a starting guess. */
1027 *pbuf = gfc_getmem (buflen + 1);
1033 preprocessor_flag = 0;
1036 /* In order to not truncate preprocessor lines, we have to
1037 remember that this is one. */
1038 preprocessor_flag = 1;
1049 /* Check for illegal use of ampersand. See F95 Standard 3.3.1.3. */
1050 if (gfc_current_form == FORM_FREE
1051 && !seen_printable && seen_ampersand)
1055 ("'&' not allowed by itself in line %d", current_line);
1058 ("'&' not allowed by itself in line %d", current_line);
1064 continue; /* Gobble characters. */
1070 /* Ctrl-Z ends the file. */
1071 while (fgetc (input) != EOF);
1075 /* Check for illegal use of ampersand. See F95 Standard 3.3.1.3. */
1079 if ((c != ' ' && c != '&' && c != '!') || (c == '!' && !seen_ampersand))
1082 if (gfc_current_form == FORM_FREE
1083 && c == '!' && !seen_printable && seen_ampersand)
1087 "'&' not allowed by itself with comment in line %d", current_line);
1090 "'&' not allowed by itself with comment in line %d", current_line);
1094 /* Is this a fixed-form comment? */
1095 if (gfc_current_form == FORM_FIXED && i == 0
1096 && (c == '*' || c == 'c' || c == 'd'))
1099 if (gfc_current_form == FORM_FIXED && c == '\t' && i <= 6)
1101 if (!gfc_option.warn_tabs && seen_comment == 0
1102 && current_line != linenum)
1104 linenum = current_line;
1106 "Nonconforming tab character in column 1 of line %d", linenum);
1121 if (maxlen == 0 || preprocessor_flag)
1125 /* Reallocate line buffer to double size to hold the
1127 buflen = buflen * 2;
1128 *pbuf = xrealloc (*pbuf, buflen + 1);
1132 else if (i >= maxlen)
1134 /* Truncate the rest of the line. */
1138 if (c == '\n' || c == EOF)
1144 ungetc ('\n', input);
1148 /* Pad lines to the selected line length in fixed form. */
1149 if (gfc_current_form == FORM_FIXED
1150 && gfc_option.fixed_line_length != 0
1151 && !preprocessor_flag
1154 while (i++ < maxlen)
1166 /* Get a gfc_file structure, initialize it and add it to
1170 get_file (const char *name, enum lc_reason reason ATTRIBUTE_UNUSED)
1174 f = gfc_getmem (sizeof (gfc_file));
1176 f->filename = gfc_getmem (strlen (name) + 1);
1177 strcpy (f->filename, name);
1179 f->next = file_head;
1182 f->included_by = current_file;
1183 if (current_file != NULL)
1184 f->inclusion_line = current_file->line;
1186 #ifdef USE_MAPPED_LOCATION
1187 linemap_add (&line_table, reason, false, f->filename, 1);
1193 /* Deal with a line from the C preprocessor. The
1194 initial octothorp has already been seen. */
1197 preprocessor_line (char *c)
1203 int escaped, unescape;
1206 while (*c == ' ' || *c == '\t')
1209 if (*c < '0' || *c > '9')
1214 c = strchr (c, ' ');
1217 /* No file name given. Set new line number. */
1218 current_file->line = line;
1223 while (*c == ' ' || *c == '\t')
1233 /* Make filename end at quote. */
1236 while (*c && ! (! escaped && *c == '"'))
1240 else if (*c == '\\')
1249 /* Preprocessor line has no closing quote. */
1254 /* Undo effects of cpp_quote_string. */
1258 char *d = gfc_getmem (c - filename - unescape);
1274 flag[1] = flag[2] = flag[3] = flag[4] = false;
1278 c = strchr (c, ' ');
1285 if (1 <= i && i <= 4)
1289 /* Interpret flags. */
1291 if (flag[1]) /* Starting new file. */
1293 f = get_file (filename, LC_RENAME);
1294 f->up = current_file;
1298 if (flag[2]) /* Ending current file. */
1300 if (!current_file->up
1301 || strcmp (current_file->up->filename, filename) != 0)
1303 gfc_warning_now ("%s:%d: file %s left but not entered",
1304 current_file->filename, current_file->line,
1307 gfc_free (filename);
1310 current_file = current_file->up;
1313 /* The name of the file can be a temporary file produced by
1314 cpp. Replace the name if it is different. */
1316 if (strcmp (current_file->filename, filename) != 0)
1318 gfc_free (current_file->filename);
1319 current_file->filename = gfc_getmem (strlen (filename) + 1);
1320 strcpy (current_file->filename, filename);
1323 /* Set new line number. */
1324 current_file->line = line;
1326 gfc_free (filename);
1330 gfc_warning_now ("%s:%d: Illegal preprocessor directive",
1331 current_file->filename, current_file->line);
1332 current_file->line++;
1336 static try load_file (const char *, bool);
1338 /* include_line()-- Checks a line buffer to see if it is an include
1339 line. If so, we call load_file() recursively to load the included
1340 file. We never return a syntax error because a statement like
1341 "include = 5" is perfectly legal. We return false if no include was
1342 processed or true if we matched an include. */
1345 include_line (char *line)
1347 char quote, *c, *begin, *stop;
1351 if (gfc_option.flag_openmp)
1353 if (gfc_current_form == FORM_FREE)
1355 while (*c == ' ' || *c == '\t')
1357 if (*c == '!' && c[1] == '$' && (c[2] == ' ' || c[2] == '\t'))
1362 if ((*c == '!' || *c == 'c' || *c == 'C' || *c == '*')
1363 && c[1] == '$' && (c[2] == ' ' || c[2] == '\t'))
1368 while (*c == ' ' || *c == '\t')
1371 if (strncasecmp (c, "include", 7))
1375 while (*c == ' ' || *c == '\t')
1378 /* Find filename between quotes. */
1381 if (quote != '"' && quote != '\'')
1386 while (*c != quote && *c != '\0')
1394 while (*c == ' ' || *c == '\t')
1397 if (*c != '\0' && *c != '!')
1400 /* We have an include line at this point. */
1402 *stop = '\0'; /* It's ok to trash the buffer, as this line won't be
1403 read by anything else. */
1405 load_file (begin, false);
1409 /* Load a file into memory by calling load_line until the file ends. */
1412 load_file (const char *filename, bool initial)
1420 for (f = current_file; f; f = f->up)
1421 if (strcmp (filename, f->filename) == 0)
1423 gfc_error_now ("File '%s' is being included recursively", filename);
1431 input = gfc_src_file;
1432 gfc_src_file = NULL;
1435 input = gfc_open_file (filename);
1438 gfc_error_now ("Can't open file '%s'", filename);
1444 input = gfc_open_included_file (filename, false, false);
1447 gfc_error_now ("Can't open included file '%s'", filename);
1452 /* Load the file. */
1454 f = get_file (filename, initial ? LC_RENAME : LC_ENTER);
1455 f->up = current_file;
1457 current_file->line = 1;
1461 if (initial && gfc_src_preprocessor_lines[0])
1463 preprocessor_line (gfc_src_preprocessor_lines[0]);
1464 gfc_free (gfc_src_preprocessor_lines[0]);
1465 gfc_src_preprocessor_lines[0] = NULL;
1466 if (gfc_src_preprocessor_lines[1])
1468 preprocessor_line (gfc_src_preprocessor_lines[1]);
1469 gfc_free (gfc_src_preprocessor_lines[1]);
1470 gfc_src_preprocessor_lines[1] = NULL;
1476 int trunc = load_line (input, &line, &line_len);
1478 len = strlen (line);
1479 if (feof (input) && len == 0)
1482 /* There are three things this line can be: a line of Fortran
1483 source, an include line or a C preprocessor directive. */
1487 preprocessor_line (line);
1491 if (include_line (line))
1493 current_file->line++;
1499 b = gfc_getmem (gfc_linebuf_header_size + len + 1);
1501 #ifdef USE_MAPPED_LOCATION
1503 = linemap_line_start (&line_table, current_file->line++, 120);
1505 b->linenum = current_file->line++;
1507 b->file = current_file;
1508 b->truncated = trunc;
1509 strcpy (b->line, line);
1511 if (line_head == NULL)
1514 line_tail->next = b;
1519 /* Release the line buffer allocated in load_line. */
1524 current_file = current_file->up;
1525 #ifdef USE_MAPPED_LOCATION
1526 linemap_add (&line_table, LC_LEAVE, 0, NULL, 0);
1532 /* Open a new file and start scanning from that file. Returns SUCCESS
1533 if everything went OK, FAILURE otherwise. If form == FORM_UKNOWN
1534 it tries to determine the source form from the filename, defaulting
1542 result = load_file (gfc_source_file, true);
1544 gfc_current_locus.lb = line_head;
1545 gfc_current_locus.nextc = (line_head == NULL) ? NULL : line_head->line;
1547 #if 0 /* Debugging aid. */
1548 for (; line_head; line_head = line_head->next)
1549 gfc_status ("%s:%3d %s\n", line_head->file->filename,
1550 #ifdef USE_MAPPED_LOCATION
1551 LOCATION_LINE (line_head->location),
1564 unescape_filename (const char *ptr)
1566 const char *p = ptr, *s;
1568 int escaped, unescape = 0;
1570 /* Make filename end at quote. */
1572 while (*p && ! (! escaped && *p == '"'))
1576 else if (*p == '\\')
1587 /* Undo effects of cpp_quote_string. */
1589 d = gfc_getmem (p + 1 - ptr - unescape);
1604 /* For preprocessed files, if the first tokens are of the form # NUM.
1605 handle the directives so we know the original file name. */
1608 gfc_read_orig_filename (const char *filename, const char **canon_source_file)
1613 gfc_src_file = gfc_open_file (filename);
1614 if (gfc_src_file == NULL)
1617 c = fgetc (gfc_src_file);
1618 ungetc (c, gfc_src_file);
1624 load_line (gfc_src_file, &gfc_src_preprocessor_lines[0], &len);
1626 if (strncmp (gfc_src_preprocessor_lines[0], "# 1 \"", 5) != 0)
1629 filename = unescape_filename (gfc_src_preprocessor_lines[0] + 5);
1630 if (filename == NULL)
1633 c = fgetc (gfc_src_file);
1634 ungetc (c, gfc_src_file);
1640 load_line (gfc_src_file, &gfc_src_preprocessor_lines[1], &len);
1642 if (strncmp (gfc_src_preprocessor_lines[1], "# 1 \"", 5) != 0)
1645 dirname = unescape_filename (gfc_src_preprocessor_lines[1] + 5);
1646 if (dirname == NULL)
1649 len = strlen (dirname);
1650 if (len < 3 || dirname[len - 1] != '/' || dirname[len - 2] != '/')
1655 dirname[len - 2] = '\0';
1656 set_src_pwd (dirname);
1658 if (! IS_ABSOLUTE_PATH (filename))
1660 char *p = gfc_getmem (len + strlen (filename));
1662 memcpy (p, dirname, len - 2);
1664 strcpy (p + len - 1, filename);
1665 *canon_source_file = p;