This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, Fortran] ABSTRACT INTERFACE
- From: Uros Bizjak <ubizjak at gmail dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Fortran List <fortran at gcc dot gnu dot org>, Tobias Burnus <burnus at net-b dot de>, Tobias Schlüter <tobias dot schlueter at physik dot uni-muenchen dot de>, Janus Weil <jaydub66 at googlemail dot com>
- Date: Sun, 19 Aug 2007 11:20:04 +0200
- Subject: Re: [PATCH, Fortran] ABSTRACT INTERFACE
Hello!
+/* Tests whether name is the name of an intrinsic type. If it is
+ the passed error_message is printed and TRUE is returned.
+ The error message must to contain a single %s for the name. */
+
+bool
+gfc_is_intrinsic_typename (const char *name, const char *error_message)
+{
+ if (strcmp (name, "integer") == 0
+ || strcmp (name, "real") == 0
+ || strcmp (name, "character") == 0
+ || strcmp (name, "logical") == 0
+ || strcmp (name, "complex") == 0
+ || strcmp (name, "doubleprecision") == 0
+ || strcmp (name, "doublecomplex") == 0)
+ {
+ gfc_error (error_message, name);
+ return true;
+ }
+
+ return false;
+}
IMO, it would better if this function only returns true or false,
without emitting error message.
gfc_new_block->attr.abstract = 1;
- if (!strcmp(gfc_new_block->name,"integer")
- || !strcmp(gfc_new_block->name,"real")
- || !strcmp(gfc_new_block->name,"complex")
- || !strcmp(gfc_new_block->name,"character")
- || !strcmp(gfc_new_block->name,"logical"))
- gfc_error ("Name of ABSTRACT INTERFACE at %C cannot be the same as "
- "an intrinsic type: %s",gfc_new_block->name);
+
+ /* Print an error if it has the name of an intrinsic type. */
+ gfc_is_intrinsic_typename (gfc_new_block->name,
+ "Name '%s' of ABSTRACT INTERFACE at %C "
+ "cannot be the same as an intrinsic type");
if (gfc_is_intrinsic_typename (gfc_new_block->name))
gfc_error ("... %s", gfc_new_block->name);
For me, it is easier to debug gcc/gfortran this way. The call to
gfc_error() is the place of an error, and IMO, the code is more readable.
Uros.