c/c++, asm: Write the asm-qualifier loop without "done" boolean
authorSegher Boessenkool <segher@kernel.crashing.org>
Wed, 19 Dec 2018 15:55:28 +0000 (16:55 +0100)
committerSegher Boessenkool <segher@gcc.gnu.org>
Wed, 19 Dec 2018 15:55:28 +0000 (16:55 +0100)
As suggested by Jason.

c/
* c-parser.c (c_parser_asm_statement): Rewrite the loop to work without
"done" boolean variable.

cp/
* parser.c (cp_parser_asm_definition): Rewrite the loop to work without
"done" boolean variable.

From-SVN: r267277

gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/cp/ChangeLog
gcc/cp/parser.c

index 3232614f4301a30551a7ed4c4b8e302409fd538a..d1beffaac6241be870e299c6ba5c6a25f942e1d0 100644 (file)
@@ -1,3 +1,8 @@
+2018-12-19  Segher Boessenkool  <segher@kernel.crashing.org>
+
+       * c-parser.c (c_parser_asm_statement): Rewrite the loop to work without
+       "done" boolean variable.
+
 2018-12-19  David Malcolm  <dmalcolm@redhat.com>
 
        PR c++/87504
index b875c4f4750fe56ea57a4f61c8830637d05c4425..835c0d8b879b5ea9534e946d0a5858eb7dac98ad 100644 (file)
@@ -6372,40 +6372,37 @@ c_parser_asm_statement (c_parser *parser)
   is_volatile = false;
   is_inline = false;
   is_goto = false;
-  for (bool done = false; !done; )
-    switch (c_parser_peek_token (parser)->keyword)
-      {
-      case RID_VOLATILE:
-       if (!is_volatile)
-         {
-           is_volatile = true;
-           quals = c_parser_peek_token (parser)->value;
-           c_parser_consume_token (parser);
-         }
-       else
-         done = true;
-       break;
-      case RID_INLINE:
-       if (!is_inline)
-         {
-           is_inline = true;
-           c_parser_consume_token (parser);
-         }
-       else
-         done = true;
-       break;
-      case RID_GOTO:
-       if (!is_goto)
-         {
-           is_goto = true;
-           c_parser_consume_token (parser);
-         }
-       else
-         done = true;
-       break;
-      default:
-       done = true;
-      }
+  for (;;)
+    {
+      switch (c_parser_peek_token (parser)->keyword)
+       {
+       case RID_VOLATILE:
+         if (is_volatile)
+           break;
+         is_volatile = true;
+         quals = c_parser_peek_token (parser)->value;
+         c_parser_consume_token (parser);
+         continue;
+
+       case RID_INLINE:
+         if (is_inline)
+           break;
+         is_inline = true;
+         c_parser_consume_token (parser);
+         continue;
+
+       case RID_GOTO:
+         if (is_goto)
+           break;
+         is_goto = true;
+         c_parser_consume_token (parser);
+         continue;
+
+       default:
+         break;
+       }
+      break;
+    }
 
   /* ??? Follow the C++ parser rather than using the
      lex_untranslated_string kludge.  */
index 7b794612c8be166ffb94f04872ff8d3dae0ec0b5..44ac2a96ff0291f4bd5469e9a84250a5568826d6 100644 (file)
@@ -1,3 +1,8 @@
+2018-12-19  Segher Boessenkool  <segher@kernel.crashing.org>
+
+       * parser.c (cp_parser_asm_definition): Rewrite the loop to work without
+       "done" boolean variable.
+
 2018-12-19  David Malcolm  <dmalcolm@redhat.com>
 
        PR c++/88375
index e5381b45d033b2843a8d60e26adeaf46d7c19795..0e4716ff0d5e86b7ae0bdfea9eb2da42d63b1651 100644 (file)
@@ -19698,47 +19698,38 @@ cp_parser_asm_definition (cp_parser* parser)
       cp_function_chain->invalid_constexpr = true;
     }
 
-  /* See if the next token is `volatile'.  */
+  /* Handle the asm-qualifier-list.  */
   if (cp_parser_allow_gnu_extensions_p (parser))
-    for (bool done = false; !done ; )
-      switch (cp_lexer_peek_token (parser->lexer)->keyword)
-       {
-       case RID_VOLATILE:
-         if (!volatile_p)
-           {
-             /* Remember that we saw the `volatile' keyword.  */
-             volatile_p = true;
-             /* Consume the token.  */
-             cp_lexer_consume_token (parser->lexer);
-           }
-         else
-           done = true;
-         break;
-       case RID_INLINE:
-         if (!inline_p && parser->in_function_body)
-           {
-             /* Remember that we saw the `inline' keyword.  */
-             inline_p = true;
-             /* Consume the token.  */
-             cp_lexer_consume_token (parser->lexer);
-           }
-         else
-           done = true;
-         break;
-       case RID_GOTO:
-         if (!goto_p && parser->in_function_body)
-           {
-             /* Remember that we saw the `goto' keyword.  */
-             goto_p = true;
-             /* Consume the token.  */
-             cp_lexer_consume_token (parser->lexer);
-           }
-         else
-           done = true;
-         break;
-       default:
-         done = true;
-       }
+    for (;;)
+      {
+       switch (cp_lexer_peek_token (parser->lexer)->keyword)
+         {
+         case RID_VOLATILE:
+           if (volatile_p)
+             break;
+           volatile_p = true;
+           cp_lexer_consume_token (parser->lexer);
+           continue;
+
+         case RID_INLINE:
+           if (inline_p || !parser->in_function_body)
+             break;
+           inline_p = true;
+           cp_lexer_consume_token (parser->lexer);
+           continue;
+
+         case RID_GOTO:
+           if (goto_p || !parser->in_function_body)
+             break;
+           goto_p = true;
+           cp_lexer_consume_token (parser->lexer);
+           continue;
+
+         default:
+           break;
+         }
+       break;
+      }
 
   /* Look for the opening `('.  */
   if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))