summaryrefslogtreecommitdiff
path: root/gcc/fortran/scanner.c
diff options
context:
space:
mode:
authorfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>2006-11-17 11:11:25 +0000
committerfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>2006-11-17 11:11:25 +0000
commit99227731b0f74729e239b2bd3c3450c1f98d7700 (patch)
tree2eedcb4f55a3cf78d29fa8c589d673751e940362 /gcc/fortran/scanner.c
parentf0903548b3287506d5f909fccde02f55b9c582c1 (diff)
downloadgcc-99227731b0f74729e239b2bd3c3450c1f98d7700.tar.gz
* gfortran.h (gfc_add_intrinsic_modules_path,
gfc_open_intrinsic_module): New prototypes. (gfc_add_include_path, gfc_open_included_file): Update prototypes. * lang.opt: Add -fintrinsic-modules-path option. * module.c (gfc_match_use): Match the Fortran 2003 form of USE statement. (gfc_use_module): Also handle intrinsic modules. * scanner.c (gfc_directorylist): Add use_for_modules for field. (intrinsic_modules_dirs): New static variable. (add_path_to_list, gfc_add_intrinsic_modules_path): New functions. (gfc_add_include_path): Use the new add_path_to_list helper function. (gfc_release_include_path): Free memory for intrinsic_modules_dirs. (open_included_file, gfc_open_intrinsic_module): New functions. (gfc_open_included_file): Use the new open_included_file helper function. * lang-specs.h: Use the new -fintrinsic-modules-path option. * parse.c (decode_statement): Do not match the required space after USE here. * options.c (gfc_handle_option): Handle the new option. Use new prototype for gfc_add_include_path. (gfc_post_options): Use new prototype for gfc_add_include_path. * gfortran.dg/use_1.f90: New test. * gfortran.dg/use_1.f90: New test. * gfortran.dg/use_1.f90: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@118930 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fortran/scanner.c')
-rw-r--r--gcc/fortran/scanner.c85
1 files changed, 64 insertions, 21 deletions
diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c
index 92ee3661480..30d9b6f3b2c 100644
--- a/gcc/fortran/scanner.c
+++ b/gcc/fortran/scanner.c
@@ -51,12 +51,13 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
typedef struct gfc_directorylist
{
char *path;
+ bool use_for_modules;
struct gfc_directorylist *next;
}
gfc_directorylist;
/* List of include file search directories. */
-static gfc_directorylist *include_dirs;
+static gfc_directorylist *include_dirs, *intrinsic_modules_dirs;
static gfc_file *file_head, *current_file;
@@ -118,22 +119,21 @@ gfc_scanner_done_1 (void)
/* Adds path to the list pointed to by list. */
-void
-gfc_add_include_path (const char *path)
+static void
+add_path_to_list (gfc_directorylist **list, const char *path,
+ bool use_for_modules)
{
gfc_directorylist *dir;
const char *p;
p = path;
- while (*p == ' ' || *p == '\t') /* someone might do 'gfortran "-I include"' */
+ while (*p == ' ' || *p == '\t') /* someone might do "-I include" */
if (*p++ == '\0')
return;
- dir = include_dirs;
+ dir = *list;
if (!dir)
- {
- dir = include_dirs = gfc_getmem (sizeof (gfc_directorylist));
- }
+ dir = *list = gfc_getmem (sizeof (gfc_directorylist));
else
{
while (dir->next)
@@ -144,12 +144,27 @@ gfc_add_include_path (const char *path)
}
dir->next = NULL;
+ dir->use_for_modules = use_for_modules;
dir->path = gfc_getmem (strlen (p) + 2);
strcpy (dir->path, p);
strcat (dir->path, "/"); /* make '/' last character */
}
+void
+gfc_add_include_path (const char *path, bool use_for_modules)
+{
+ add_path_to_list (&include_dirs, path, use_for_modules);
+}
+
+
+void
+gfc_add_intrinsic_modules_path (const char *path)
+{
+ add_path_to_list (&intrinsic_modules_dirs, path, true);
+}
+
+
/* Release resources allocated for options. */
void
@@ -165,28 +180,30 @@ gfc_release_include_path (void)
gfc_free (p->path);
gfc_free (p);
}
+
+ gfc_free (gfc_option.module_dir);
+ while (intrinsic_modules_dirs != NULL)
+ {
+ p = intrinsic_modules_dirs;
+ intrinsic_modules_dirs = intrinsic_modules_dirs->next;
+ gfc_free (p->path);
+ gfc_free (p);
+ }
}
-/* Opens file for reading, searching through the include directories
- given if necessary. If the include_cwd argument is true, we try
- to open the file in the current directory first. */
-FILE *
-gfc_open_included_file (const char *name, const bool include_cwd)
+static FILE *
+open_included_file (const char *name, gfc_directorylist *list, bool module)
{
char *fullname;
gfc_directorylist *p;
FILE *f;
- if (include_cwd)
+ for (p = list; p; p = p->next)
{
- f = gfc_open_file (name);
- if (f != NULL)
- return f;
- }
+ if (module && !p->use_for_modules)
+ continue;
- for (p = include_dirs; p; p = p->next)
- {
fullname = (char *) alloca(strlen (p->path) + strlen (name) + 1);
strcpy (fullname, p->path);
strcat (fullname, name);
@@ -199,6 +216,32 @@ gfc_open_included_file (const char *name, const bool include_cwd)
return NULL;
}
+
+/* Opens file for reading, searching through the include directories
+ given if necessary. If the include_cwd argument is true, we try
+ to open the file in the current directory first. */
+
+FILE *
+gfc_open_included_file (const char *name, bool include_cwd, bool module)
+{
+ FILE *f;
+
+ if (include_cwd)
+ {
+ f = gfc_open_file (name);
+ if (f != NULL)
+ return f;
+ }
+
+ return open_included_file (name, include_dirs, module);
+}
+
+FILE *
+gfc_open_intrinsic_module (const char *name)
+{
+ return open_included_file (name, intrinsic_modules_dirs, true);
+}
+
/* Test to see if we're at the end of the main source file. */
int
@@ -1393,7 +1436,7 @@ load_file (const char *filename, bool initial)
}
else
{
- input = gfc_open_included_file (filename, false);
+ input = gfc_open_included_file (filename, false, false);
if (input == NULL)
{
gfc_error_now ("Can't open included file '%s'", filename);