This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[dictionary] merge with recent patches to mainline


This updates carlton_dictionary-branch to match with some patches that
I've recently committed or RFA'd to mainline.  Only changes are
cosmetic.

David Carlton
carlton@kealia.com

2003-09-30  David Carlton  <carlton@kealia.com>

	* Makefile.in (c-exp.tab.o): Depend on cp_support_h.
	* c-exp.y: Include c-exp.y.  Update comments, replace
	lookup_nested_type by cp_lookup_nested_type.
	(yylex): Update comments, remove #if 0 block.
	* cp-namespace.c (cp_lookup_nested_type): Move here from symtab.c;
	rename from lookup_nested_type.
	* cp-support.h: Add cp_lookup_nested_type declaration.
	* dwarf2read.c (read_die_and_children): Update comment.
	(read_die_and_siblings): Update comment, move declaration of
	'die'.
	(read_full_die): Update comment, tweak formatting.
	* symtab.c (lookup_nested_type): Move to cp-namespace.c, rename to
	cp_lookup_nested_type.
	* symtab.h: Delete declaration of lookup_nested_type.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.262.2.36
diff -u -p -r1.262.2.36 Makefile.in
--- Makefile.in	17 Sep 2003 21:28:03 -0000	1.262.2.36
+++ Makefile.in	30 Sep 2003 17:46:57 -0000
@@ -1412,7 +1412,7 @@ ada-lex.c: ada-lex.l
 .PRECIOUS: c-exp.tab.c
 c-exp.tab.o: c-exp.tab.c $(defs_h) $(gdb_string_h) $(expression_h) \
 	$(value_h) $(parser_defs_h) $(language_h) $(c_lang_h) $(bfd_h) \
-	$(symfile_h) $(objfiles_h) $(charset_h) $(block_h)
+	$(symfile_h) $(objfiles_h) $(charset_h) $(block_h) $(cp_support_h)
 c-exp.tab.c: c-exp.y
 	$(SHELL) $(YLWRAP) "$(YACC)" \
 	    $(srcdir)/c-exp.y  y.tab.c c-exp.tmp -- $(YFLAGS) 
Index: c-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/c-exp.y,v
retrieving revision 1.15.2.12
diff -u -p -r1.15.2.12 c-exp.y
--- c-exp.y	20 Sep 2003 00:32:31 -0000	1.15.2.12
+++ c-exp.y	30 Sep 2003 17:46:58 -0000
@@ -51,6 +51,7 @@ Foundation, Inc., 59 Temple Place - Suit
 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
 #include "charset.h"
 #include "block.h"
+#include "cp-support.h"
 
 /* Flag indicating we're dealing with HP-compiled objects */ 
 extern int hp_som_som_object_present;
@@ -894,23 +895,50 @@ typebase  /* Implements (approximately):
 	| qualified_type
 	;
 
-/* FIXME: carlton/2003-09-19: This leads to lots of reduce-reduce
-   conflicts, because the parser doesn't know whether or not to use
-   qualified_name or qualified_type.  There's no good way to fix this
-   with the grammar as it stands; as far as I can tell, some of the
-   problems arise from ambiguities that GDB introduces ('start' can be
-   either an expression or a type), but some of it is inherent to the
-   nature of C++ (you want to treat the input "(FOO)" fairly
-   differently depending on whether FOO is an expression or a type,
-   and if FOO is a complex expression, this can be hard to determine
-   at the right time.
+/* FIXME: carlton/2003-09-25: This next bit leads to lots of
+   reduce-reduce conflicts, because the parser doesn't know whether or
+   not to use qualified_name or qualified_type: the rules are
+   identical.  If the parser is parsing 'A::B::x', then, when it sees
+   the second '::', it knows that the expression to the left of it has
+   to be a type, so it uses qualified_type.  But if it is parsing just
+   'A::B', then it doesn't have any way of knowing which rule to use,
+   so there's a reduce-reduce conflict; it picks qualified_name, since
+   that occurs earlier in this file than qualified_type.
+
+   There's no good way to fix this with the grammar as it stands; as
+   far as I can tell, some of the problems arise from ambiguities that
+   GDB introduces ('start' can be either an expression or a type), but
+   some of it is inherent to the nature of C++ (you want to treat the
+   input "(FOO)" fairly differently depending on whether FOO is an
+   expression or a type, and if FOO is a complex expression, this can
+   be hard to determine at the right time).  Fortunately, it works
+   pretty well in most cases.  For example, if you do 'ptype A::B',
+   where A::B is a nested type, then the parser will mistakenly
+   misidentify it as an expression; but evaluate_subexp will get
+   called with 'noside' set to EVAL_AVOID_SIDE_EFFECTS, and everything
+   will work out anyways.  But there are situations where the parser
+   will get confused: the most common one that I've run into is when
+   you want to do
+
+     print *((A::B *) x)"
+
+   where the parser doesn't realize that A::B has to be a type until
+   it hits the first right paren, at which point it's too late.  (The
+   workaround is to type "print *(('A::B' *) x)" instead.)  (And
+   another solution is to fix our symbol-handling code so that the
+   user never wants to type something like that in the first place,
+   because we get all the types right without the user's help!)
 
-   Perhaps we could fix this by making the lexer smarter.  (Some of
+   Perhaps we could fix this by making the lexer smarter.  Some of
    this functionality used to be in the lexer, but in a way that
-   worked even less well than the current solution.)  Ideally, the
-   code in question could be shared by the lexer and by decode_line_1.
-   I'm not holding my breath waiting for somebody to get around to
-   cleaning this up, however...  */
+   worked even less well than the current solution: that attempt
+   involved having the parser sometimes handle '::' and having the
+   lexer sometimes handle it, and without a clear division of
+   responsibility, it quickly degenerated into a big mess.  Probably
+   the eventual correct solution will give more of a role to the lexer
+   (ideally via code that is shared between the lexer and
+   decode_line_1), but I'm not holding my breath waiting for somebody
+   to get around to cleaning this up...  */
 
 qualified_type: typebase COLONCOLON name
 		{
@@ -927,8 +955,8 @@ qualified_type: typebase COLONCOLON name
 		    error ("`%s' is not defined as an aggregate type.",
 			   TYPE_NAME (type));
 
-		  new_type = lookup_nested_type (type, ncopy,
-						 expression_context_block);
+		  new_type = cp_lookup_nested_type (type, ncopy,
+						    expression_context_block);
 		  if (new_type == NULL)
 		    error ("No type \"%s\" within class or namespace \"%s\".",
 			   ncopy, TYPE_NAME (type));
@@ -1682,12 +1710,11 @@ yylex ()
      HP aCC compiler's generation of symbol names with embedded
      colons for namespace and nested classes. */
 
-  /* NOTE: carlton/2002-12-17: I really don't understand this
-     HP-specific stuff (here or in linespec), but it has to go away.
-     It's actually possible that it would be best to start from the
-     current HP case than from the current non-HP case: the
-     description of HP symbol names sounds like what I'm trying to get
-     symbol names to look like.  */
+  /* NOTE: carlton/2003-09-24: I don't entirely understand the
+     HP-specific code, either here or in linespec.  Having said that,
+     I suspect that we're actually moving towards their model: we want
+     symbols whose names are fully qualified, which matches the
+     description above.  */
   if (unquoted_expr)
     {
       /* Only do it if not inside single quotes */ 
@@ -1741,83 +1768,10 @@ yylex ()
 
     if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
         {
-#if 0
-	  char *p;
-	  char *namestart;
-	  struct type *best_type;
-
-	  /* Look ahead to detect nested types.  This probably should be
-	     done in the grammar, but trying seemed to introduce a lot
-	     of shift/reduce and reduce/reduce conflicts.  It's possible
-	     that it could be done, though.  Or perhaps a non-grammar, but
-	     less ad hoc, approach would work well.  */
-
-	  /* NOTE: carlton/2002-12-17: The idea of doing this in the
-	     lexer rather than the grammar seems awful to me.
-	     Unfortunately, there currently seems to be no way around
-	     it that I can see: the grammar is for either expressions
-	     or types (see the 'start' rule), so it can be used for
-	     the commands 'print' and 'ptype', and furthermore it's
-	     the parser's job to evaluate types whereas it's
-	     evaluate_expression's job to evaluate other expressions,
-	     which combine to make an awful mess.
-
-	     So, for now, we 'handle' nested types here.  Sigh.  But I
-	     really don't think this setup is a good idea: it papers
-	     over :: issues, and should fall flat on its face when
-	     dealing with initial :: operators.
-
-	     An earlier version of this code was even worse: it
-	     'dealt' with nested types by pretending they weren't
-	     nested, because of stabs limitations.  Sigh.  */
-
-	  p = lexptr;
-	  best_type = SYMBOL_TYPE (sym);
-	  while (1)
-	    {
-	      /* Skip whitespace.  */
-	      while (*p == ' ' || *p == '\t' || *p == '\n')
-		++p;
-	      if (*p == ':' && p[1] == ':')
-		{
-		  /* Skip the `::'.  */
-		  p += 2;
-		  /* Skip whitespace.  */
-		  while (*p == ' ' || *p == '\t' || *p == '\n')
-		    ++p;
-		  namestart = p;
-		  while (*p == '_' || *p == '$' || (*p >= '0' && *p <= '9')
-			 || (*p >= 'a' && *p <= 'z')
-			 || (*p >= 'A' && *p <= 'Z'))
-		    ++p;
-		  if (p != namestart)
-		    {
-		      struct type *cur_type;
-		      char *ncopy = alloca (p - namestart + 1);
-		      memcpy (ncopy, namestart, p - namestart);
-		      ncopy[p - namestart] = '\0';
-		      cur_type = lookup_nested_type (best_type,
-						     ncopy,
-						     expression_context_block);
-		      if (cur_type != NULL)
-			{
-			  best_type = cur_type;
-			  lexptr = p;
-			}
-		      else
-			break;
-		    }
-		  else
-		    break;
-		}
-	      else
-		break;
-	    }
-
-	  yylval.tsym.type = best_type;
-#else /* not 1 */
+	  /* NOTE: carlton/2003-09-25: There used to be code here to
+	     handle nested types.  It didn't work very well.  See the
+	     comment before qualified_type for more info.  */
 	  yylval.tsym.type = SYMBOL_TYPE (sym);
-#endif /* not 1 */
 	  return TYPENAME;
         }
     if ((yylval.tsym.type = lookup_primitive_typename (tmp)) != 0)
Index: cp-namespace.c
===================================================================
RCS file: /cvs/src/src/gdb/cp-namespace.c,v
retrieving revision 1.1.2.9
diff -u -p -r1.1.2.9 cp-namespace.c
--- cp-namespace.c	17 Sep 2003 21:28:13 -0000	1.1.2.9
+++ cp-namespace.c	30 Sep 2003 17:46:58 -0000
@@ -520,6 +520,51 @@ lookup_symbol_file (const char *name,
   return NULL;
 }
 
+/* Look up a type named NESTED_NAME that is nested inside the C++
+   class or namespace given by PARENT_TYPE, from within the context
+   given by BLOCK.  */
+
+struct type *
+cp_lookup_nested_type (struct type *parent_type,
+		       const char *nested_name,
+		       const struct block *block)
+{
+  switch (TYPE_CODE (parent_type))
+    {
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_NAMESPACE:
+      {
+	/* NOTE: carlton/2002-12-17: As of this writing, C++ class
+	   members of classes aren't treated like, say, data or
+	   function members.  Instead, they're just represented by
+	   symbols whose names are qualified by the name of the
+	   surrounding class.  This is just like members of
+	   namespaces; in particular, lookup_symbol_namespace works
+	   when looking them up.  */
+
+	/* NOTE: carlton/2002-12-17: The above is, actually, lying:
+	   there are still situations where nested types are
+	   represented by symbols that include only the member name,
+	   not the parent name.  Sigh.  Blame it on stabs, or
+	   something.  */
+	const char *parent_name = TYPE_TAG_NAME (parent_type);
+	struct symbol *sym = cp_lookup_symbol_namespace (parent_name,
+							 nested_name,
+							 NULL,
+							 block,
+							 VAR_DOMAIN,
+							 NULL);
+	if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
+	  return NULL;
+	else
+	  return SYMBOL_TYPE (sym);
+      }
+    default:
+      error ("\"%s\" is not defined as a compound type.",
+	     TYPE_NAME (parent_type));
+    }
+}
+
 /* Try to look up the type definition associated to NAME if honest
    methods don't work: look for NAME in the classes/namespaces that
    are currently active, on the off chance that it might be there.  */
Index: cp-support.h
===================================================================
RCS file: /cvs/src/src/gdb/cp-support.h,v
retrieving revision 1.1.2.22
diff -u -p -r1.1.2.22 cp-support.h
--- cp-support.h	20 Sep 2003 00:32:31 -0000	1.1.2.22
+++ cp-support.h	30 Sep 2003 17:46:58 -0000
@@ -102,6 +102,10 @@ extern struct symbol *cp_lookup_symbol_n
 						  const domain_enum domain,
 						  struct symtab **symtab);
 
+extern struct type *cp_lookup_nested_type (struct type *parent_type,
+					   const char *nested_name,
+					   const struct block *block);
+
 extern void cp_check_possible_namespace_symbols (const char *name,
 						 struct objfile *objfile);
 
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.66.4.35
diff -u -p -r1.66.4.35 dwarf2read.c
--- dwarf2read.c	17 Sep 2003 21:28:15 -0000	1.66.4.35
+++ dwarf2read.c	30 Sep 2003 17:46:59 -0000
@@ -4023,7 +4023,11 @@ read_comp_unit (char *info_ptr, bfd *abf
   return read_die_and_children (info_ptr, abfd, cu_header, &info_ptr, NULL);
 }
 
-/* Read a single die and all its descendents.  */
+/* Read a single die and all its descendents.  Set the die's sibling
+   field to NULL; set other fields in the die correctly, and set all
+   of the descendents' fields correctly.  Set *NEW_INFO_PTR to the
+   location of the info_ptr after reading all of those dies.  PARENT
+   is the parent of the die in question.  */
 
 static struct die_info *
 read_die_and_children (char *info_ptr, bfd *abfd,
@@ -4054,8 +4058,9 @@ read_die_and_children (char *info_ptr, b
   return die;
 }
 
-/* Helper function for read_comp_unit; it reads in a die, all of its
-   descendents, and all of its siblings.  */
+/* Read a die, all of its descendents, and all of its siblings; set
+   all of the fields of all of the dies correctly.  Arguments are as
+   in read_die_and_children.  */
 
 static struct die_info *
 read_die_and_siblings (char *info_ptr, bfd *abfd,
@@ -4063,7 +4068,7 @@ read_die_and_siblings (char *info_ptr, b
 		       char **new_info_ptr,
 		       struct die_info *parent)
 {
-  struct die_info *first_die, *last_sibling, *die;
+  struct die_info *first_die, *last_sibling;
   char *cur_ptr;
 
   cur_ptr = info_ptr;
@@ -4071,7 +4076,9 @@ read_die_and_siblings (char *info_ptr, b
 
   while (1)
     {
-      die = read_die_and_children (cur_ptr, abfd, cu_header, &cur_ptr, parent);
+      struct die_info *die
+	= read_die_and_children (cur_ptr, abfd, cu_header,
+				 &cur_ptr, parent);
 
       if (!first_die)
 	{
@@ -4421,8 +4428,9 @@ read_partial_die (struct partial_die_inf
 }
 
 /* Read the die from the .debug_info section buffer.  Set DIEP to
-   point to a newly allocated die with its information, and set
-   HAS_CHILDREN to tell whether the die has children or not.  */
+   point to a newly allocated die with its information, except for its
+   child, sibling, and parent fields.  Set HAS_CHILDREN to tell
+   whether the die has children or not.  */
 
 static char *
 read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr,
@@ -4449,8 +4457,9 @@ read_full_die (struct die_info **diep, b
   abbrev = dwarf2_lookup_abbrev (abbrev_number, cu_header);
   if (!abbrev)
     {
-      error ("Dwarf Error: could not find abbrev number %d [in module %s]", abbrev_number, 
-		      bfd_get_filename (abfd));
+      error ("Dwarf Error: could not find abbrev number %d [in module %s]",
+	     abbrev_number, 
+	     bfd_get_filename (abfd));
     }
   die = dwarf_alloc_die ();
   die->offset = offset;
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.70.2.41
diff -u -p -r1.70.2.41 symtab.c
--- symtab.c	17 Sep 2003 21:28:33 -0000	1.70.2.41
+++ symtab.c	30 Sep 2003 17:47:00 -0000
@@ -1347,53 +1347,6 @@ lookup_symbol_linkage (const char *linka
   return sym;
 }
 
-/* Look up a type named NESTED_NAME that is nested inside the C++
-   class or namespace given by PARENT_TYPE, from within the context
-   given by BLOCK.  */
-
-/* FIXME: Move to cp-namespace.c.  */
-
-struct type *
-lookup_nested_type (struct type *parent_type,
-		    const char *nested_name,
-		    const struct block *block)
-{
-  switch (TYPE_CODE (parent_type))
-    {
-    case TYPE_CODE_STRUCT:
-    case TYPE_CODE_NAMESPACE:
-      {
-	/* NOTE: carlton/2002-12-17: As of this writing, C++ class
-	   members of classes aren't treated like, say, data or
-	   function members.  Instead, they're just represented by
-	   symbols whose names are qualified by the name of the
-	   surrounding class.  This is just like members of
-	   namespaces; in particular, lookup_symbol_namespace works
-	   when looking them up.  */
-
-	/* NOTE: carlton/2002-12-17: The above is, actually, lying:
-	   there are still situations where nested types are
-	   represented by symbols that include only the member name,
-	   not the parent name.  Sigh.  Blame it on stabs, or
-	   something.  */
-	const char *parent_name = TYPE_TAG_NAME (parent_type);
-	struct symbol *sym = cp_lookup_symbol_namespace (parent_name,
-							 nested_name,
-							 NULL,
-							 block,
-							 VAR_DOMAIN,
-							 NULL);
-	if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
-	  return NULL;
-	else
-	  return SYMBOL_TYPE (sym);
-      }
-    default:
-      error ("\"%s\" is not defined as a compound type.",
-	     TYPE_NAME (parent_type));
-    }
-}
-
 /* A default version of lookup_symbol_nonlocal for use by languages
    that can't think of anything better to do.  This implements the C
    lookup rules.  */
Index: symtab.h
===================================================================
RCS file: /cvs/src/src/gdb/symtab.h,v
retrieving revision 1.42.2.30
diff -u -p -r1.42.2.30 symtab.h
--- symtab.h	17 Sep 2003 21:28:33 -0000	1.42.2.30
+++ symtab.h	30 Sep 2003 17:47:01 -0000
@@ -1024,12 +1024,6 @@ extern struct symbol *lookup_symbol_mins
 
 extern struct symbol *lookup_symbol_linkage (const char *linkage_name);
 
-/* Lookup a type within a class or a namespace.  */
-
-extern struct type *lookup_nested_type (struct type *parent_type,
-					const char *nested_name,
-					const struct block *block);
-
 /* A default version of lookup_symbol_nonlocal for use by languages
    that can't think of anything better to do.  */
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]