aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/decl.c
diff options
context:
space:
mode:
authorSteven G. Kargl <kargl@gcc.gnu.org>2009-06-12 21:14:42 +0000
committerSteven G. Kargl <kargl@gcc.gnu.org>2009-06-12 21:14:42 +0000
commit312243969e3a0022c0eabe6f974c24abd4a2211b (patch)
treeb5c34c448cef8a8161bd6d57e5fbde7d823aa8a6 /gcc/fortran/decl.c
parentd1d919c362ce6dd1cc74e7d2c0912ea586dcfd4a (diff)
downloadgcc-312243969e3a0022c0eabe6f974c24abd4a2211b.zip
gcc-312243969e3a0022c0eabe6f974c24abd4a2211b.tar.gz
gcc-312243969e3a0022c0eabe6f974c24abd4a2211b.tar.bz2
arith.c (gfc_enum_initializer): Move function ...
2009-06-12 Steven G. Kargl <kargls@comcast.net> * arith.c (gfc_enum_initializer): Move function ... * decl.c: ... here. Remove gfc_ prefix and make static. (enumerator_decl): Update function call. * gfortran.h: Remove gfc_enum_initializer prototype. From-SVN: r148441
Diffstat (limited to 'gcc/fortran/decl.c')
-rw-r--r--gcc/fortran/decl.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 7ecb921..1a4ca36 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -6812,6 +6812,51 @@ gfc_match_enum (void)
}
+/* Returns an initializer whose value is one higher than the value of the
+ LAST_INITIALIZER argument. If the argument is NULL, the
+ initializers value will be set to zero. The initializer's kind
+ will be set to gfc_c_int_kind.
+
+ If -fshort-enums is given, the appropriate kind will be selected
+ later after all enumerators have been parsed. A warning is issued
+ here if an initializer exceeds gfc_c_int_kind. */
+
+static gfc_expr *
+enum_initializer (gfc_expr *last_initializer, locus where)
+{
+ gfc_expr *result;
+
+ result = gfc_get_expr ();
+ result->expr_type = EXPR_CONSTANT;
+ result->ts.type = BT_INTEGER;
+ result->ts.kind = gfc_c_int_kind;
+ result->where = where;
+
+ mpz_init (result->value.integer);
+
+ if (last_initializer != NULL)
+ {
+ mpz_add_ui (result->value.integer, last_initializer->value.integer, 1);
+ result->where = last_initializer->where;
+
+ if (gfc_check_integer_range (result->value.integer,
+ gfc_c_int_kind) != ARITH_OK)
+ {
+ gfc_error ("Enumerator exceeds the C integer type at %C");
+ return NULL;
+ }
+ }
+ else
+ {
+ /* Control comes here, if it's the very first enumerator and no
+ initializer has been given. It will be initialized to zero. */
+ mpz_set_si (result->value.integer, 0);
+ }
+
+ return result;
+}
+
+
/* Match a variable name with an optional initializer. When this
subroutine is called, a variable is expected to be parsed next.
Depending on what is happening at the moment, updates either the
@@ -6872,7 +6917,7 @@ enumerator_decl (void)
previous enumerator (stored in last_initializer) is incremented
by 1 and is used to initialize the current enumerator. */
if (initializer == NULL)
- initializer = gfc_enum_initializer (last_initializer, old_locus);
+ initializer = enum_initializer (last_initializer, old_locus);
if (initializer == NULL || initializer->ts.type != BT_INTEGER)
{