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]

[gcc-in-cxx] Fix fortran frontend to build with C++


I committed this patch to the gcc-in-cxx branch to let the fortran
frontend build with C++.  This was mostly a matter of enum fiddling, in
particular moving enum definitions out of structs to the top level.  In
a couple of cases the C++ frontend complained about using an
uninitialized variable, so I initialized it.

Ian


2009-03-04  Ian Lance Taylor  <iant@google.com>

	* fortran/Make-lang.in (gfortranspec.o): Compile with $(CXX).
	(fortran/cpp.o): Likewise.
	(gfortran$(exeext)): Link with $(CXX).
	(f951$(exeext)): Likewise.
	* fortran/gfortran.h (enum omp_sched_kind): Move out of struct
	gfc_omp_clauses.
	(enum omp_sharing): Likewise.
	(enum gfc_symbol_type): Move out of struct gfc_gsymbol.
	(enum gfc_array_ref_dimen_type): Move out of strutc
	gfc_array_ref.
	* fortran/cpp.c (struct gfc_cpp_option_data): Give name to
	anonymous struct.
	* fortran/decl.c (build_struct): Initialize first_len.
	(match_attr_spec): Change variable 'd' to int.
	(add_global_entry): Change variable 'type' to gfc_symbol_type.
	* fortran/dump-parse-tree.c (show_namespace): Change variable 'op'
	to int.
	* fortran/interface.c (gfc_check_interfaces): Change loop to use
	int type rather than enum type.
	* fortran/module.c (enum rsym_state, enum wsym_state): Move out of
	struct pointer_info.
	(mio_array_ref, mio_symbol): Add casts to enum type.
	(read_module): Change variable 'i' to int.
	(write_module): Likewise.
	(import_iso_c_binding_module): Add cast to enum type.
	* fortran/parse.c (enum state_order): Move out of st_state
	struct.
	* fortran/resolve.c (resolve_global_procedure): Change variable
	'type' to gfc_symbol_type.
	(check_host_association): Initialize tail.
	* fortran/symbol.c (gfc_get_namespace): Change variable 'in' to
	int.
	(gfc_free_namespace): Change variable 'i' to int.
	* fortran/trans-intrinsic.c (DEFINE_MATH_BUILTIN): Add casts to
	enum type.
	* fortran/trans-io.c (st_parameter_field): Add casts to enum
	type.
	(gfc_build_st_parameter): Change variable 'type' to int.
	(gfc_build_io_library_fndecls): Change variable 'ptype' to int.
	* fortran/trans-types.c (gfc_init_kinds): Change loops to use int
	type rather than enum type.


Index: interface.c
===================================================================
--- interface.c	(revision 144568)
+++ interface.c	(working copy)
@@ -1267,7 +1267,7 @@ gfc_check_interfaces (gfc_namespace *ns)
 {
   gfc_namespace *old_ns, *ns2;
   char interface_name[100];
-  gfc_intrinsic_op i;
+  int iloop;
 
   old_ns = gfc_current_ns;
   gfc_current_ns = ns;
@@ -1276,8 +1276,10 @@ gfc_check_interfaces (gfc_namespace *ns)
 
   gfc_traverse_user_op (ns, check_uop_interfaces);
 
-  for (i = GFC_INTRINSIC_BEGIN; i != GFC_INTRINSIC_END; i++)
+  for (iloop = GFC_INTRINSIC_BEGIN; iloop != GFC_INTRINSIC_END; iloop++)
     {
+      gfc_intrinsic_op i = (gfc_intrinsic_op) iloop;
+
       if (i == INTRINSIC_USER)
 	continue;
 
Index: symbol.c
===================================================================
--- symbol.c	(revision 144568)
+++ symbol.c	(working copy)
@@ -2179,7 +2179,7 @@ gfc_get_namespace (gfc_namespace *parent
 {
   gfc_namespace *ns;
   gfc_typespec *ts;
-  gfc_intrinsic_op in;
+  int in;
   int i;
 
   ns = XCNEW (gfc_namespace);
@@ -3034,7 +3034,7 @@ void
 gfc_free_namespace (gfc_namespace *ns)
 {
   gfc_namespace *p, *q;
-  gfc_intrinsic_op i;
+  int i;
 
   if (ns == NULL)
     return;
Index: decl.c
===================================================================
--- decl.c	(revision 144568)
+++ decl.c	(working copy)
@@ -1435,7 +1435,7 @@ build_struct (const char *name, gfc_char
 	  gfc_constructor *ctor = c->initializer->value.constructor;
 
 	  bool first = true;
-	  int first_len;
+	  int first_len = 0;
 
 	  has_ts = (c->initializer->ts.cl
 		    && c->initializer->ts.cl->length_from_typespec);
@@ -2804,7 +2804,7 @@ match_attr_spec (void)
 
   locus start, seen_at[NUM_DECL];
   int seen[NUM_DECL];
-  decl_types d;
+  int d;
   const char *attr;
   match m;
   gfc_try t;
@@ -4516,7 +4516,7 @@ static bool
 add_global_entry (const char *name, int sub)
 {
   gfc_gsymbol *s;
-  unsigned int type;
+  enum gfc_symbol_type type;
 
   s = gfc_get_gsymbol(name);
   type = sub ? GSYM_SUBROUTINE : GSYM_FUNCTION;
Index: dump-parse-tree.c
===================================================================
--- dump-parse-tree.c	(revision 144568)
+++ dump-parse-tree.c	(working copy)
@@ -1955,7 +1955,7 @@ show_namespace (gfc_namespace *ns)
 {
   gfc_interface *intr;
   gfc_namespace *save;
-  gfc_intrinsic_op op;
+  int op;
   gfc_equiv *eq;
   int i;
 
@@ -2005,7 +2005,7 @@ show_namespace (gfc_namespace *ns)
 
 	  show_indent ();
 	  fprintf (dumpfile, "Operator interfaces for %s:",
-		   gfc_op2string (op));
+		   gfc_op2string ((gfc_intrinsic_op) op));
 
 	  for (; intr; intr = intr->next)
 	    fprintf (dumpfile, " %s", intr->sym->name);
Index: Make-lang.in
===================================================================
--- Make-lang.in	(revision 144568)
+++ Make-lang.in	(working copy)
@@ -80,13 +80,13 @@ fortran: f951$(exeext)
 gfortranspec.o: $(srcdir)/fortran/gfortranspec.c $(SYSTEM_H) $(TM_H) $(GCC_H) \
 	$(CONFIG_H) coretypes.h intl.h
 	(SHLIB_LINK='$(SHLIB_LINK)'; \
-	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(DRIVER_DEFINES) \
+	$(CXX) -c $(ALL_CXXFLAGS) $(ALL_CPPFLAGS) $(DRIVER_DEFINES) \
 		$(INCLUDES) $(srcdir)/fortran/gfortranspec.c)
 
 # Create the compiler driver gfortran.
 GFORTRAN_D_OBJS = $(GCC_OBJS) gfortranspec.o version.o prefix.o intl.o
 gfortran$(exeext): $(GFORTRAN_D_OBJS) $(EXTRA_GCC_OBJS) $(LIBDEPS)
-	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \
+	$(CXX) $(ALL_CXXFLAGS) $(LDFLAGS) -o $@ \
 	  $(GFORTRAN_D_OBJS) $(EXTRA_GCC_OBJS) $(LIBS)
 
 # Create a version of the gfortran driver which calls the cross-compiler.
@@ -97,7 +97,7 @@ gfortran-cross$(exeext): gfortran$(exeex
 # The compiler itself is called f951.
 f951$(exeext): $(F95_OBJS) \
 		$(BACKEND) $(LIBDEPS) attribs.o
-	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \
+	$(CXX) $(ALL_CXXFLAGS) $(LDFLAGS) -o $@ \
 		$(F95_OBJS) $(BACKEND) $(LIBS) attribs.o $(BACKENDLIBS)
 
 gt-fortran-trans.h    : s-gtype; @true
@@ -337,5 +337,5 @@ fortran/resolve.o: fortran/dependency.h 
 fortran/data.o: fortran/data.h
 fortran/options.o: $(PARAMS_H) $(TARGET_H) fortran/cpp.h
 fortran/cpp.o: fortran/cpp.c $(BASEVER) incpath.h incpath.o
-	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) -DBASEVER=$(BASEVER_s) \
+	$(CXX) -c $(ALL_CXXFLAGS) $(ALL_CPPFLAGS) -DBASEVER=$(BASEVER_s) \
 		$< $(OUTPUT_OPTION)
Index: cpp.c
===================================================================
--- cpp.c	(revision 144568)
+++ cpp.c	(working copy)
@@ -66,7 +66,7 @@ typedef struct gfc_cpp_macro_queue
 } gfc_cpp_macro_queue;
 static gfc_cpp_macro_queue *cpp_define_queue, *cpp_undefine_queue;
 
-struct
+struct gfc_cpp_option_data
 {
   /* Argument of -cpp, implied by SPEC;
      if NULL, preprocessing disabled.  */
Index: gfortran.h
===================================================================
--- gfortran.h	(revision 144568)
+++ gfortran.h	(working copy)
@@ -922,29 +922,34 @@ enum
 
 /* Because a symbol can belong to multiple namelists, they must be
    linked externally to the symbol itself.  */
+
+enum omp_sched_kind
+{
+  OMP_SCHED_NONE,
+  OMP_SCHED_STATIC,
+  OMP_SCHED_DYNAMIC,
+  OMP_SCHED_GUIDED,
+  OMP_SCHED_RUNTIME,
+  OMP_SCHED_AUTO
+};
+
+enum omp_sharing
+{
+  OMP_DEFAULT_UNKNOWN,
+  OMP_DEFAULT_NONE,
+  OMP_DEFAULT_PRIVATE,
+  OMP_DEFAULT_SHARED,
+  OMP_DEFAULT_FIRSTPRIVATE
+};
+
 typedef struct gfc_omp_clauses
 {
   struct gfc_expr *if_expr;
   struct gfc_expr *num_threads;
   gfc_namelist *lists[OMP_LIST_NUM];
-  enum
-    {
-      OMP_SCHED_NONE,
-      OMP_SCHED_STATIC,
-      OMP_SCHED_DYNAMIC,
-      OMP_SCHED_GUIDED,
-      OMP_SCHED_RUNTIME,
-      OMP_SCHED_AUTO
-    } sched_kind;
+  enum omp_sched_kind sched_kind;
   struct gfc_expr *chunk_size;
-  enum
-    {
-      OMP_DEFAULT_UNKNOWN,
-      OMP_DEFAULT_NONE,
-      OMP_DEFAULT_PRIVATE,
-      OMP_DEFAULT_SHARED,
-      OMP_DEFAULT_FIRSTPRIVATE
-    } default_sharing;
+  enum omp_sharing default_sharing;
   int collapse;
   bool nowait, ordered, untied;
 }
@@ -1314,6 +1319,12 @@ extern gfc_namespace *gfc_current_ns;
    this to detect collisions already when parsing.
    TODO: Extend to verify procedure calls.  */
 
+enum gfc_symbol_type
+{
+  GSYM_UNKNOWN=1, GSYM_PROGRAM, GSYM_FUNCTION, GSYM_SUBROUTINE,
+  GSYM_MODULE, GSYM_COMMON, GSYM_BLOCK_DATA
+};
+
 typedef struct gfc_gsymbol
 {
   BBT_HEADER(gfc_gsymbol);
@@ -1322,8 +1333,7 @@ typedef struct gfc_gsymbol
   const char *sym_name;
   const char *mod_name;
   const char *binding_label;
-  enum { GSYM_UNKNOWN=1, GSYM_PROGRAM, GSYM_FUNCTION, GSYM_SUBROUTINE,
-        GSYM_MODULE, GSYM_COMMON, GSYM_BLOCK_DATA } type;
+  enum gfc_symbol_type type;
 
   int defined, used;
   locus where;
@@ -1347,6 +1357,12 @@ extern gfc_interface_info current_interf
 
 
 /* Array reference.  */
+
+enum gfc_array_ref_dimen_type
+{
+  DIMEN_ELEMENT = 1, DIMEN_RANGE, DIMEN_VECTOR, DIMEN_UNKNOWN
+};
+
 typedef struct gfc_array_ref
 {
   ar_type type;
@@ -1358,9 +1374,7 @@ typedef struct gfc_array_ref
   struct gfc_expr *start[GFC_MAX_DIMENSIONS], *end[GFC_MAX_DIMENSIONS],
     *stride[GFC_MAX_DIMENSIONS];
 
-  enum
-  { DIMEN_ELEMENT = 1, DIMEN_RANGE, DIMEN_VECTOR, DIMEN_UNKNOWN }
-  dimen_type[GFC_MAX_DIMENSIONS];
+  enum gfc_array_ref_dimen_type dimen_type[GFC_MAX_DIMENSIONS];
 
   struct gfc_expr *offset;
 }
Index: module.c
===================================================================
--- module.c	(revision 144568)
+++ module.c	(working copy)
@@ -115,6 +115,16 @@ fixup_t;
 
 /* Structure for holding extra info needed for pointers being read.  */
 
+enum rsym_state
+{
+  UNUSED, NEEDED, USED
+};
+
+enum wsym_state
+{
+  UNREFERENCED = 0, NEEDS_WRITE, WRITTEN
+};
+
 typedef struct pointer_info
 {
   BBT_HEADER (pointer_info);
@@ -134,9 +144,7 @@ typedef struct pointer_info
     {
       gfc_symbol *sym;
       char true_name[GFC_MAX_SYMBOL_LEN + 1], module[GFC_MAX_SYMBOL_LEN + 1];
-      enum
-      { UNUSED, NEEDED, USED }
-      state;
+      enum rsym_state state;
       int ns, referenced, renamed;
       module_locus where;
       fixup_t *stfixup;
@@ -148,9 +156,7 @@ typedef struct pointer_info
     struct
     {
       gfc_symbol *sym;
-      enum
-      { UNREFERENCED = 0, NEEDS_WRITE, WRITTEN }
-      state;
+      enum wsym_state state;
     }
     wsym;
   }
@@ -2157,7 +2163,7 @@ mio_array_ref (gfc_array_ref *ar)
       for (i = 0; i < ar->dimen; i++)
 	{
 	  require_atom (ATOM_INTEGER);
-	  ar->dimen_type[i] = atom_int;
+	  ar->dimen_type[i] = (enum gfc_array_ref_dimen_type) atom_int;
 	}
     }
 
@@ -3448,7 +3454,7 @@ mio_symbol (gfc_symbol *sym)
   else
     {
       mio_integer (&intmod);
-      sym->from_intmod = intmod;
+      sym->from_intmod = (intmod_id) intmod;
     }
   
   mio_integer (&(sym->intmod_sym_id));
@@ -3992,7 +3998,7 @@ read_module (void)
   module_locus operator_interfaces, user_operators;
   const char *p;
   char name[GFC_MAX_SYMBOL_LEN + 1];
-  gfc_intrinsic_op i;
+  int i;
   int ambiguous, j, nuse, symbol;
   pointer_info *info, *q;
   gfc_use_rename *u;
@@ -4200,7 +4206,7 @@ read_module (void)
 
       if (only_flag)
 	{
-	  u = find_use_operator (i);
+	  u = find_use_operator ((gfc_intrinsic_op) i);
 
 	  if (u == NULL)
 	    {
@@ -4652,7 +4658,7 @@ write_symtree (gfc_symtree *st)
 static void
 write_module (void)
 {
-  gfc_intrinsic_op i;
+  int i;
 
   /* Write the operator interfaces.  */
   mio_lparen ();
@@ -4964,7 +4970,8 @@ import_iso_c_binding_module (void)
 	{
 	  iso_c_binding_symbol is;
 
-	  is = get_c_kind (u->use_name, c_interop_kinds_table);
+	  is = (iso_c_binding_symbol) get_c_kind (u->use_name,
+						  c_interop_kinds_table);
 
 	  if (is == ISOCBINDING_INVALID || is == ISOCBINDING_LAST)
 	    {
Index: trans-types.c
===================================================================
--- trans-types.c	(revision 144568)
+++ trans-types.c	(working copy)
@@ -252,13 +252,16 @@ void init_c_interop_kinds (void)
 void
 gfc_init_kinds (void)
 {
-  enum machine_mode mode;
+  int mode_loop;
   int i_index, r_index, kind;
   bool saw_i4 = false, saw_i8 = false;
   bool saw_r4 = false, saw_r8 = false, saw_r16 = false;
 
-  for (i_index = 0, mode = MIN_MODE_INT; mode <= MAX_MODE_INT; mode++)
+  for (i_index = 0, mode_loop = MIN_MODE_INT;
+       mode_loop <= MAX_MODE_INT;
+       mode_loop++)
     {
+      enum machine_mode mode = (enum machine_mode) mode_loop;
       int kind, bitsize;
 
       if (!targetm.scalar_mode_supported_p (mode))
@@ -307,8 +310,11 @@ gfc_init_kinds (void)
   /* Set the maximum integer kind.  Used with at least BOZ constants.  */
   gfc_max_integer_kind = gfc_integer_kinds[i_index - 1].kind;
 
-  for (r_index = 0, mode = MIN_MODE_FLOAT; mode <= MAX_MODE_FLOAT; mode++)
+  for (r_index = 0, mode_loop = MIN_MODE_FLOAT;
+       mode_loop <= MAX_MODE_FLOAT;
+       mode_loop++)
     {
+      enum machine_mode mode = (enum machine_mode) mode_loop;
       const struct real_format *fmt = REAL_MODE_FORMAT (mode);
       int kind;
 
Index: resolve.c
===================================================================
--- resolve.c	(revision 144568)
+++ resolve.c	(working copy)
@@ -1587,7 +1587,7 @@ static void
 resolve_global_procedure (gfc_symbol *sym, locus *where, int sub)
 {
   gfc_gsymbol * gsym;
-  unsigned int type;
+  enum gfc_symbol_type type;
 
   type = sub ? GSYM_SUBROUTINE : GSYM_FUNCTION;
 
@@ -4299,7 +4299,8 @@ check_host_association (gfc_expr *e)
   gfc_symtree *st;
   int n;
   gfc_ref *ref;
-  gfc_actual_arglist *arg, *tail;
+  gfc_actual_arglist *arg;
+  gfc_actual_arglist *tail = NULL;
   bool retval = e->expr_type == EXPR_FUNCTION;
 
   /*  If the expression is the result of substitution in
Index: trans-io.c
===================================================================
--- trans-io.c	(revision 144568)
+++ trans-io.c	(working copy)
@@ -107,7 +107,7 @@ static GTY(()) gfc_st_parameter_field st
   { #name, mask, IOPARM_ptype_##param_type, IOPARM_type_##type, NULL, NULL },
 #include "ioparm.def"
 #undef IOPARM
-  { NULL, 0, 0, 0, NULL, NULL }
+  { NULL, 0, (enum ioparam_type) 0, (enum iofield_type) 0, NULL, NULL }
 };
 
 /* Library I/O subroutines */
@@ -155,7 +155,7 @@ static stmtblock_t *dt_post_end_block;
 static void
 gfc_build_st_parameter (enum ioparam_type ptype, tree *types)
 {
-  enum iofield type;
+  int type;
   gfc_st_parameter_field *p;
   char name[64];
   size_t len;
@@ -281,7 +281,7 @@ gfc_build_io_library_fndecls (void)
   tree gfc_intio_type_node;
   tree parm_type, dt_parm_type;
   HOST_WIDE_INT pad_size;
-  enum ioparam_type ptype;
+  int ptype;
 
   types[IOPARM_type_int4] = gfc_int4_type_node = gfc_get_int_type (4);
   types[IOPARM_type_intio] = gfc_intio_type_node
@@ -304,7 +304,7 @@ gfc_build_io_library_fndecls (void)
 		     TYPE_ALIGN (gfc_get_int_type (gfc_intio_kind)));
 
   for (ptype = IOPARM_ptype_common; ptype < IOPARM_ptype_num; ptype++)
-    gfc_build_st_parameter (ptype, types);
+    gfc_build_st_parameter ((enum ioparam_type) ptype, types);
 
   /* Define the transfer functions.  */
 
Index: parse.c
===================================================================
--- parse.c	(revision 144568)
+++ parse.c	(working copy)
@@ -1572,13 +1572,15 @@ unexpected_statement (gfc_statement st)
 
 */
 
+enum state_order
+{
+  ORDER_START, ORDER_USE, ORDER_IMPORT, ORDER_IMPLICIT_NONE,
+  ORDER_IMPLICIT, ORDER_SPEC, ORDER_EXEC
+};
+
 typedef struct
 {
-  enum
-  { ORDER_START, ORDER_USE, ORDER_IMPORT, ORDER_IMPLICIT_NONE,
-    ORDER_IMPLICIT, ORDER_SPEC, ORDER_EXEC
-  }
-  state;
+  enum state_order state;
   gfc_statement last_statement;
   locus where;
 }
Index: trans-intrinsic.c
===================================================================
--- trans-intrinsic.c	(revision 144568)
+++ trans-intrinsic.c	(working copy)
@@ -93,9 +93,11 @@ gfc_intrinsic_map_t;
    except for atan2.  */
 #define DEFINE_MATH_BUILTIN(ID, NAME, ARGTYPE) \
   { GFC_ISYM_ ## ID, BUILT_IN_ ## ID ## F, BUILT_IN_ ## ID, \
-    BUILT_IN_ ## ID ## L, BUILT_IN_ ## ID ## L, 0, 0, 0, 0, true, \
-    false, true, NAME, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, \
-    NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE},
+    BUILT_IN_ ## ID ## L, BUILT_IN_ ## ID ## L, (enum built_in_function) 0, \
+    (enum built_in_function) 0, (enum built_in_function) 0, \
+    (enum built_in_function) 0, true, false, true, NAME, NULL_TREE, \
+    NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, \
+    NULL_TREE},
 
 #define DEFINE_MATH_BUILTIN_C(ID, NAME, ARGTYPE) \
   { GFC_ISYM_ ## ID, BUILT_IN_ ## ID ## F, BUILT_IN_ ## ID, \

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