OSDN Git Service

* c-tree.h, c-decl.c (build_enumerator): Add location parameter.
[pf3gnuchains/gcc-fork.git] / gcc / c-parser.c
index dc3f26e..666f418 100644 (file)
@@ -42,18 +42,17 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "tm.h"                        /* For rtl.h: needs enum reg_class.  */
 #include "tree.h"
-#include "rtl.h"               /* For decl_default_tls_model.  */
 #include "langhooks.h"
 #include "input.h"
 #include "cpplib.h"
 #include "timevar.h"
-#include "c-pragma.h"
+#include "c-family/c-pragma.h"
 #include "c-tree.h"
 #include "flags.h"
 #include "output.h"
 #include "toplev.h"
 #include "ggc.h"
-#include "c-common.h"
+#include "c-family/c-common.h"
 #include "vec.h"
 #include "target.h"
 #include "cgraph.h"
@@ -87,7 +86,7 @@ c_parse_init (void)
   if (!c_dialect_objc ())
     mask |= D_OBJC | D_CXX_OBJC;
 
-  ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
+  ridpointers = ggc_alloc_cleared_vec_tree ((int) RID_MAX);
   for (i = 0; i < num_c_common_reswords; i++)
     {
       /* If a keyword is disabled, do not enter it into the table
@@ -195,7 +194,6 @@ typedef struct GTY(()) c_parser {
 
 static GTY (()) c_parser *the_parser;
 
-
 /* Read in and lex a single token, storing it in *TOKEN.  */
 
 static void
@@ -379,6 +377,7 @@ c_token_starts_typename (c_token *token)
        {
        case RID_UNSIGNED:
        case RID_LONG:
+       case RID_INT128:
        case RID_SHORT:
        case RID_SIGNED:
        case RID_COMPLEX:
@@ -458,6 +457,7 @@ c_token_starts_declspecs (c_token *token)
        case RID_THREAD:
        case RID_UNSIGNED:
        case RID_LONG:
+       case RID_INT128:
        case RID_SHORT:
        case RID_SIGNED:
        case RID_COMPLEX:
@@ -1575,6 +1575,7 @@ c_parser_static_assert_declaration_no_semi (c_parser *parser)
 
    type-specifier:
      typeof-specifier
+     __int128
      _Decimal32
      _Decimal64
      _Decimal128
@@ -1692,6 +1693,7 @@ c_parser_declspecs (c_parser *parser, struct c_declspecs *specs,
          break;
        case RID_UNSIGNED:
        case RID_LONG:
+       case RID_INT128:
        case RID_SHORT:
        case RID_SIGNED:
        case RID_COMPLEX:
@@ -1831,7 +1833,7 @@ c_parser_enum_specifier (c_parser *parser)
          bool seen_comma;
          c_token *token;
          location_t comma_loc = UNKNOWN_LOCATION;  /* Quiet warning.  */
-         location_t value_loc;
+         location_t decl_loc, value_loc;
          if (c_parser_next_token_is_not (parser, CPP_NAME))
            {
              c_parser_error (parser, "expected identifier");
@@ -1843,7 +1845,7 @@ c_parser_enum_specifier (c_parser *parser)
          enum_id = token->value;
          /* Set the location in case we create a decl now.  */
          c_parser_set_source_position_from_token (token);
-         value_loc = token->location;
+         decl_loc = value_loc = token->location;
          c_parser_consume_token (parser);
          if (c_parser_next_token_is (parser, CPP_EQ))
            {
@@ -1853,7 +1855,7 @@ c_parser_enum_specifier (c_parser *parser)
            }
          else
            enum_value = NULL_TREE;
-         enum_decl = build_enumerator (value_loc,
+         enum_decl = build_enumerator (decl_loc, value_loc,
                                        &the_enum, enum_id, enum_value);
          TREE_CHAIN (enum_decl) = values;
          values = enum_decl;
@@ -2226,7 +2228,7 @@ c_parser_struct_declaration (c_parser *parser)
                         declarator, specs, width, &all_prefix_attrs);
          decl_attributes (&d, chainon (postfix_attrs,
                                        all_prefix_attrs), 0);
-         TREE_CHAIN (d) = decls;
+         DECL_CHAIN (d) = decls;
          decls = d;
          if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
            all_prefix_attrs = chainon (c_parser_attributes (parser),
@@ -2669,13 +2671,8 @@ c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
        }
       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
        {
-         struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
-         ret->parms = 0;
-         ret->tags = 0;
+         struct c_arg_info *ret = build_arg_info ();
          ret->types = list;
-         ret->others = 0;
-         ret->pending_sizes = 0;
-         ret->had_vla_unspec = 0;
          c_parser_consume_token (parser);
          pop_scope ();
          return ret;
@@ -2703,7 +2700,7 @@ c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
 static struct c_arg_info *
 c_parser_parms_list_declarator (c_parser *parser, tree attrs)
 {
-  bool good_parm = false;
+  bool bad_parm = false;
   /* ??? Following the old parser, forward parameter declarations may
      use abstract declarators, and if no real parameter declarations
      follow the forward declarations then this is not diagnosed.  Also
@@ -2712,24 +2709,13 @@ c_parser_parms_list_declarator (c_parser *parser, tree attrs)
      declarations.  */
   if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
     {
-      struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
-      ret->parms = 0;
-      ret->tags = 0;
-      ret->types = 0;
-      ret->others = 0;
-      ret->pending_sizes = 0;
-      ret->had_vla_unspec = 0;
+      struct c_arg_info *ret = build_arg_info ();
       c_parser_consume_token (parser);
       return ret;
     }
   if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
     {
-      struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
-      ret->parms = 0;
-      ret->tags = 0;
-      ret->others = 0;
-      ret->pending_sizes = 0;
-      ret->had_vla_unspec = 0;
+      struct c_arg_info *ret = build_arg_info ();
       /* Suppress -Wold-style-definition for this case.  */
       ret->types = error_mark_node;
       error_at (c_parser_peek_token (parser)->location,
@@ -2755,11 +2741,10 @@ c_parser_parms_list_declarator (c_parser *parser, tree attrs)
       /* Parse a parameter.  */
       struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
       attrs = NULL_TREE;
-      if (parm != NULL)
-       {
-         good_parm = true;
-         push_parm_decl (parm);
-       }
+      if (parm == NULL)
+       bad_parm = true;
+      else
+       push_parm_decl (parm);
       if (c_parser_next_token_is (parser, CPP_SEMICOLON))
        {
          tree new_attrs;
@@ -2771,20 +2756,13 @@ c_parser_parms_list_declarator (c_parser *parser, tree attrs)
       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
        {
          c_parser_consume_token (parser);
-         if (good_parm)
-           return get_parm_info (false);
-         else
+         if (bad_parm)
            {
-             struct c_arg_info *ret
-               = XOBNEW (&parser_obstack, struct c_arg_info);
-             ret->parms = 0;
-             ret->tags = 0;
-             ret->types = 0;
-             ret->others = 0;
-             ret->pending_sizes = 0;
-             ret->had_vla_unspec = 0;
-             return ret;
+             get_pending_sizes ();
+             return NULL;
            }
+         else
+           return get_parm_info (false);
        }
       if (!c_parser_require (parser, CPP_COMMA,
                             "expected %<;%>, %<,%> or %<)%>"))
@@ -2799,20 +2777,13 @@ c_parser_parms_list_declarator (c_parser *parser, tree attrs)
          if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
            {
              c_parser_consume_token (parser);
-             if (good_parm)
-               return get_parm_info (true);
-             else
+             if (bad_parm)
                {
-                 struct c_arg_info *ret
-                   = XOBNEW (&parser_obstack, struct c_arg_info);
-                 ret->parms = 0;
-                 ret->tags = 0;
-                 ret->types = 0;
-                 ret->others = 0;
-                 ret->pending_sizes = 0;
-                 ret->had_vla_unspec = 0;
-                 return ret;
+                 get_pending_sizes ();
+                 return NULL;
                }
+             else
+               return get_parm_info (true);
            }
          else
            {
@@ -2838,10 +2809,22 @@ c_parser_parameter_declaration (c_parser *parser, tree attrs)
   bool dummy = false;
   if (!c_parser_next_token_starts_declspecs (parser))
     {
+      c_token *token = c_parser_peek_token (parser);
+      if (parser->error)
+       return NULL;
+      c_parser_set_source_position_from_token (token);
+      if (token->type == CPP_NAME
+         && c_parser_peek_2nd_token (parser)->type != CPP_COMMA
+         && c_parser_peek_2nd_token (parser)->type != CPP_CLOSE_PAREN)
+       {
+         error ("unknown type name %qE", token->value);
+         parser->error = true;
+       }
       /* ??? In some Objective-C cases '...' isn't applicable so there
         should be a different message.  */
-      c_parser_error (parser,
-                     "expected declaration specifiers or %<...%>");
+      else
+       c_parser_error (parser,
+                       "expected declaration specifiers or %<...%>");
       c_parser_skip_to_end_of_parameter (parser);
       return NULL;
     }
@@ -3006,6 +2989,7 @@ c_parser_attributes (c_parser *parser)
                case RID_STATIC:
                case RID_UNSIGNED:
                case RID_LONG:
+               case RID_INT128:
                case RID_CONST:
                case RID_EXTERN:
                case RID_REGISTER:
@@ -4791,7 +4775,7 @@ static struct c_expr
 c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
 {
   struct c_expr cond, exp1, exp2, ret;
-  location_t cond_loc, colon_loc;
+  location_t cond_loc, colon_loc, middle_loc;
 
   gcc_assert (!after || c_dialect_objc ());
 
@@ -4805,8 +4789,11 @@ c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
   if (c_parser_next_token_is (parser, CPP_COLON))
     {
       tree eptype = NULL_TREE;
-      pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic,
+
+      middle_loc = c_parser_peek_token (parser)->location;
+      pedwarn (middle_loc, OPT_pedantic, 
               "ISO C forbids omitting the middle term of a ?: expression");
+      warn_for_omitted_condop (middle_loc, cond.value);
       if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
        {
          eptype = TREE_TYPE (cond.value);
@@ -5597,6 +5584,7 @@ c_parser_postfix_expression (c_parser *parser)
          pedwarn (loc, OPT_pedantic,
                   "ISO C forbids braced-groups within expressions");
          expr.value = c_finish_stmt_expr (brace_loc, stmt);
+         mark_exp_read (expr.value);
        }
       else if (c_token_starts_typename (c_parser_peek_2nd_token (parser)))
        {
@@ -5842,9 +5830,8 @@ c_parser_postfix_expression (c_parser *parser)
            e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
            e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
 
-           expr.value = comptypes (e1, e2)
-             ? build_int_cst (NULL_TREE, 1)
-             : build_int_cst (NULL_TREE, 0);
+           expr.value
+             = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
          }
          break;
        case RID_AT_SELECTOR:
@@ -6426,7 +6413,7 @@ c_parser_objc_class_instance_variables (c_parser *parser)
        /* Comma-separated instance variables are chained together in
           reverse order; add them one by one.  */
        tree ivar = nreverse (decls);
-       for (; ivar; ivar = TREE_CHAIN (ivar))
+       for (; ivar; ivar = DECL_CHAIN (ivar))
          objc_add_instance_variable (copy_node (ivar));
       }
       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
@@ -6988,6 +6975,7 @@ c_parser_objc_selector (c_parser *parser)
     case RID_ALIGNOF:
     case RID_UNSIGNED:
     case RID_LONG:
+    case RID_INT128:
     case RID_CONST:
     case RID_SHORT:
     case RID_VOLATILE:
@@ -8016,6 +8004,42 @@ c_parser_omp_atomic (location_t loc, c_parser *parser)
       rhs = integer_one_node;
       break;
 
+    case COMPOUND_EXPR:
+      if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR
+         && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR
+         && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR
+         && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0)
+         && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
+                                             (TREE_OPERAND (lhs, 1), 0), 0)))
+            == BOOLEAN_TYPE)
+       /* Undo effects of boolean_increment for post {in,de}crement.  */
+       lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0);
+      /* FALLTHRU */
+    case MODIFY_EXPR:
+      if (TREE_CODE (lhs) == MODIFY_EXPR
+         && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE)
+       {
+         /* Undo effects of boolean_increment.  */
+         if (integer_onep (TREE_OPERAND (lhs, 1)))
+           {
+             /* This is pre or post increment.  */
+             rhs = TREE_OPERAND (lhs, 1);
+             lhs = TREE_OPERAND (lhs, 0);
+             code = NOP_EXPR;
+             break;
+           }
+         if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR
+             && TREE_OPERAND (lhs, 0)
+                == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0))
+           {
+             /* This is pre or post decrement.  */
+             rhs = TREE_OPERAND (lhs, 1);
+             lhs = TREE_OPERAND (lhs, 0);
+             code = NOP_EXPR;
+             break;
+           }
+       }
+      /* FALLTHRU */
     default:
       switch (c_parser_peek_token (parser)->type)
        {
@@ -8144,10 +8168,11 @@ c_parser_omp_for_loop (location_t loc,
                       c_parser *parser, tree clauses, tree *par_clauses)
 {
   tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
-  tree declv, condv, incrv, initv, for_block = NULL, ret = NULL;
+  tree declv, condv, incrv, initv, ret = NULL;
   bool fail = false, open_brace_parsed = false;
   int i, collapse = 1, nbraces = 0;
   location_t for_loc;
+  VEC(tree,gc) *for_block = make_tree_vector ();
 
   for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
     if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
@@ -8179,8 +8204,7 @@ c_parser_omp_for_loop (location_t loc,
       if (c_parser_next_token_starts_declaration (parser))
        {
          if (i > 0)
-           for_block
-             = tree_cons (NULL, c_begin_compound_stmt (true), for_block);
+           VEC_safe_push (tree, gc, for_block, c_begin_compound_stmt (true));
          c_parser_declaration_or_fndef (parser, true, true, true, true, true);
          decl = check_for_loop_decls (for_loc);
          if (decl == NULL)
@@ -8410,15 +8434,15 @@ c_parser_omp_for_loop (location_t loc,
       ret = stmt;
     }
 pop_scopes:
-  while (for_block)
+  while (!VEC_empty (tree, for_block))
     {
       /* FIXME diagnostics: LOC below should be the actual location of
         this particular for block.  We need to build a list of
         locations to go along with FOR_BLOCK.  */
-      stmt = c_end_compound_stmt (loc, TREE_VALUE (for_block), true);
+      stmt = c_end_compound_stmt (loc, VEC_pop (tree, for_block), true);
       add_stmt (stmt);
-      for_block = TREE_CHAIN (for_block);
     }
+  release_tree_vector (for_block);
   return ret;
 }
 
@@ -8876,7 +8900,7 @@ c_parse_file (void)
   if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS)
     c_parser_pragma_pch_preprocess (&tparser);
 
-  the_parser = GGC_NEW (c_parser);
+  the_parser = ggc_alloc_c_parser ();
   *the_parser = tparser;
 
   /* Initialize EH, if we've been told to do so.  */