This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

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.


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