]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Introduce CP_OPERATOR_STR/CP_OPERATOR_LEN and use throughout
authorPedro Alves <palves@redhat.com>
Mon, 17 Jul 2017 14:51:55 +0000 (15:51 +0100)
committerPedro Alves <palves@redhat.com>
Mon, 17 Jul 2017 14:51:55 +0000 (15:51 +0100)
Move LENGTH_OF_OPERATOR from cp-support.c to cp-support.h so we can
use it elsewhere.  Since there's already
CP_ANONYMOUS_NAMESPACE_STR/CP_ANONYMOUS_NAMESPACE_LEN there, follow
the same naming pattern for the new symbols.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

* c-exp.y (operator_stoken): Use CP_OPERATOR_LEN and
CP_OPERATOR_STR.
* c-typeprint.c (is_type_conversion_operator): Use
CP_OPERATOR_STR.
* cp-support.c (LENGTH_OF_OPERATOR): Delete.
(cp_find_first_component_aux): Use CP_OPERATOR_STR and
CP_OPERATOR_LEN.
* cp-support.h (CP_OPERATOR_STR, CP_OPERATOR_LEN): New.
* gnu-v2-abi.c (gnuv2_is_operator_name): Use CP_OPERATOR_STR.
* gnu-v3-abi.c (gnuv3_is_operator_name): Use CP_OPERATOR_STR.
* linespec.c (linespec_lexer_lex_string): Use CP_OPERATOR_LEN and
CP_OPERATOR_STR.
* location.c: Include "cp-support.h".
(explicit_location_lex_one): Use CP_OPERATOR_LEN and
CP_OPERATOR_STR.
* symtab.c (operator_chars): Use CP_OPERATOR_STR and
CP_OPERATOR_LEN.

gdb/ChangeLog
gdb/c-exp.y
gdb/c-typeprint.c
gdb/cp-support.c
gdb/cp-support.h
gdb/gnu-v2-abi.c
gdb/gnu-v3-abi.c
gdb/linespec.c
gdb/location.c
gdb/symtab.c

index 554a9e5d341f9440ad520d612ed4b16ec433cf6d..8778caea426b66a71cca3cf7c480f94151d280a8 100644 (file)
@@ -1,3 +1,23 @@
+2017-07-17  Pedro Alves  <palves@redhat.com>
+
+       * c-exp.y (operator_stoken): Use CP_OPERATOR_LEN and
+       CP_OPERATOR_STR.
+       * c-typeprint.c (is_type_conversion_operator): Use
+       CP_OPERATOR_STR.
+       * cp-support.c (LENGTH_OF_OPERATOR): Delete.
+       (cp_find_first_component_aux): Use CP_OPERATOR_STR and
+       CP_OPERATOR_LEN.
+       * cp-support.h (CP_OPERATOR_STR, CP_OPERATOR_LEN): New.
+       * gnu-v2-abi.c (gnuv2_is_operator_name): Use CP_OPERATOR_STR.
+       * gnu-v3-abi.c (gnuv3_is_operator_name): Use CP_OPERATOR_STR.
+       * linespec.c (linespec_lexer_lex_string): Use CP_OPERATOR_LEN and
+       CP_OPERATOR_STR.
+       * location.c: Include "cp-support.h".
+       (explicit_location_lex_one): Use CP_OPERATOR_LEN and
+       CP_OPERATOR_STR.
+       * symtab.c (operator_chars): Use CP_OPERATOR_STR and
+       CP_OPERATOR_LEN.
+
 2017-07-17  Pedro Alves  <palves@redhat.com>
 
        * cli/cli-cmds.c (complete_command): Use a completion tracker
index bdcd51f4a6efb078ad60f6a6c718682a0a55a56c..24a2fbd76e684e284bc32878068567d99fef4ec8 100644 (file)
@@ -1625,13 +1625,12 @@ write_destructor_name (struct parser_state *par_state, struct stoken token)
 static struct stoken
 operator_stoken (const char *op)
 {
-  static const char *operator_string = "operator";
   struct stoken st = { NULL, 0 };
   char *buf;
 
-  st.length = strlen (operator_string) + strlen (op);
+  st.length = CP_OPERATOR_LEN + strlen (op);
   buf = (char *) malloc (st.length + 1);
-  strcpy (buf, operator_string);
+  strcpy (buf, CP_OPERATOR_STR);
   strcat (buf, op);
   st.ptr = buf;
 
index 9e197f5721fcebdfe3bb7c7a9fbda486b517ea76..890888bd4f9da17720932344061016db43b70aca 100644 (file)
@@ -547,7 +547,7 @@ is_type_conversion_operator (struct type *type, int i, int j)
      some other way, feel free to rewrite this function.  */
   const char *name = TYPE_FN_FIELDLIST_NAME (type, i);
 
-  if (!startswith (name, "operator"))
+  if (!startswith (name, CP_OPERATOR_STR))
     return 0;
 
   name += 8;
index 5704466c923bd3800a913c3cd040805e1b487929..122faddf35d6ced19d808b5a7129cd8c4d29a2cd 100644 (file)
@@ -931,10 +931,6 @@ cp_find_first_component (const char *name)
    the recursion easier, it also stops if it reaches an unexpected ')'
    or '>' if the value of PERMISSIVE is nonzero.  */
 
-/* Let's optimize away calls to strlen("operator").  */
-
-#define LENGTH_OF_OPERATOR 8
-
 static unsigned int
 cp_find_first_component_aux (const char *name, int permissive)
 {
@@ -1006,10 +1002,9 @@ cp_find_first_component_aux (const char *name, int permissive)
        case 'o':
          /* Operator names can screw up the recursion.  */
          if (operator_possible
-             && strncmp (name + index, "operator",
-                         LENGTH_OF_OPERATOR) == 0)
+             && startswith (name + index, CP_OPERATOR_STR))
            {
-             index += LENGTH_OF_OPERATOR;
+             index += CP_OPERATOR_LEN;
              while (ISSPACE(name[index]))
                ++index;
              switch (name[index])
index 9054bf678c837d3c2ceeed0c078bf951f46febc1..37b281fa54af555a9b34acc04803a33800e96473 100644 (file)
@@ -46,6 +46,14 @@ struct using_direct;
 
 #define CP_ANONYMOUS_NAMESPACE_LEN 21
 
+/* A string representing the start of an operator name.  */
+
+#define CP_OPERATOR_STR "operator"
+
+/* The length of CP_OPERATOR_STR.  */
+
+#define CP_OPERATOR_LEN 8
+
 /* The result of parsing a name.  */
 
 struct demangle_parse_info
index 0af684f4546546b80d163891607bc393b5f7bef0..91c42015aae419c2530e0929d50f5ce1b5e909ca 100644 (file)
@@ -68,7 +68,7 @@ gnuv2_is_vtable_name (const char *name)
 static int
 gnuv2_is_operator_name (const char *name)
 {
-  return startswith (name, "operator");
+  return startswith (name, CP_OPERATOR_STR);
 }
 
 \f
index 0090990b1e672639a17316dd2a97a27471a0118e..f5d3d13a537c7e283409aa2360a94f9946b4e085 100644 (file)
@@ -46,7 +46,7 @@ gnuv3_is_vtable_name (const char *name)
 static int
 gnuv3_is_operator_name (const char *name)
 {
-  return startswith (name, "operator");
+  return startswith (name, CP_OPERATOR_STR);
 }
 
 
index 4c076fea3eb46020dd0bc5d651213855c2b7a188..25ebdcafa9524e96915e42eaafc1108bbeb7b767 100644 (file)
@@ -688,10 +688,9 @@ linespec_lexer_lex_string (linespec_parser *parser)
            {
              if ((PARSER_STATE (parser)->language->la_language
                   == language_cplus)
-                 && (PARSER_STREAM (parser) - start) > 8
-                 /* strlen ("operator") */)
+                 && (PARSER_STREAM (parser) - start) > CP_OPERATOR_LEN)
                {
-                 const char *p = strstr (start, "operator");
+                 const char *p = strstr (start, CP_OPERATOR_STR);
 
                  if (p != NULL && is_operator_name (p))
                    {
index 87963207ba16eef22ee92fea4f6a58b6a9ccf63a..d711d7b25b526bb98a07e10b844bd28708fbbfca 100644 (file)
@@ -24,6 +24,7 @@
 #include "linespec.h"
 #include "cli/cli-utils.h"
 #include "probe.h"
+#include "cp-support.h"
 
 #include <ctype.h>
 #include <string.h>
@@ -473,8 +474,8 @@ explicit_location_lex_one (const char **inp,
        {
          /* Special case: C++ operator,.  */
          if (language->la_language == language_cplus
-             && strncmp (*inp, "operator", 8) == 0)
-           (*inp) += 8;
+             && startswith (*inp, CP_OPERATOR_STR))
+           (*inp) += CP_OPERATOR_LEN;
          ++(*inp);
        }
     }
index 57fb355328f16fa82cc906ac9184516bdb681998..b077369516e78a5a3e71f69f96cb1a1381b2133c 100644 (file)
@@ -3839,9 +3839,9 @@ static const char *
 operator_chars (const char *p, const char **end)
 {
   *end = "";
-  if (!startswith (p, "operator"))
+  if (!startswith (p, CP_OPERATOR_STR))
     return *end;
-  p += 8;
+  p += CP_OPERATOR_LEN;
 
   /* Don't get faked out by `operator' being part of a longer
      identifier.  */