2 Copyright (C) 2000-2015 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* Set of subroutines to (ultimately) return the next character to the
22 various matching subroutines. This file's job is to read files and
23 build up lines that are parsed by the parser. This means that we
24 handle continuation lines and "include" lines.
26 The first thing the scanner does is to load an entire file into
27 memory. We load the entire file into memory for a couple reasons.
28 The first is that we want to be able to deal with nonseekable input
29 (pipes, stdin) and there is a lot of backing up involved during
32 The second is that we want to be able to print the locus of errors,
33 and an error on line 999999 could conflict with something on line
34 one. Given nonseekable input, we've got to store the whole thing.
36 One thing that helps are the column truncation limits that give us
37 an upper bound on the size of individual lines. We don't store the
40 From the scanner's viewpoint, the higher level subroutines ask for
41 new characters and do a lot of jumping backwards. */
45 #include "coretypes.h"
47 #include "toplev.h" /* For set_src_pwd. */
53 /* List of include file search directories. */
54 gfc_directorylist
*include_dirs
, *intrinsic_modules_dirs
;
56 static gfc_file
*file_head
, *current_file
;
58 static int continue_flag
, end_flag
, gcc_attribute_flag
;
59 /* If !$omp/!$acc occurred in current comment line. */
60 static int openmp_flag
, openacc_flag
;
61 static int continue_count
, continue_line
;
62 static locus openmp_locus
;
63 static locus openacc_locus
;
64 static locus gcc_attribute_locus
;
66 gfc_source_form gfc_current_form
;
67 static gfc_linebuf
*line_head
, *line_tail
;
69 locus gfc_current_locus
;
70 const char *gfc_source_file
;
71 static FILE *gfc_src_file
;
72 static gfc_char_t
*gfc_src_preprocessor_lines
[2];
74 static struct gfc_file_change
80 size_t file_changes_cur
, file_changes_count
;
81 size_t file_changes_allocated
;
84 /* Functions dealing with our wide characters (gfc_char_t) and
85 sequences of such characters. */
88 gfc_wide_fits_in_byte (gfc_char_t c
)
90 return (c
<= UCHAR_MAX
);
94 wide_is_ascii (gfc_char_t c
)
96 return (gfc_wide_fits_in_byte (c
) && ((unsigned char) c
& ~0x7f) == 0);
100 gfc_wide_is_printable (gfc_char_t c
)
102 return (gfc_wide_fits_in_byte (c
) && ISPRINT ((unsigned char) c
));
106 gfc_wide_tolower (gfc_char_t c
)
108 return (wide_is_ascii (c
) ? (gfc_char_t
) TOLOWER((unsigned char) c
) : c
);
112 gfc_wide_toupper (gfc_char_t c
)
114 return (wide_is_ascii (c
) ? (gfc_char_t
) TOUPPER((unsigned char) c
) : c
);
118 gfc_wide_is_digit (gfc_char_t c
)
120 return (c
>= '0' && c
<= '9');
124 wide_atoi (gfc_char_t
*c
)
126 #define MAX_DIGITS 20
127 char buf
[MAX_DIGITS
+1];
130 while (gfc_wide_is_digit(*c
) && i
< MAX_DIGITS
)
137 gfc_wide_strlen (const gfc_char_t
*str
)
141 for (i
= 0; str
[i
]; i
++)
148 gfc_wide_memset (gfc_char_t
*b
, gfc_char_t c
, size_t len
)
152 for (i
= 0; i
< len
; i
++)
159 wide_strcpy (gfc_char_t
*dest
, const gfc_char_t
*src
)
163 for (d
= dest
; (*d
= *src
) != '\0'; ++src
, ++d
)
170 wide_strchr (const gfc_char_t
*s
, gfc_char_t c
)
175 return CONST_CAST(gfc_char_t
*, s
);
182 gfc_widechar_to_char (const gfc_char_t
*s
, int length
)
190 /* Passing a negative length is used to indicate that length should be
191 calculated using gfc_wide_strlen(). */
192 len
= (length
>= 0 ? (size_t) length
: gfc_wide_strlen (s
));
193 res
= XNEWVEC (char, len
+ 1);
195 for (i
= 0; i
< len
; i
++)
197 gcc_assert (gfc_wide_fits_in_byte (s
[i
]));
198 res
[i
] = (unsigned char) s
[i
];
206 gfc_char_to_widechar (const char *s
)
215 res
= gfc_get_wide_string (len
+ 1);
217 for (i
= 0; i
< len
; i
++)
218 res
[i
] = (unsigned char) s
[i
];
225 wide_strncmp (const gfc_char_t
*s1
, const char *s2
, size_t n
)
234 return (c1
> c2
? 1 : -1);
242 gfc_wide_strncasecmp (const gfc_char_t
*s1
, const char *s2
, size_t n
)
248 c1
= gfc_wide_tolower (*s1
++);
249 c2
= TOLOWER (*s2
++);
251 return (c1
> c2
? 1 : -1);
259 /* Main scanner initialization. */
262 gfc_scanner_init_1 (void)
275 /* Main scanner destructor. */
278 gfc_scanner_done_1 (void)
283 while(line_head
!= NULL
)
285 lb
= line_head
->next
;
290 while(file_head
!= NULL
)
293 free (file_head
->filename
);
300 /* Adds path to the list pointed to by list. */
303 add_path_to_list (gfc_directorylist
**list
, const char *path
,
304 bool use_for_modules
, bool head
, bool warn
)
306 gfc_directorylist
*dir
;
314 while (*p
== ' ' || *p
== '\t') /* someone might do "-I include" */
318 /* Strip trailing directory separators from the path, as this
319 will confuse Windows systems. */
321 q
= (char *) alloca (len
+ 1);
322 memcpy (q
, p
, len
+ 1);
324 while (i
>=0 && IS_DIR_SEPARATOR (q
[i
]))
330 gfc_warning_now (0, "Include directory %qs: %s", path
,
333 gfc_warning_now (OPT_Wmissing_include_dirs
,
334 "Nonexistent include directory %qs", path
);
337 else if (!S_ISDIR (st
.st_mode
))
339 gfc_warning_now (0, "%qs is not a directory", path
);
343 if (head
|| *list
== NULL
)
345 dir
= XCNEW (gfc_directorylist
);
355 dir
->next
= XCNEW (gfc_directorylist
);
359 dir
->next
= head
? *list
: NULL
;
362 dir
->use_for_modules
= use_for_modules
;
363 dir
->path
= XCNEWVEC (char, strlen (p
) + 2);
364 strcpy (dir
->path
, p
);
365 strcat (dir
->path
, "/"); /* make '/' last character */
370 gfc_add_include_path (const char *path
, bool use_for_modules
, bool file_dir
,
373 add_path_to_list (&include_dirs
, path
, use_for_modules
, file_dir
, warn
);
375 /* For '#include "..."' these directories are automatically searched. */
377 gfc_cpp_add_include_path (xstrdup(path
), true);
382 gfc_add_intrinsic_modules_path (const char *path
)
384 add_path_to_list (&intrinsic_modules_dirs
, path
, true, false, false);
388 /* Release resources allocated for options. */
391 gfc_release_include_path (void)
393 gfc_directorylist
*p
;
395 while (include_dirs
!= NULL
)
398 include_dirs
= include_dirs
->next
;
403 while (intrinsic_modules_dirs
!= NULL
)
405 p
= intrinsic_modules_dirs
;
406 intrinsic_modules_dirs
= intrinsic_modules_dirs
->next
;
411 free (gfc_option
.module_dir
);
416 open_included_file (const char *name
, gfc_directorylist
*list
,
417 bool module
, bool system
)
420 gfc_directorylist
*p
;
423 for (p
= list
; p
; p
= p
->next
)
425 if (module
&& !p
->use_for_modules
)
428 fullname
= (char *) alloca(strlen (p
->path
) + strlen (name
) + 1);
429 strcpy (fullname
, p
->path
);
430 strcat (fullname
, name
);
432 f
= gfc_open_file (fullname
);
435 if (gfc_cpp_makedep ())
436 gfc_cpp_add_dep (fullname
, system
);
446 /* Opens file for reading, searching through the include directories
447 given if necessary. If the include_cwd argument is true, we try
448 to open the file in the current directory first. */
451 gfc_open_included_file (const char *name
, bool include_cwd
, bool module
)
455 if (IS_ABSOLUTE_PATH (name
) || include_cwd
)
457 f
= gfc_open_file (name
);
458 if (f
&& gfc_cpp_makedep ())
459 gfc_cpp_add_dep (name
, false);
463 f
= open_included_file (name
, include_dirs
, module
, false);
469 /* Test to see if we're at the end of the main source file. */
478 /* Test to see if we're at the end of the current file. */
486 if (line_head
== NULL
)
487 return 1; /* Null file */
489 if (gfc_current_locus
.lb
== NULL
)
496 /* Test to see if we're at the beginning of a new line. */
504 return (gfc_current_locus
.nextc
== gfc_current_locus
.lb
->line
);
508 /* Test to see if we're at the end of a line. */
516 return (*gfc_current_locus
.nextc
== '\0');
520 add_file_change (const char *filename
, int line
)
522 if (file_changes_count
== file_changes_allocated
)
524 if (file_changes_allocated
)
525 file_changes_allocated
*= 2;
527 file_changes_allocated
= 16;
528 file_changes
= XRESIZEVEC (struct gfc_file_change
, file_changes
,
529 file_changes_allocated
);
531 file_changes
[file_changes_count
].filename
= filename
;
532 file_changes
[file_changes_count
].lb
= NULL
;
533 file_changes
[file_changes_count
++].line
= line
;
537 report_file_change (gfc_linebuf
*lb
)
539 size_t c
= file_changes_cur
;
540 while (c
< file_changes_count
541 && file_changes
[c
].lb
== lb
)
543 if (file_changes
[c
].filename
)
544 (*debug_hooks
->start_source_file
) (file_changes
[c
].line
,
545 file_changes
[c
].filename
);
547 (*debug_hooks
->end_source_file
) (file_changes
[c
].line
);
550 file_changes_cur
= c
;
554 gfc_start_source_files (void)
556 /* If the debugger wants the name of the main source file,
558 if (debug_hooks
->start_end_main_source_file
)
559 (*debug_hooks
->start_source_file
) (0, gfc_source_file
);
561 file_changes_cur
= 0;
562 report_file_change (gfc_current_locus
.lb
);
566 gfc_end_source_files (void)
568 report_file_change (NULL
);
570 if (debug_hooks
->start_end_main_source_file
)
571 (*debug_hooks
->end_source_file
) (0);
574 /* Advance the current line pointer to the next line. */
577 gfc_advance_line (void)
582 if (gfc_current_locus
.lb
== NULL
)
588 if (gfc_current_locus
.lb
->next
589 && !gfc_current_locus
.lb
->next
->dbg_emitted
)
591 report_file_change (gfc_current_locus
.lb
->next
);
592 gfc_current_locus
.lb
->next
->dbg_emitted
= true;
595 gfc_current_locus
.lb
= gfc_current_locus
.lb
->next
;
597 if (gfc_current_locus
.lb
!= NULL
)
598 gfc_current_locus
.nextc
= gfc_current_locus
.lb
->line
;
601 gfc_current_locus
.nextc
= NULL
;
607 /* Get the next character from the input, advancing gfc_current_file's
608 locus. When we hit the end of the line or the end of the file, we
609 start returning a '\n' in order to complete the current statement.
610 No Fortran line conventions are implemented here.
612 Requiring explicit advances to the next line prevents the parse
613 pointer from being on the wrong line if the current statement ends
621 if (gfc_current_locus
.nextc
== NULL
)
624 c
= *gfc_current_locus
.nextc
++;
627 gfc_current_locus
.nextc
--; /* Remain on this line. */
635 /* Skip a comment. When we come here the parse pointer is positioned
636 immediately after the comment character. If we ever implement
637 compiler directives within comments, here is where we parse the
641 skip_comment_line (void)
656 gfc_define_undef_line (void)
660 /* All lines beginning with '#' are either #define or #undef. */
661 if (debug_info_level
!= DINFO_LEVEL_VERBOSE
|| gfc_peek_ascii_char () != '#')
664 if (wide_strncmp (gfc_current_locus
.nextc
, "#define ", 8) == 0)
666 tmp
= gfc_widechar_to_char (&gfc_current_locus
.nextc
[8], -1);
667 (*debug_hooks
->define
) (gfc_linebuf_linenum (gfc_current_locus
.lb
),
672 if (wide_strncmp (gfc_current_locus
.nextc
, "#undef ", 7) == 0)
674 tmp
= gfc_widechar_to_char (&gfc_current_locus
.nextc
[7], -1);
675 (*debug_hooks
->undef
) (gfc_linebuf_linenum (gfc_current_locus
.lb
),
680 /* Skip the rest of the line. */
681 skip_comment_line ();
687 /* Return true if GCC$ was matched. */
689 skip_gcc_attribute (locus start
)
693 locus old_loc
= gfc_current_locus
;
695 if ((c
= next_char ()) == 'g' || c
== 'G')
696 if ((c
= next_char ()) == 'c' || c
== 'C')
697 if ((c
= next_char ()) == 'c' || c
== 'C')
698 if ((c
= next_char ()) == '$')
702 gfc_current_locus
= old_loc
;
705 gcc_attribute_flag
= 1;
706 gcc_attribute_locus
= old_loc
;
707 gfc_current_locus
= start
;
713 /* Return true if CC was matched. */
715 skip_oacc_attribute (locus start
, locus old_loc
, bool continue_flag
)
720 if ((c
= next_char ()) == 'c' || c
== 'C')
721 if ((c
= next_char ()) == 'c' || c
== 'C')
726 if ((c
= next_char ()) == ' ' || c
== '\t'
729 while (gfc_is_whitespace (c
))
731 if (c
!= '\n' && c
!= '!')
734 openacc_locus
= old_loc
;
735 gfc_current_locus
= start
;
742 gfc_warning_now (0, "!$ACC at %C starts a commented "
743 "line as it neither is followed "
744 "by a space nor is a "
745 "continuation line");
753 /* Return true if MP was matched. */
755 skip_omp_attribute (locus start
, locus old_loc
, bool continue_flag
)
760 if ((c
= next_char ()) == 'm' || c
== 'M')
761 if ((c
= next_char ()) == 'p' || c
== 'P')
766 if ((c
= next_char ()) == ' ' || c
== '\t'
769 while (gfc_is_whitespace (c
))
771 if (c
!= '\n' && c
!= '!')
774 openmp_locus
= old_loc
;
775 gfc_current_locus
= start
;
782 gfc_warning_now (0, "!$OMP at %C starts a commented "
783 "line as it neither is followed "
784 "by a space nor is a "
785 "continuation line");
793 /* Comment lines are null lines, lines containing only blanks or lines
794 on which the first nonblank line is a '!'.
795 Return true if !$ openmp or openacc conditional compilation sentinel was
799 skip_free_comments (void)
807 at_bol
= gfc_at_bol ();
808 start
= gfc_current_locus
;
814 while (gfc_is_whitespace (c
));
824 /* Keep the !GCC$ line. */
825 if (at_bol
&& skip_gcc_attribute (start
))
828 /* If -fopenmp/-fopenacc, we need to handle here 2 things:
829 1) don't treat !$omp/!$acc as comments, but directives
830 2) handle OpenMP/OpenACC conditional compilation, where
831 !$ should be treated as 2 spaces (for initial lines
832 only if followed by space). */
835 if ((flag_openmp
|| flag_openmp_simd
)
838 locus old_loc
= gfc_current_locus
;
839 if (next_char () == '$')
842 if (c
== 'o' || c
== 'O')
844 if (skip_omp_attribute (start
, old_loc
, continue_flag
))
846 gfc_current_locus
= old_loc
;
850 else if (c
== 'a' || c
== 'A')
852 if (skip_oacc_attribute (start
, old_loc
, continue_flag
))
854 gfc_current_locus
= old_loc
;
858 if (continue_flag
|| c
== ' ' || c
== '\t')
860 gfc_current_locus
= old_loc
;
862 openmp_flag
= openacc_flag
= 0;
866 gfc_current_locus
= old_loc
;
868 else if ((flag_openmp
|| flag_openmp_simd
)
871 locus old_loc
= gfc_current_locus
;
872 if (next_char () == '$')
875 if (c
== 'o' || c
== 'O')
877 if (skip_omp_attribute (start
, old_loc
, continue_flag
))
879 gfc_current_locus
= old_loc
;
883 if (continue_flag
|| c
== ' ' || c
== '\t')
885 gfc_current_locus
= old_loc
;
891 gfc_current_locus
= old_loc
;
893 else if (flag_openacc
894 && !(flag_openmp
|| flag_openmp_simd
))
896 locus old_loc
= gfc_current_locus
;
897 if (next_char () == '$')
900 if (c
== 'a' || c
== 'A')
902 if (skip_oacc_attribute (start
, old_loc
,
905 gfc_current_locus
= old_loc
;
909 if (continue_flag
|| c
== ' ' || c
== '\t')
911 gfc_current_locus
= old_loc
;
917 gfc_current_locus
= old_loc
;
920 skip_comment_line ();
927 if (openmp_flag
&& at_bol
)
930 if (openacc_flag
&& at_bol
)
933 gcc_attribute_flag
= 0;
934 gfc_current_locus
= start
;
939 /* Skip comment lines in fixed source mode. We have the same rules as
940 in skip_free_comment(), except that we can have a 'c', 'C' or '*'
941 in column 1, and a '!' cannot be in column 6. Also, we deal with
942 lines with 'd' or 'D' in column 1, if the user requested this. */
945 skip_fixed_comments (void)
953 start
= gfc_current_locus
;
958 while (gfc_is_whitespace (c
));
963 skip_comment_line ();
968 gfc_current_locus
= start
;
975 start
= gfc_current_locus
;
986 if (c
== '!' || c
== 'c' || c
== 'C' || c
== '*')
988 if (skip_gcc_attribute (start
))
990 /* Canonicalize to *$omp. */
995 /* If -fopenmp/-fopenacc, we need to handle here 2 things:
996 1) don't treat !$omp/!$acc|c$omp/c$acc|*$omp / *$acc as comments,
998 2) handle OpenMP/OpenACC conditional compilation, where
999 !$|c$|*$ should be treated as 2 spaces if the characters
1000 in columns 3 to 6 are valid fixed form label columns
1002 if (gfc_current_locus
.lb
!= NULL
1003 && continue_line
< gfc_linebuf_linenum (gfc_current_locus
.lb
))
1004 continue_line
= gfc_linebuf_linenum (gfc_current_locus
.lb
);
1006 if (flag_openmp
|| flag_openmp_simd
)
1008 if (next_char () == '$')
1011 if (c
== 'o' || c
== 'O')
1013 if (((c
= next_char ()) == 'm' || c
== 'M')
1014 && ((c
= next_char ()) == 'p' || c
== 'P'))
1018 && ((openmp_flag
&& continue_flag
)
1019 || c
== ' ' || c
== '\t' || c
== '0'))
1023 while (gfc_is_whitespace (c
));
1024 if (c
!= '\n' && c
!= '!')
1026 /* Canonicalize to *$omp. */
1029 gfc_current_locus
= start
;
1039 for (col
= 3; col
< 6; col
++, c
= next_char ())
1047 else if (c
< '0' || c
> '9')
1052 if (col
== 6 && c
!= '\n'
1053 && ((continue_flag
&& !digit_seen
)
1054 || c
== ' ' || c
== '\t' || c
== '0'))
1056 gfc_current_locus
= start
;
1057 start
.nextc
[0] = ' ';
1058 start
.nextc
[1] = ' ';
1063 gfc_current_locus
= start
;
1068 if (next_char () == '$')
1071 if (c
== 'a' || c
== 'A')
1073 if (((c
= next_char ()) == 'c' || c
== 'C')
1074 && ((c
= next_char ()) == 'c' || c
== 'C'))
1078 && ((openacc_flag
&& continue_flag
)
1079 || c
== ' ' || c
== '\t' || c
== '0'))
1083 while (gfc_is_whitespace (c
));
1084 if (c
!= '\n' && c
!= '!')
1086 /* Canonicalize to *$acc. */
1089 gfc_current_locus
= start
;
1099 for (col
= 3; col
< 6; col
++, c
= next_char ())
1107 else if (c
< '0' || c
> '9')
1112 if (col
== 6 && c
!= '\n'
1113 && ((continue_flag
&& !digit_seen
)
1114 || c
== ' ' || c
== '\t' || c
== '0'))
1116 gfc_current_locus
= start
;
1117 start
.nextc
[0] = ' ';
1118 start
.nextc
[1] = ' ';
1123 gfc_current_locus
= start
;
1126 skip_comment_line ();
1130 if (gfc_option
.flag_d_lines
!= -1 && (c
== 'd' || c
== 'D'))
1132 if (gfc_option
.flag_d_lines
== 0)
1134 skip_comment_line ();
1138 *start
.nextc
= c
= ' ';
1143 while (gfc_is_whitespace (c
))
1151 gfc_advance_line ();
1155 if (col
!= 6 && c
== '!')
1157 if (gfc_current_locus
.lb
!= NULL
1158 && continue_line
< gfc_linebuf_linenum (gfc_current_locus
.lb
))
1159 continue_line
= gfc_linebuf_linenum (gfc_current_locus
.lb
);
1160 skip_comment_line ();
1169 gcc_attribute_flag
= 0;
1170 gfc_current_locus
= start
;
1174 /* Skips the current line if it is a comment. */
1177 gfc_skip_comments (void)
1179 if (gfc_current_form
== FORM_FREE
)
1180 skip_free_comments ();
1182 skip_fixed_comments ();
1186 /* Get the next character from the input, taking continuation lines
1187 and end-of-line comments into account. This implies that comment
1188 lines between continued lines must be eaten here. For higher-level
1189 subroutines, this flattens continued lines into a single logical
1190 line. The in_string flag denotes whether we're inside a character
1194 gfc_next_char_literal (gfc_instring in_string
)
1197 int i
, prev_openmp_flag
, prev_openacc_flag
;
1201 prev_openacc_flag
= prev_openmp_flag
= 0;
1211 if (gfc_current_form
== FORM_FREE
)
1213 bool openmp_cond_flag
;
1215 if (!in_string
&& c
== '!')
1217 if (gcc_attribute_flag
1218 && memcmp (&gfc_current_locus
, &gcc_attribute_locus
,
1219 sizeof (gfc_current_locus
)) == 0)
1223 && memcmp (&gfc_current_locus
, &openmp_locus
,
1224 sizeof (gfc_current_locus
)) == 0)
1228 && memcmp (&gfc_current_locus
, &openacc_locus
,
1229 sizeof (gfc_current_locus
)) == 0)
1232 /* This line can't be continued */
1239 /* Avoid truncation warnings for comment ending lines. */
1240 gfc_current_locus
.lb
->truncated
= 0;
1245 /* Check to see if the continuation line was truncated. */
1246 if (warn_line_truncation
&& gfc_current_locus
.lb
!= NULL
1247 && gfc_current_locus
.lb
->truncated
)
1249 int maxlen
= flag_free_line_length
;
1250 gfc_char_t
*current_nextc
= gfc_current_locus
.nextc
;
1252 gfc_current_locus
.lb
->truncated
= 0;
1253 gfc_current_locus
.nextc
= gfc_current_locus
.lb
->line
+ maxlen
;
1254 gfc_warning_now (OPT_Wline_truncation
,
1255 "Line truncated at %L", &gfc_current_locus
);
1256 gfc_current_locus
.nextc
= current_nextc
;
1262 /* If the next nonblank character is a ! or \n, we've got a
1263 continuation line. */
1264 old_loc
= gfc_current_locus
;
1267 while (gfc_is_whitespace (c
))
1270 /* Character constants to be continued cannot have commentary
1271 after the '&'. However, there are cases where we may think we
1272 are still in a string and we are looking for a possible
1273 doubled quote and we end up here. See PR64506. */
1275 if (in_string
&& c
!= '\n')
1277 gfc_current_locus
= old_loc
;
1282 if (c
!= '!' && c
!= '\n')
1284 gfc_current_locus
= old_loc
;
1290 prev_openmp_flag
= openmp_flag
;
1292 prev_openacc_flag
= openacc_flag
;
1296 skip_comment_line ();
1298 gfc_advance_line ();
1301 goto not_continuation
;
1303 /* We've got a continuation line. If we are on the very next line after
1304 the last continuation, increment the continuation line count and
1305 check whether the limit has been exceeded. */
1306 if (gfc_linebuf_linenum (gfc_current_locus
.lb
) == continue_line
+ 1)
1308 if (++continue_count
== gfc_option
.max_continue_free
)
1310 if (gfc_notification_std (GFC_STD_GNU
) || pedantic
)
1311 gfc_warning (0, "Limit of %d continuations exceeded in "
1312 "statement at %C", gfc_option
.max_continue_free
);
1316 /* Now find where it continues. First eat any comment lines. */
1317 openmp_cond_flag
= skip_free_comments ();
1319 if (gfc_current_locus
.lb
!= NULL
1320 && continue_line
< gfc_linebuf_linenum (gfc_current_locus
.lb
))
1321 continue_line
= gfc_linebuf_linenum (gfc_current_locus
.lb
);
1324 if (prev_openmp_flag
!= openmp_flag
)
1326 gfc_current_locus
= old_loc
;
1327 openmp_flag
= prev_openmp_flag
;
1333 if (prev_openacc_flag
!= openacc_flag
)
1335 gfc_current_locus
= old_loc
;
1336 openacc_flag
= prev_openacc_flag
;
1341 /* Now that we have a non-comment line, probe ahead for the
1342 first non-whitespace character. If it is another '&', then
1343 reading starts at the next character, otherwise we must back
1344 up to where the whitespace started and resume from there. */
1346 old_loc
= gfc_current_locus
;
1349 while (gfc_is_whitespace (c
))
1354 for (i
= 0; i
< 5; i
++, c
= next_char ())
1356 gcc_assert (gfc_wide_tolower (c
) == (unsigned char) "!$omp"[i
]);
1358 old_loc
= gfc_current_locus
;
1360 while (gfc_is_whitespace (c
))
1365 for (i
= 0; i
< 5; i
++, c
= next_char ())
1367 gcc_assert (gfc_wide_tolower (c
) == (unsigned char) "!$acc"[i
]);
1369 old_loc
= gfc_current_locus
;
1371 while (gfc_is_whitespace (c
))
1379 gfc_current_locus
.nextc
--;
1380 if (warn_ampersand
&& in_string
== INSTRING_WARN
)
1381 gfc_warning (OPT_Wampersand
,
1382 "Missing %<&%> in continued character "
1385 else if (!in_string
&& (c
== '\'' || c
== '"'))
1387 /* Both !$omp and !$ -fopenmp continuation lines have & on the
1388 continuation line only optionally. */
1389 else if (openmp_flag
|| openacc_flag
|| openmp_cond_flag
)
1390 gfc_current_locus
.nextc
--;
1394 gfc_current_locus
= old_loc
;
1399 else /* Fixed form. */
1401 /* Fixed form continuation. */
1402 if (in_string
!= INSTRING_WARN
&& c
== '!')
1404 /* Skip comment at end of line. */
1411 /* Avoid truncation warnings for comment ending lines. */
1412 gfc_current_locus
.lb
->truncated
= 0;
1418 /* Check to see if the continuation line was truncated. */
1419 if (warn_line_truncation
&& gfc_current_locus
.lb
!= NULL
1420 && gfc_current_locus
.lb
->truncated
)
1422 gfc_current_locus
.lb
->truncated
= 0;
1423 gfc_warning_now (OPT_Wline_truncation
,
1424 "Line truncated at %L", &gfc_current_locus
);
1428 prev_openmp_flag
= openmp_flag
;
1430 prev_openacc_flag
= openacc_flag
;
1433 old_loc
= gfc_current_locus
;
1435 gfc_advance_line ();
1436 skip_fixed_comments ();
1438 /* See if this line is a continuation line. */
1439 if (flag_openmp
&& openmp_flag
!= prev_openmp_flag
)
1441 openmp_flag
= prev_openmp_flag
;
1442 goto not_continuation
;
1444 if (flag_openacc
&& openacc_flag
!= prev_openacc_flag
)
1446 openacc_flag
= prev_openacc_flag
;
1447 goto not_continuation
;
1450 if (!openmp_flag
&& !openacc_flag
)
1451 for (i
= 0; i
< 5; i
++)
1455 goto not_continuation
;
1457 else if (openmp_flag
)
1458 for (i
= 0; i
< 5; i
++)
1461 if (gfc_wide_tolower (c
) != (unsigned char) "*$omp"[i
])
1462 goto not_continuation
;
1464 else if (openacc_flag
)
1465 for (i
= 0; i
< 5; i
++)
1468 if (gfc_wide_tolower (c
) != (unsigned char) "*$acc"[i
])
1469 goto not_continuation
;
1473 if (c
== '0' || c
== ' ' || c
== '\n')
1474 goto not_continuation
;
1476 /* We've got a continuation line. If we are on the very next line after
1477 the last continuation, increment the continuation line count and
1478 check whether the limit has been exceeded. */
1479 if (gfc_linebuf_linenum (gfc_current_locus
.lb
) == continue_line
+ 1)
1481 if (++continue_count
== gfc_option
.max_continue_fixed
)
1483 if (gfc_notification_std (GFC_STD_GNU
) || pedantic
)
1484 gfc_warning (0, "Limit of %d continuations exceeded in "
1486 gfc_option
.max_continue_fixed
);
1490 if (gfc_current_locus
.lb
!= NULL
1491 && continue_line
< gfc_linebuf_linenum (gfc_current_locus
.lb
))
1492 continue_line
= gfc_linebuf_linenum (gfc_current_locus
.lb
);
1495 /* Ready to read first character of continuation line, which might
1496 be another continuation line! */
1501 gfc_current_locus
= old_loc
;
1511 /* Get the next character of input, folded to lowercase. In fixed
1512 form mode, we also ignore spaces. When matcher subroutines are
1513 parsing character literals, they have to call
1514 gfc_next_char_literal(). */
1517 gfc_next_char (void)
1523 c
= gfc_next_char_literal (NONSTRING
);
1525 while (gfc_current_form
== FORM_FIXED
&& gfc_is_whitespace (c
));
1527 return gfc_wide_tolower (c
);
1531 gfc_next_ascii_char (void)
1533 gfc_char_t c
= gfc_next_char ();
1535 return (gfc_wide_fits_in_byte (c
) ? (unsigned char) c
1536 : (unsigned char) UCHAR_MAX
);
1541 gfc_peek_char (void)
1546 old_loc
= gfc_current_locus
;
1547 c
= gfc_next_char ();
1548 gfc_current_locus
= old_loc
;
1555 gfc_peek_ascii_char (void)
1557 gfc_char_t c
= gfc_peek_char ();
1559 return (gfc_wide_fits_in_byte (c
) ? (unsigned char) c
1560 : (unsigned char) UCHAR_MAX
);
1564 /* Recover from an error. We try to get past the current statement
1565 and get lined up for the next. The next statement follows a '\n'
1566 or a ';'. We also assume that we are not within a character
1567 constant, and deal with finding a '\'' or '"'. */
1570 gfc_error_recovery (void)
1572 gfc_char_t c
, delim
;
1579 c
= gfc_next_char ();
1580 if (c
== '\n' || c
== ';')
1583 if (c
!= '\'' && c
!= '"')
1612 /* Read ahead until the next character to be read is not whitespace. */
1615 gfc_gobble_whitespace (void)
1617 static int linenum
= 0;
1623 old_loc
= gfc_current_locus
;
1624 c
= gfc_next_char_literal (NONSTRING
);
1625 /* Issue a warning for nonconforming tabs. We keep track of the line
1626 number because the Fortran matchers will often back up and the same
1627 line will be scanned multiple times. */
1628 if (warn_tabs
&& c
== '\t')
1630 int cur_linenum
= LOCATION_LINE (gfc_current_locus
.lb
->location
);
1631 if (cur_linenum
!= linenum
)
1633 linenum
= cur_linenum
;
1634 gfc_warning_now (OPT_Wtabs
, "Nonconforming tab character at %C");
1638 while (gfc_is_whitespace (c
));
1640 gfc_current_locus
= old_loc
;
1644 /* Load a single line into pbuf.
1646 If pbuf points to a NULL pointer, it is allocated.
1647 We truncate lines that are too long, unless we're dealing with
1648 preprocessor lines or if the option -ffixed-line-length-none is set,
1649 in which case we reallocate the buffer to fit the entire line, if
1651 In fixed mode, we expand a tab that occurs within the statement
1652 label region to expand to spaces that leave the next character in
1655 If first_char is not NULL, it's a pointer to a single char value holding
1656 the first character of the line, which has already been read by the
1657 caller. This avoids the use of ungetc().
1659 load_line returns whether the line was truncated.
1661 NOTE: The error machinery isn't available at this point, so we can't
1662 easily report line and column numbers consistent with other
1663 parts of gfortran. */
1666 load_line (FILE *input
, gfc_char_t
**pbuf
, int *pbuflen
, const int *first_char
)
1668 static int linenum
= 0, current_line
= 1;
1669 int c
, maxlen
, i
, preprocessor_flag
, buflen
= *pbuflen
;
1670 int trunc_flag
= 0, seen_comment
= 0;
1671 int seen_printable
= 0, seen_ampersand
= 0, quoted
= ' ';
1673 bool found_tab
= false;
1675 /* Determine the maximum allowed line length. */
1676 if (gfc_current_form
== FORM_FREE
)
1677 maxlen
= flag_free_line_length
;
1678 else if (gfc_current_form
== FORM_FIXED
)
1679 maxlen
= flag_fixed_line_length
;
1685 /* Allocate the line buffer, storing its length into buflen.
1686 Note that if maxlen==0, indicating that arbitrary-length lines
1687 are allowed, the buffer will be reallocated if this length is
1688 insufficient; since 132 characters is the length of a standard
1689 free-form line, we use that as a starting guess. */
1695 *pbuf
= gfc_get_wide_string (buflen
+ 1);
1706 /* In order to not truncate preprocessor lines, we have to
1707 remember that this is one. */
1708 preprocessor_flag
= (c
== '#' ? 1 : 0);
1717 /* Check for illegal use of ampersand. See F95 Standard 3.3.1.3. */
1718 if (gfc_current_form
== FORM_FREE
1719 && !seen_printable
&& seen_ampersand
)
1722 gfc_error_now ("%<&%> not allowed by itself in line %d",
1725 gfc_warning_now (0, "%<&%> not allowed by itself in line %d",
1731 if (c
== '\r' || c
== '\0')
1732 goto next_char
; /* Gobble characters. */
1745 if ((c
!= '&' && c
!= '!' && c
!= ' ') || (c
== '!' && !seen_ampersand
))
1748 /* Is this a fixed-form comment? */
1749 if (gfc_current_form
== FORM_FIXED
&& i
== 0
1750 && (c
== '*' || c
== 'c' || c
== 'd'))
1755 if (c
== '\'' || c
== '"')
1758 else if (c
== quoted
)
1761 /* Is this a free-form comment? */
1762 if (c
== '!' && quoted
== ' ')
1765 /* Vendor extension: "<tab>1" marks a continuation line. */
1769 if (c
>= '1' && c
<= '9')
1776 if (gfc_current_form
== FORM_FIXED
&& c
== '\t' && i
< 6)
1780 if (warn_tabs
&& seen_comment
== 0 && current_line
!= linenum
)
1782 linenum
= current_line
;
1783 gfc_warning_now (OPT_Wtabs
,
1784 "Nonconforming tab character in column %d "
1785 "of line %d", i
+1, linenum
);
1800 if (maxlen
== 0 || preprocessor_flag
)
1804 /* Reallocate line buffer to double size to hold the
1806 buflen
= buflen
* 2;
1807 *pbuf
= XRESIZEVEC (gfc_char_t
, *pbuf
, (buflen
+ 1));
1808 buffer
= (*pbuf
) + i
;
1811 else if (i
>= maxlen
)
1813 bool trunc_warn
= true;
1815 /* Enhancement, if the very next non-space character is an ampersand
1816 or comment that we would otherwise warn about, don't mark as
1819 /* Truncate the rest of the line. */
1823 if (c
== '\r' || c
== ' ')
1826 if (c
== '\n' || c
== EOF
)
1829 if (!trunc_warn
&& c
!= '!')
1832 if (trunc_warn
&& ((gfc_current_form
== FORM_FIXED
&& c
== '&')
1839 if (trunc_warn
&& !seen_comment
)
1851 /* Pad lines to the selected line length in fixed form. */
1852 if (gfc_current_form
== FORM_FIXED
1853 && flag_fixed_line_length
!= 0
1854 && !preprocessor_flag
1857 while (i
++ < maxlen
)
1869 /* Get a gfc_file structure, initialize it and add it to
1873 get_file (const char *name
, enum lc_reason reason ATTRIBUTE_UNUSED
)
1877 f
= XCNEW (gfc_file
);
1879 f
->filename
= xstrdup (name
);
1881 f
->next
= file_head
;
1884 f
->up
= current_file
;
1885 if (current_file
!= NULL
)
1886 f
->inclusion_line
= current_file
->line
;
1888 linemap_add (line_table
, reason
, false, f
->filename
, 1);
1894 /* Deal with a line from the C preprocessor. The
1895 initial octothorp has already been seen. */
1898 preprocessor_line (gfc_char_t
*c
)
1902 gfc_char_t
*wide_filename
;
1904 int escaped
, unescape
;
1908 while (*c
== ' ' || *c
== '\t')
1911 if (*c
< '0' || *c
> '9')
1914 line
= wide_atoi (c
);
1916 c
= wide_strchr (c
, ' ');
1919 /* No file name given. Set new line number. */
1920 current_file
->line
= line
;
1925 while (*c
== ' ' || *c
== '\t')
1935 /* Make filename end at quote. */
1938 while (*c
&& ! (!escaped
&& *c
== '"'))
1942 else if (*c
== '\\')
1951 /* Preprocessor line has no closing quote. */
1956 /* Undo effects of cpp_quote_string. */
1959 gfc_char_t
*s
= wide_filename
;
1960 gfc_char_t
*d
= gfc_get_wide_string (c
- wide_filename
- unescape
);
1976 flag
[1] = flag
[2] = flag
[3] = flag
[4] = false;
1980 c
= wide_strchr (c
, ' ');
1987 if (1 <= i
&& i
<= 4)
1991 /* Convert the filename in wide characters into a filename in narrow
1993 filename
= gfc_widechar_to_char (wide_filename
, -1);
1995 /* Interpret flags. */
1997 if (flag
[1]) /* Starting new file. */
1999 f
= get_file (filename
, LC_RENAME
);
2000 add_file_change (f
->filename
, f
->inclusion_line
);
2004 if (flag
[2]) /* Ending current file. */
2006 if (!current_file
->up
2007 || filename_cmp (current_file
->up
->filename
, filename
) != 0)
2009 linemap_line_start (line_table
, current_file
->line
, 80);
2010 /* ??? One could compute the exact column where the filename
2011 starts and compute the exact location here. */
2012 gfc_warning_now_at (linemap_position_for_column (line_table
, 1),
2013 0, "file %qs left but not entered",
2015 current_file
->line
++;
2017 free (wide_filename
);
2022 add_file_change (NULL
, line
);
2023 current_file
= current_file
->up
;
2024 linemap_add (line_table
, LC_RENAME
, false, current_file
->filename
,
2025 current_file
->line
);
2028 /* The name of the file can be a temporary file produced by
2029 cpp. Replace the name if it is different. */
2031 if (filename_cmp (current_file
->filename
, filename
) != 0)
2033 /* FIXME: we leak the old filename because a pointer to it may be stored
2034 in the linemap. Alternative could be using GC or updating linemap to
2035 point to the new name, but there is no API for that currently. */
2036 current_file
->filename
= xstrdup (filename
);
2039 /* Set new line number. */
2040 current_file
->line
= line
;
2042 free (wide_filename
);
2047 linemap_line_start (line_table
, current_file
->line
, 80);
2048 /* ??? One could compute the exact column where the directive
2049 starts and compute the exact location here. */
2050 gfc_warning_now_at (linemap_position_for_column (line_table
, 2), 0,
2051 "Illegal preprocessor directive");
2052 current_file
->line
++;
2056 static bool load_file (const char *, const char *, bool);
2058 /* include_line()-- Checks a line buffer to see if it is an include
2059 line. If so, we call load_file() recursively to load the included
2060 file. We never return a syntax error because a statement like
2061 "include = 5" is perfectly legal. We return false if no include was
2062 processed or true if we matched an include. */
2065 include_line (gfc_char_t
*line
)
2067 gfc_char_t quote
, *c
, *begin
, *stop
;
2072 if (flag_openmp
|| flag_openmp_simd
)
2074 if (gfc_current_form
== FORM_FREE
)
2076 while (*c
== ' ' || *c
== '\t')
2078 if (*c
== '!' && c
[1] == '$' && (c
[2] == ' ' || c
[2] == '\t'))
2083 if ((*c
== '!' || *c
== 'c' || *c
== 'C' || *c
== '*')
2084 && c
[1] == '$' && (c
[2] == ' ' || c
[2] == '\t'))
2089 while (*c
== ' ' || *c
== '\t')
2092 if (gfc_wide_strncasecmp (c
, "include", 7))
2096 while (*c
== ' ' || *c
== '\t')
2099 /* Find filename between quotes. */
2102 if (quote
!= '"' && quote
!= '\'')
2107 while (*c
!= quote
&& *c
!= '\0')
2115 while (*c
== ' ' || *c
== '\t')
2118 if (*c
!= '\0' && *c
!= '!')
2121 /* We have an include line at this point. */
2123 *stop
= '\0'; /* It's ok to trash the buffer, as this line won't be
2124 read by anything else. */
2126 filename
= gfc_widechar_to_char (begin
, -1);
2127 if (!load_file (filename
, NULL
, false))
2128 exit (FATAL_EXIT_CODE
);
2135 /* Load a file into memory by calling load_line until the file ends. */
2138 load_file (const char *realfilename
, const char *displayedname
, bool initial
)
2146 const char *filename
;
2147 /* If realfilename and displayedname are different and non-null then
2148 surely realfilename is the preprocessed form of
2150 bool preprocessed_p
= (realfilename
&& displayedname
2151 && strcmp (realfilename
, displayedname
));
2153 filename
= displayedname
? displayedname
: realfilename
;
2155 for (f
= current_file
; f
; f
= f
->up
)
2156 if (filename_cmp (filename
, f
->filename
) == 0)
2158 fprintf (stderr
, "%s:%d: Error: File '%s' is being included "
2159 "recursively\n", current_file
->filename
, current_file
->line
,
2168 input
= gfc_src_file
;
2169 gfc_src_file
= NULL
;
2172 input
= gfc_open_file (realfilename
);
2175 gfc_error_now ("Can't open file %qs", filename
);
2181 input
= gfc_open_included_file (realfilename
, false, false);
2184 fprintf (stderr
, "%s:%d: Error: Can't open included file '%s'\n",
2185 current_file
->filename
, current_file
->line
, filename
);
2192 A "non-initial" file means a file that is being included. In
2193 that case we are creating an LC_ENTER map.
2195 An "initial" file means a main file; one that is not included.
2196 That file has already got at least one (surely more) line map(s)
2197 created by gfc_init. So the subsequent map created in that case
2198 must have LC_RENAME reason.
2200 This latter case is not true for a preprocessed file. In that
2201 case, although the file is "initial", the line maps created by
2202 gfc_init was used during the preprocessing of the file. Now that
2203 the preprocessing is over and we are being fed the result of that
2204 preprocessing, we need to create a brand new line map for the
2205 preprocessed file, so the reason is going to be LC_ENTER. */
2207 f
= get_file (filename
, (initial
&& !preprocessed_p
) ? LC_RENAME
: LC_ENTER
);
2209 add_file_change (f
->filename
, f
->inclusion_line
);
2211 current_file
->line
= 1;
2216 if (initial
&& gfc_src_preprocessor_lines
[0])
2218 preprocessor_line (gfc_src_preprocessor_lines
[0]);
2219 free (gfc_src_preprocessor_lines
[0]);
2220 gfc_src_preprocessor_lines
[0] = NULL
;
2221 if (gfc_src_preprocessor_lines
[1])
2223 preprocessor_line (gfc_src_preprocessor_lines
[1]);
2224 free (gfc_src_preprocessor_lines
[1]);
2225 gfc_src_preprocessor_lines
[1] = NULL
;
2231 int trunc
= load_line (input
, &line
, &line_len
, NULL
);
2233 len
= gfc_wide_strlen (line
);
2234 if (feof (input
) && len
== 0)
2237 /* If this is the first line of the file, it can contain a byte
2238 order mark (BOM), which we will ignore:
2239 FF FE is UTF-16 little endian,
2240 FE FF is UTF-16 big endian,
2241 EF BB BF is UTF-8. */
2243 && ((line_len
>= 2 && line
[0] == (unsigned char) '\xFF'
2244 && line
[1] == (unsigned char) '\xFE')
2245 || (line_len
>= 2 && line
[0] == (unsigned char) '\xFE'
2246 && line
[1] == (unsigned char) '\xFF')
2247 || (line_len
>= 3 && line
[0] == (unsigned char) '\xEF'
2248 && line
[1] == (unsigned char) '\xBB'
2249 && line
[2] == (unsigned char) '\xBF')))
2251 int n
= line
[1] == (unsigned char) '\xBB' ? 3 : 2;
2252 gfc_char_t
*new_char
= gfc_get_wide_string (line_len
);
2254 wide_strcpy (new_char
, &line
[n
]);
2260 /* There are three things this line can be: a line of Fortran
2261 source, an include line or a C preprocessor directive. */
2265 /* When -g3 is specified, it's possible that we emit #define
2266 and #undef lines, which we need to pass to the middle-end
2267 so that it can emit correct debug info. */
2268 if (debug_info_level
== DINFO_LEVEL_VERBOSE
2269 && (wide_strncmp (line
, "#define ", 8) == 0
2270 || wide_strncmp (line
, "#undef ", 7) == 0))
2274 preprocessor_line (line
);
2279 /* Preprocessed files have preprocessor lines added before the byte
2280 order mark, so first_line is not about the first line of the file
2281 but the first line that's not a preprocessor line. */
2284 if (include_line (line
))
2286 current_file
->line
++;
2292 b
= XCNEWVAR (gfc_linebuf
, gfc_linebuf_header_size
2293 + (len
+ 1) * sizeof (gfc_char_t
));
2297 = linemap_line_start (line_table
, current_file
->line
++, len
);
2298 /* ??? We add the location for the maximum column possible here,
2299 because otherwise if the next call creates a new line-map, it
2300 will not reserve space for any offset. */
2302 linemap_position_for_column (line_table
, len
);
2304 b
->file
= current_file
;
2305 b
->truncated
= trunc
;
2306 wide_strcpy (b
->line
, line
);
2308 if (line_head
== NULL
)
2311 line_tail
->next
= b
;
2315 while (file_changes_cur
< file_changes_count
)
2316 file_changes
[file_changes_cur
++].lb
= b
;
2319 /* Release the line buffer allocated in load_line. */
2325 add_file_change (NULL
, current_file
->inclusion_line
+ 1);
2326 current_file
= current_file
->up
;
2327 linemap_add (line_table
, LC_LEAVE
, 0, NULL
, 0);
2332 /* Open a new file and start scanning from that file. Returns true
2333 if everything went OK, false otherwise. If form == FORM_UNKNOWN
2334 it tries to determine the source form from the filename, defaulting
2342 if (gfc_cpp_enabled ())
2344 result
= gfc_cpp_preprocess (gfc_source_file
);
2345 if (!gfc_cpp_preprocess_only ())
2346 result
= load_file (gfc_cpp_temporary_file (), gfc_source_file
, true);
2349 result
= load_file (gfc_source_file
, NULL
, true);
2351 gfc_current_locus
.lb
= line_head
;
2352 gfc_current_locus
.nextc
= (line_head
== NULL
) ? NULL
: line_head
->line
;
2354 #if 0 /* Debugging aid. */
2355 for (; line_head
; line_head
= line_head
->next
)
2356 printf ("%s:%3d %s\n", LOCATION_FILE (line_head
->location
),
2357 LOCATION_LINE (line_head
->location
), line_head
->line
);
2359 exit (SUCCESS_EXIT_CODE
);
2366 unescape_filename (const char *ptr
)
2368 const char *p
= ptr
, *s
;
2370 int escaped
, unescape
= 0;
2372 /* Make filename end at quote. */
2374 while (*p
&& ! (! escaped
&& *p
== '"'))
2378 else if (*p
== '\\')
2389 /* Undo effects of cpp_quote_string. */
2391 d
= XCNEWVEC (char, p
+ 1 - ptr
- unescape
);
2406 /* For preprocessed files, if the first tokens are of the form # NUM.
2407 handle the directives so we know the original file name. */
2410 gfc_read_orig_filename (const char *filename
, const char **canon_source_file
)
2413 char *dirname
, *tmp
;
2415 gfc_src_file
= gfc_open_file (filename
);
2416 if (gfc_src_file
== NULL
)
2419 c
= getc (gfc_src_file
);
2425 load_line (gfc_src_file
, &gfc_src_preprocessor_lines
[0], &len
, &c
);
2427 if (wide_strncmp (gfc_src_preprocessor_lines
[0], "# 1 \"", 5) != 0)
2430 tmp
= gfc_widechar_to_char (&gfc_src_preprocessor_lines
[0][5], -1);
2431 filename
= unescape_filename (tmp
);
2433 if (filename
== NULL
)
2436 c
= getc (gfc_src_file
);
2442 load_line (gfc_src_file
, &gfc_src_preprocessor_lines
[1], &len
, &c
);
2444 if (wide_strncmp (gfc_src_preprocessor_lines
[1], "# 1 \"", 5) != 0)
2447 tmp
= gfc_widechar_to_char (&gfc_src_preprocessor_lines
[1][5], -1);
2448 dirname
= unescape_filename (tmp
);
2450 if (dirname
== NULL
)
2453 len
= strlen (dirname
);
2454 if (len
< 3 || dirname
[len
- 1] != '/' || dirname
[len
- 2] != '/')
2459 dirname
[len
- 2] = '\0';
2460 set_src_pwd (dirname
);
2462 if (! IS_ABSOLUTE_PATH (filename
))
2464 char *p
= XCNEWVEC (char, len
+ strlen (filename
));
2466 memcpy (p
, dirname
, len
- 2);
2468 strcpy (p
+ len
- 1, filename
);
2469 *canon_source_file
= p
;