aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/parse.c
diff options
context:
space:
mode:
authorTobias Schlüter <tobi@gcc.gnu.org>2005-10-30 19:09:55 +0100
committerTobias Schlüter <tobi@gcc.gnu.org>2005-10-30 19:09:55 +0100
commit25d8f0a2839a99417ab79879fb55f2ead76fcf2a (patch)
tree3920d0fc1db1a9d875d55587afd2ffefff790a10 /gcc/fortran/parse.c
parente8299ec258037fb73ee906633760ff1191bf05e1 (diff)
downloadgcc-25d8f0a2839a99417ab79879fb55f2ead76fcf2a.zip
gcc-25d8f0a2839a99417ab79879fb55f2ead76fcf2a.tar.gz
gcc-25d8f0a2839a99417ab79879fb55f2ead76fcf2a.tar.bz2
arith.c (gfc_enum_initializer): New function.
fortran/ 2005-10-30 Gaurav Gautam <gauravga@noida.hcltech.com> Tobias Schl"uter <tobias.schlueter@physik.uni-muenchen.de> * arith.c (gfc_enum_initializer): New function. (gfc_check_integer_range): Made extern. * decl.c (enumerator_history): New typedef. (last_initializer, enum_history, max_enum): New variables. (create_enum_history, gfc_free_enum_history): New functions. (add_init_expr_to_sym): Call create_enum_history if parsing ENUM. (variable_decl): Modified to parse enumerator definition. (match_attr_spec): Add PARAMETER attribute to ENUMERATORs. (gfc_match_data_decl): Issues error, if match_type_spec do not return desired return values. (set_enum_kind, gfc_match_enum, gfc_match_enumerator_def): New functions. (gfc_match_end): Deal with END ENUM. * gfortran.h (gfc_statement): ST_ENUM, ST_ENUMERATOR, ST_END_ENUM added. (symbol_attribute): Bit field for enumerator added. (gfc_options): Add fshort_enums. (gfc_enum_initializer, gfc_check_integer_range): Add prototypes. * options.c: Include target.h (gfc_init_options): Initialize fshort_enums. (gfc_handle_option): Deal with fshort_enums. * parse.c (decode_statement): Match ENUM and ENUMERATOR statement. (gfc_ascii_statement): Deal with the enumerator statements. (parse_enum): New function to parse enum construct. (parse_spec): Added case ST_ENUM. * parse.h (gfc_compile_state): COMP_ENUM added. (gfc_match_enum, gfc_match_enumerator_def, gfc_free_enum_history): Prototype added. * symbol.c (gfc_copy_attr): Copy enumeration attribute. * lang.opt (fshort-enums): Option added. testsuite/ 2005-10-30 Tobias Schl"uter <tobias.schlueter@physik.uni-muenchen.de> * gfortran.dg/enum_10.f90, gfortran.dg/enum_10.c: New test. 2005-10-30 Gaurav Gautam <gauravga@noida.hcltech.com> * gfortran.dg/enum_1.f90, gfortran.dg/enum_2.f90, gfortran.dg/enum_3.f90, gfortran.dg/enum_4.f90, gfortran.dg/enum_5.f90, gfortran.dg/enum_6.f90, gfortran.dg/enum_7.f90, gfortran.dg/enum_8.f90, gfortran.dg/enum_9.f90, gfortran.fortran-torture/compile/enum_1.f90, gfortran.fortran-torture/execute/enum_1.f90, gfortran.fortran-torture/execute/enum_2.f90, gfortran.fortran-torture/execute/enum_3.f90, gfortran.fortran-torture/execute/enum_4.f90: New tests. From-SVN: r106246
Diffstat (limited to 'gcc/fortran/parse.c')
-rw-r--r--gcc/fortran/parse.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c
index 69459251..430d8f3 100644
--- a/gcc/fortran/parse.c
+++ b/gcc/fortran/parse.c
@@ -132,6 +132,7 @@ decode_statement (void)
match (NULL, gfc_match_st_function, ST_STATEMENT_FUNCTION);
match (NULL, gfc_match_data_decl, ST_DATA_DECL);
+ match (NULL, gfc_match_enumerator_def, ST_ENUMERATOR);
/* Try to match a subroutine statement, which has the same optional
prefixes that functions can have. */
@@ -205,6 +206,7 @@ decode_statement (void)
match ("else", gfc_match_else, ST_ELSE);
match ("else where", gfc_match_elsewhere, ST_ELSEWHERE);
match ("else if", gfc_match_elseif, ST_ELSEIF);
+ match ("enum , bind ( c )", gfc_match_enum, ST_ENUM);
if (gfc_match_end (&st) == MATCH_YES)
return st;
@@ -951,6 +953,15 @@ gfc_ascii_statement (gfc_statement st)
case ST_LABEL_ASSIGNMENT:
p = "LABEL ASSIGNMENT";
break;
+ case ST_ENUM:
+ p = "ENUM DEFINITION";
+ break;
+ case ST_ENUMERATOR:
+ p = "ENUMERATOR DEFINITION";
+ break;
+ case ST_END_ENUM:
+ p = "END ENUM";
+ break;
default:
gfc_internal_error ("gfc_ascii_statement(): Bad statement code");
}
@@ -1335,6 +1346,56 @@ parse_derived (void)
+/* Parse an ENUM. */
+
+static void
+parse_enum (void)
+{
+ int error_flag;
+ gfc_statement st;
+ int compiling_enum;
+ gfc_state_data s;
+ int seen_enumerator = 0;
+
+ error_flag = 0;
+
+ push_state (&s, COMP_ENUM, gfc_new_block);
+
+ compiling_enum = 1;
+
+ while (compiling_enum)
+ {
+ st = next_statement ();
+ switch (st)
+ {
+ case ST_NONE:
+ unexpected_eof ();
+ break;
+
+ case ST_ENUMERATOR:
+ seen_enumerator = 1;
+ accept_statement (st);
+ break;
+
+ case ST_END_ENUM:
+ compiling_enum = 0;
+ if (!seen_enumerator)
+ {
+ gfc_error ("ENUM declaration at %C has no ENUMERATORS");
+ error_flag = 1;
+ }
+ accept_statement (st);
+ break;
+
+ default:
+ gfc_free_enum_history ();
+ unexpected_statement (st);
+ break;
+ }
+ }
+ pop_state ();
+}
+
/* Parse an interface. We must be able to deal with the possibility
of recursive interfaces. The parse_spec() subroutine is mutually
recursive with parse_interface(). */
@@ -1540,6 +1601,12 @@ loop:
st = next_statement ();
goto loop;
+ case ST_ENUM:
+ accept_statement (st);
+ parse_enum();
+ st = next_statement ();
+ goto loop;
+
default:
break;
}