diff mbox series

[Demangle] Some pre-fix cleanups

Message ID 7293d93e-d94e-7e2c-c8d6-e8552bd568d4@acm.org
State New
Headers show
Series [Demangle] Some pre-fix cleanups | expand

Commit Message

Nathan Sidwell Sept. 15, 2017, 10:48 a.m. UTC
In working on bug 82195, a lambda-related demangler bug, I noticed some 
cleanup opportunities.

1) we express an is_fnqual_component_type in two separate, independent, 
ways.  It would be smarter to express one of those ways in terms of the 
other.

2) An overly nested function call made it awkward to look at the 
argument values at the outer call side.  Use a local variable.

3) An if condition ended with the same call in both true and false 
cases.  Move that call out of the if.

4) The testsuite had mis-ordered blank lines (optional args) towards the 
end.

Applying to trunk.

nathan
diff mbox series

Patch

2017-09-15  Nathan Sidwell  <nathan@acm.org>

	* cp-demangle.c (is_fnqual_component_type): Reimplement using
	FNQUAL_COMPONENT_CASE.
	(d_encoding): Hold bare_function_type in local var.
	(d_local_name): Build name in both cases and build result once.
	Collapse switch-if to single conditional.
	* testsuite/demangle-expected: Realign blank lines with tests.

Index: cp-demangle.c
===================================================================
--- cp-demangle.c	(revision 252076)
+++ cp-demangle.c	(working copy)
@@ -568,22 +568,6 @@  static int d_demangle_callback (const ch
                                 demangle_callbackref, void *);
 static char *d_demangle (const char *, int, size_t *);
 
-/* True iff TYPE is a demangling component representing a
-   function-type-qualifier.  */
-
-static int
-is_fnqual_component_type (enum demangle_component_type type)
-{
-  return (type == DEMANGLE_COMPONENT_RESTRICT_THIS
-	  || type == DEMANGLE_COMPONENT_VOLATILE_THIS
-	  || type == DEMANGLE_COMPONENT_CONST_THIS
-	  || type == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
-	  || type == DEMANGLE_COMPONENT_TRANSACTION_SAFE
-	  || type == DEMANGLE_COMPONENT_NOEXCEPT
-	  || type == DEMANGLE_COMPONENT_THROW_SPEC
-	  || type == DEMANGLE_COMPONENT_REFERENCE_THIS);
-}
-
 #define FNQUAL_COMPONENT_CASE				\
     case DEMANGLE_COMPONENT_RESTRICT_THIS:		\
     case DEMANGLE_COMPONENT_VOLATILE_THIS:		\
@@ -594,6 +578,23 @@  is_fnqual_component_type (enum demangle_
     case DEMANGLE_COMPONENT_NOEXCEPT:			\
     case DEMANGLE_COMPONENT_THROW_SPEC
 
+/* True iff TYPE is a demangling component representing a
+   function-type-qualifier.  */
+
+static int
+is_fnqual_component_type (enum demangle_component_type type)
+{
+  switch (type)
+    {
+    FNQUAL_COMPONENT_CASE:
+      return 1;
+    default:
+      break;
+    }
+  return 0;
+}
+
+
 #ifdef CP_DEMANGLE_DEBUG
 
 static void
@@ -1305,7 +1306,7 @@  d_encoding (struct d_info *di, int top_l
     return d_special_name (di);
   else
     {
-      struct demangle_component *dc;
+      struct demangle_component *dc, *dcr;
 
       dc = d_name (di);
 
@@ -1327,8 +1328,6 @@  d_encoding (struct d_info *di, int top_l
 	     which is local to a function.  */
 	  if (dc->type == DEMANGLE_COMPONENT_LOCAL_NAME)
 	    {
-	      struct demangle_component *dcr;
-
 	      dcr = d_right (dc);
 	      while (is_fnqual_component_type (dcr->type))
 		dcr = d_left (dcr);
@@ -1341,8 +1340,8 @@  d_encoding (struct d_info *di, int top_l
       peek = d_peek_char (di);
       if (dc == NULL || peek == '\0' || peek == 'E')
 	return dc;
-      return d_make_comp (di, DEMANGLE_COMPONENT_TYPED_NAME, dc,
-			  d_bare_function_type (di, has_return_type (dc)));
+      dcr = d_bare_function_type (di, has_return_type (dc));
+      return d_make_comp (di, DEMANGLE_COMPONENT_TYPED_NAME, dc, dcr);
     }
 }
 
@@ -3571,6 +3570,7 @@  static struct demangle_component *
 d_local_name (struct d_info *di)
 {
   struct demangle_component *function;
+  struct demangle_component *name;
 
   if (! d_check_char (di, 'Z'))
     return NULL;
@@ -3585,13 +3585,10 @@  d_local_name (struct d_info *di)
       d_advance (di, 1);
       if (! d_discriminator (di))
 	return NULL;
-      return d_make_comp (di, DEMANGLE_COMPONENT_LOCAL_NAME, function,
-			  d_make_name (di, "string literal",
-				       sizeof "string literal" - 1));
+      name = d_make_name (di, "string literal", sizeof "string literal" - 1);
     }
   else
     {
-      struct demangle_component *name;
       int num = -1;
 
       if (d_peek_char (di) == 'd')
@@ -3604,21 +3601,19 @@  d_local_name (struct d_info *di)
 	}
 
       name = d_name (di);
-      if (name)
-	switch (name->type)
-	  {
-	    /* Lambdas and unnamed types have internal discriminators.  */
-	  case DEMANGLE_COMPONENT_LAMBDA:
-	  case DEMANGLE_COMPONENT_UNNAMED_TYPE:
-	    break;
-	  default:
-	    if (! d_discriminator (di))
-	      return NULL;
-	  }
+      if (name
+	  /* Lambdas and unnamed types have internal discriminators.  */
+	  && name->type != DEMANGLE_COMPONENT_LAMBDA
+	  && name->type != DEMANGLE_COMPONENT_UNNAMED_TYPE
+	  /* Otherwise read and ignore an optional discriminator.  */
+	  && ! d_discriminator (di))
+	return NULL;
+
       if (num >= 0)
 	name = d_make_default_arg (di, num, name);
-      return d_make_comp (di, DEMANGLE_COMPONENT_LOCAL_NAME, function, name);
     }
+
+  return d_make_comp (di, DEMANGLE_COMPONENT_LOCAL_NAME, function, name);
 }
 
 /* <discriminator> ::= _ <number>    # when number < 10
Index: testsuite/demangle-expected
===================================================================
--- testsuite/demangle-expected	(revision 252076)
+++ testsuite/demangle-expected	(working copy)
@@ -4720,18 +4720,19 @@  _ZdvMMMMMMMMMMMMMrrrrA_DTdvfp_fp_Eededil
 
 _Z1MA_aMMMMA_MMA_MMMMMMMMSt1MS_o11T0000000000t2M0oooozoooo
 _Z1MA_aMMMMA_MMA_MMMMMMMMSt1MS_o11T0000000000t2M0oooozoooo
-
 #
 # demangler/80513 Test for overflow in d_number
+
 _Z4294967297x
 _Z4294967297x
-
 #
 # demangler/80513 Test for bogus characters after __thunk_
+
 __thunk_16a_$_1x
 __thunk_16a_$_1x
-
 #
 # demangler/80513 Test for overflow in consume_count
+
 __thunk_4294967297__$_1x
 __thunk_4294967297__$_1x
+#