gdb/
authorJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 13 Jun 2012 16:10:10 +0000 (16:10 +0000)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 13 Jun 2012 16:10:10 +0000 (16:10 +0000)
PR c++/14177 - Fix parsing TYPENAME:: in parentheses.
* c-exp.y (classify_inner_name): Remove caller assumptions in the
function comment.  Return ERROR for unresolved cases.  Implement
returning proper NAME.
(yylex): Accept also NAME from classify_inner_name.
* cp-namespace.c (cp_lookup_nested_type): Rename to ...
(cp_lookup_nested_symbol): ... here.  Return any found symbol, not just
LOC_TYPEDEF type.
* cp-support.h (cp_lookup_nested_type): Update its declaration.

gdb/testsuite/
PR c++/14177 - Fix parsing TYPENAME:: in parentheses.
* gdb.cp/cpexprs.cc (class CV, CV::i, ATTRIBUTE_USED, CV_f): New.
(test_function): Call CV_f.
* gdb.cp/cpexprs.exp (p 'CV::m(int)', p CV::m(int))
(p 'CV::m(int) const', p CV::m(int) const, p 'CV::m(int) volatile')
(p CV::m(int) volatile, p 'CV::m(int) const volatile')
(p CV::m(int) const volatile, p CV_f(int), p CV_f(CV::t))
(p CV_f(CV::i)): New tests.

gdb/ChangeLog
gdb/c-exp.y
gdb/cp-namespace.c
gdb/cp-support.h
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.cp/cpexprs.cc
gdb/testsuite/gdb.cp/cpexprs.exp

index 304adc62967f0ed855a387bf6df00c82a00d0e24..ee7e9cb093ba1f98fe8c084b77fccc2183e40318 100644 (file)
@@ -1,3 +1,15 @@
+2012-06-13  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       PR c++/14177 - Fix parsing TYPENAME:: in parentheses.
+       * c-exp.y (classify_inner_name): Remove caller assumptions in the
+       function comment.  Return ERROR for unresolved cases.  Implement
+       returning proper NAME.
+       (yylex): Accept also NAME from classify_inner_name.
+       * cp-namespace.c (cp_lookup_nested_type): Rename to ...
+       (cp_lookup_nested_symbol): ... here.  Return any found symbol, not just
+       LOC_TYPEDEF type.
+       * cp-support.h (cp_lookup_nested_type): Update its declaration.
+
 2012-06-13  Tom Tromey  <tromey@redhat.com>
 
        * breakpoint.c (condition_completer): New function.
index e912657754d36b57449a612f6b5d07f8df99f5be..1e14337da42c7343842e4c91f9ddb27c99ced963 100644 (file)
@@ -2505,9 +2505,8 @@ classify_name (struct block *block)
 
 /* Like classify_name, but used by the inner loop of the lexer, when a
    name might have already been seen.  FIRST_NAME is true if the token
-   in `yylval' is the first component of a name, false otherwise.  If
-   this function returns NAME, it might not have updated `yylval'.
-   This is ok because the caller only cares about TYPENAME.  */
+   in `yylval' is the first component of a name, false otherwise.  */
+
 static int
 classify_inner_name (struct block *block, int first_name)
 {
@@ -2521,18 +2520,28 @@ classify_inner_name (struct block *block, int first_name)
   if (TYPE_CODE (type) != TYPE_CODE_STRUCT
       && TYPE_CODE (type) != TYPE_CODE_UNION
       && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
-    /* We know the caller won't expect us to update yylval.  */
-    return NAME;
+    return ERROR;
 
   copy = copy_name (yylval.tsym.stoken);
-  new_type = cp_lookup_nested_type (yylval.tsym.type, copy, block);
+  yylval.ssym.sym = cp_lookup_nested_symbol (yylval.tsym.type, copy, block);
+  if (yylval.ssym.sym == NULL)
+    return ERROR;
+
+  switch (SYMBOL_CLASS (yylval.ssym.sym))
+    {
+    case LOC_BLOCK:
+    case LOC_LABEL:
+      return ERROR;
 
-  if (new_type == NULL)
-    /* We know the caller won't expect us to update yylval.  */
-    return NAME;
+    case LOC_TYPEDEF:
+      yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym);;
+      return TYPENAME;
 
-  yylval.tsym.type = new_type;
-  return TYPENAME;
+    default:
+      yylval.ssym.is_a_field_of_this = 0;
+      return NAME;
+    }
+  internal_error (__FILE__, __LINE__, _("not reached"));
 }
 
 /* The outer level of a two-level lexer.  This calls the inner lexer
@@ -2592,7 +2601,7 @@ yylex (void)
                                                first_iter);
          /* We keep going until we either run out of names, or until
             we have a qualified name which is not a type.  */
-         if (classification != TYPENAME)
+         if (classification != TYPENAME && classification != NAME)
            {
              /* Push the final component and leave the loop.  */
              VEC_safe_push (token_and_value, token_fifo, &next);
index 170dd5f82f97f10ffd10510b85099dffd5dbd99f..e2291a9938f9118a937d21e67465b0649a4659e1 100644 (file)
@@ -660,14 +660,14 @@ lookup_symbol_file (const char *name,
   return sym;
 }
 
-/* Look up a type named NESTED_NAME that is nested inside the C++
+/* Look up a symbol named NESTED_NAME that is nested inside the C++
    class or namespace given by PARENT_TYPE, from within the context
    given by BLOCK.  Return NULL if there is no such nested type.  */
 
-struct type *
-cp_lookup_nested_type (struct type *parent_type,
-                      const char *nested_name,
-                      const struct block *block)
+struct symbol *
+cp_lookup_nested_symbol (struct type *parent_type,
+                        const char *nested_name,
+                        const struct block *block)
 {
   /* type_name_no_tag_required provides better error reporting using the
      original type.  */
@@ -694,8 +694,8 @@ cp_lookup_nested_type (struct type *parent_type,
                                           block, VAR_DOMAIN);
        char *concatenated_name;
 
-       if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
-         return SYMBOL_TYPE (sym);
+       if (sym != NULL)
+         return sym;
 
        /* Now search all static file-level symbols.  Not strictly
           correct, but more useful than an error.  We do not try to
@@ -707,16 +707,15 @@ cp_lookup_nested_type (struct type *parent_type,
                                    + strlen (nested_name) + 1);
        sprintf (concatenated_name, "%s::%s",
                 parent_name, nested_name);
-       sym = lookup_static_symbol_aux (concatenated_name,
-                                       VAR_DOMAIN);
-       if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
-         return SYMBOL_TYPE (sym);
+       sym = lookup_static_symbol_aux (concatenated_name, VAR_DOMAIN);
+       if (sym != NULL)
+         return sym;
 
        return NULL;
       }
     default:
       internal_error (__FILE__, __LINE__,
-                     _("cp_lookup_nested_type called "
+                     _("cp_lookup_nested_symbol called "
                        "on a non-aggregate type."));
     }
 }
index 9c150f801594480fd4a2dc420fc3d3605bafcff9..0d2b5131b549eae2e006096d198b4fdd0a495568 100644 (file)
@@ -213,9 +213,9 @@ extern struct symbol *cp_lookup_symbol_imports_or_template
       const struct block *block,
       const domain_enum domain);
 
-extern struct type *cp_lookup_nested_type (struct type *parent_type,
-                                          const char *nested_name,
-                                          const struct block *block);
+extern struct symbol *cp_lookup_nested_symbol (struct type *parent_type,
+                                              const char *nested_name,
+                                              const struct block *block);
 
 struct type *cp_lookup_transparent_type (const char *name);
 
index d369a2a2630626c4e1dec653de00195450e570ff..d12bd9e8cabcd25338932cd2780d34edeec6b7c6 100644 (file)
@@ -1,3 +1,14 @@
+2012-06-13  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       PR c++/14177 - Fix parsing TYPENAME:: in parentheses.
+       * gdb.cp/cpexprs.cc (class CV, CV::i, ATTRIBUTE_USED, CV_f): New.
+       (test_function): Call CV_f.
+       * gdb.cp/cpexprs.exp (p 'CV::m(int)', p CV::m(int))
+       (p 'CV::m(int) const', p CV::m(int) const, p 'CV::m(int) volatile')
+       (p CV::m(int) volatile, p 'CV::m(int) const volatile')
+       (p CV::m(int) const volatile, p CV_f(int), p CV_f(CV::t))
+       (p CV_f(CV::i)): New tests.
+
 2012-06-13  Tom Tromey  <tromey@redhat.com>
 
        * gdb.base/condbreak.exp: Add tests for "condition" completion.
index c8c5ac8a2a7919b2f82f97057818c843f852e3f7..f6b355c3d54519b20d034c53ebe160f10c16a86e 100644 (file)
@@ -308,6 +308,29 @@ class derived : public base1, public base2
   int foo_;
 };
 
+class CV { public:
+  static const int i;
+  typedef int t;
+  void m(t);
+  void m(t) const;
+  void m(t) volatile;
+  void m(t) const volatile;
+};
+const int CV::i = 42;
+#ifdef __GNUC__
+# define ATTRIBUTE_USED __attribute__((used))
+#else
+# define ATTRIBUTE_USED
+#endif
+ATTRIBUTE_USED void CV::m(CV::t) {}
+ATTRIBUTE_USED void CV::m(CV::t) const {}
+ATTRIBUTE_USED void CV::m(CV::t) volatile {}
+ATTRIBUTE_USED void CV::m(CV::t) const volatile {}
+int CV_f (int x)
+{
+  return x + 1;
+}
+
 int
 test_function (int argc, char* argv[]) // test_function
 { // test_function
@@ -428,6 +451,8 @@ test_function (int argc, char* argv[]) // test_function
   fluff* flp = a;
   fluff** flpp = a;
 
+  CV_f(CV::i);
+
   return 0;
 }
 
index 13af2656ce6e2c5bd1e975b5e33b6e4b7a242db5..1ae7dc0c2f0fdbd521a2239b1b1864f1f7f0f6ff 100644 (file)
@@ -719,5 +719,26 @@ foreach name [get_functions list] {
     }
 }
 
+# Test c/v gets recognized even without quoting.
+foreach cv {{} { const} { volatile} { const volatile}} {
+  set test "p 'CV::m(int)$cv'"
+  gdb_test_multiple $test $test {
+      -re "( = {.*} 0x\[0-9a-f\]+ <CV::m.*>)\r\n$gdb_prompt $" {
+         # = {void (CV * const, CV::t)} 0x400944 <CV::m(int)>
+         set correct $expect_out(1,string)
+         pass $test
+      }
+  }
+  if {"$cv" != ""} {
+      setup_kfail c++/14186 *-*-*
+  }
+  gdb_test "p CV::m(int)$cv" [string_to_regexp $correct]
+}
+
+# Test TYPENAME:: gets recognized even in parentheses.
+gdb_test "p CV_f(int)"   { = {int \(int\)} 0x[0-9a-f]+ <CV_f\(int\)>}
+gdb_test "p CV_f(CV::t)" { = {int \(int\)} 0x[0-9a-f]+ <CV_f\(int\)>}
+gdb_test "p CV_f(CV::i)" " = 43"
+
 gdb_exit
 return 0
This page took 0.041538 seconds and 4 git commands to generate.