This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Warning/error mechanism in libgfortran


Hi all,

attached patch and new file compile_options.c is the basis of a mechanism for issuing warnings and errors about standard conformance.

The interface between the library and the generated is the set_std function (exported as _gfortran_set_std). This function should be called by the generated code to tell the library what standard is used. Two questions are not yet answered:

1. Whether this function call should be done for each subroutine (since there can be a F77 subroutine and a F95 one), or only once for the whole program.

2. What code should be added to the front-end so that it issues the generated code for this function call? The prototype is:
void _gfortran_set_std (const int, const int)
the first argument should be gfc_option.warn_std and the second one gfc_option.allow_std.



I'd say that once question 2 is answered, I can do some profiling on point 1.


FX
? libgfortran/runtime/compile_options.c
Index: libgfortran/Makefile.am
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/Makefile.am,v
retrieving revision 1.36
diff -u -3 -p -r1.36 Makefile.am
--- libgfortran/Makefile.am	11 Jun 2005 19:39:09 -0000	1.36
+++ libgfortran/Makefile.am	18 Jun 2005 10:59:47 -0000
@@ -94,6 +94,7 @@ runtime/in_unpack_generic.c \
 runtime/normalize.c
 
 gfor_src= \
+runtime/compile_options.c \
 runtime/environ.c \
 runtime/error.c \
 runtime/main.c \
Index: libgfortran/libgfortran.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/libgfortran.h,v
retrieving revision 1.25
diff -u -3 -p -r1.25 libgfortran.h
--- libgfortran/libgfortran.h	11 Jun 2005 19:39:09 -0000	1.25
+++ libgfortran/libgfortran.h	18 Jun 2005 10:59:47 -0000
@@ -314,11 +314,25 @@ typedef struct
 }
 options_t;
 
-
 extern options_t options;
 internal_proto(options);
 
 
+/* Compile-time options that will influence the library.  */
+
+typedef struct
+{
+  int warn_std;
+  int allow_std;
+}
+compile_options_t;
+
+extern compile_options_t compile_options;
+internal_proto(compile_options);
+
+
+
+
 /* Structure for statement options.  */
 
 typedef struct
@@ -353,6 +367,18 @@ typedef enum
 error_codes;
 
 
+/* Flags to specify which standard/extension contains a feature.
+   Keep them in sync with their counterparts in gcc/fortran/gfortran.h.  */
+#define GFC_STD_LEGACY          (1<<6) /* Backward compatibility.  */
+#define GFC_STD_GNU             (1<<5)    /* GNU Fortran extension.  */
+#define GFC_STD_F2003           (1<<4)    /* New in F2003.  */
+/* Note that no features were obsoleted nor deleted in F2003.  */
+#define GFC_STD_F95             (1<<3)    /* New in F95.  */
+#define GFC_STD_F95_DEL         (1<<2)    /* Deleted in F95.  */
+#define GFC_STD_F95_OBS         (1<<1)    /* Obsoleted in F95.  */
+#define GFC_STD_F77             (1<<0)    /* Up to and including F77.  */
+
+
 /* The filename and line number don't go inside the globals structure.
    They are set by the rest of the program and must be linked to.  */
 
Index: libgfortran/io/format.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/io/format.c,v
retrieving revision 1.13
diff -u -3 -p -r1.13 format.c
--- libgfortran/io/format.c	29 May 2005 12:22:49 -0000	1.13
+++ libgfortran/io/format.c	18 Jun 2005 10:59:48 -0000
@@ -580,6 +580,7 @@ parse_format_list (void)
     case FMT_DOLLAR:
       get_fnode (&head, &tail, FMT_DOLLAR);
       tail->repeat = 1;
+      notify_std (GFC_STD_GNU, "Extension: $ descriptor");
       goto between_desc;
 
     case FMT_T:
Index: libgfortran/runtime/error.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/runtime/error.c,v
retrieving revision 1.9
diff -u -3 -p -r1.9 error.c
--- libgfortran/runtime/error.c	12 Jan 2005 21:27:31 -0000	1.9
+++ libgfortran/runtime/error.c	18 Jun 2005 10:59:48 -0000
@@ -488,3 +488,28 @@ generate_error (int family, const char *
 
   runtime_error (message);
 }
+
+
+
+/* Possibly issue a warning/error about use of a nonstandard (or deleted)
+   feature.  An error/warning will be issued if the currently selected
+   standard does not contain the requested bits.  */
+
+void
+notify_std (int std, const char * message)
+{
+  int warning;
+
+  warning = compile_options.warn_std & std;
+  if ((compile_options.allow_std & std) != 0 && !warning)
+    return;
+
+  show_locus ();
+  if (!warning)
+    {
+      st_printf ("Fortran runtime error: %s\n", message);
+      sys_exit (2);
+    }
+  else
+    st_printf ("Fortran runtime warning: %s\n", message);
+}
Index: libgfortran/runtime/main.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/runtime/main.c,v
retrieving revision 1.7
diff -u -3 -p -r1.7 main.c
--- libgfortran/runtime/main.c	15 May 2005 12:44:39 -0000	1.7
+++ libgfortran/runtime/main.c	18 Jun 2005 10:59:48 -0000
@@ -96,6 +96,7 @@ init (void)
   init_variables ();
 
   init_units ();
+  init_compile_options ();
 
 #ifdef DEBUG
   /* Check for special command lines.  */
/* Handling of compile-time options that influence the library.
   Copyright (C) 2005 Free Software Foundation, Inc.

This file is part of the GNU Fortran 95 runtime library (libgfortran).

Libgfortran is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file.  (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)

Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with libgfortran; see the file COPYING.  If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */

#include "config.h"

#include "libgfortran.h"


/* Useful compile-time options will be stored in here.  */
compile_options_t compile_options;


/* Prototypes */
extern void set_std (int, int);
export_proto(set_std);


void
set_std (const int warn_std, const int allow_std)
{
  compile_options.warn_std = warn_std;
  compile_options.allow_std = allow_std;
}


/* Default values for the compile-time options.  Keep in sync with
   gcc/fortran/options.c (gfc_init_options).  */
void
init_compile_options (void)
{
  compile_options.warn_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
    | GFC_STD_F2003 | GFC_STD_LEGACY;
  compile_options.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
    | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F77 | GFC_STD_GNU | GFC_STD_LEGACY;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]