public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch 1/2] Add demangling for java resource files to libiberty
@ 2008-01-15  1:02 David Daney
  2008-01-15  1:23 ` [Patch 2/2] Make java compiled resources public David Daney
  2008-01-18 19:46 ` [Patch 1/2] Add demangling for java resource files to libiberty Ian Lance Taylor
  0 siblings, 2 replies; 10+ messages in thread
From: David Daney @ 2008-01-15  1:02 UTC (permalink / raw)
  To: gcc-patches, binutils, Java Patch List

[-- Attachment #1: Type: text/plain, Size: 2187 bytes --]

This is the first of a two part patch to make embedded java resources
public symbols in libgcj.a.

The patch is motivated by the fact that there are no references to the
resource files.  So when doing static linking there is no easy way to
make the linker include them in the compiled object.

The patches give the resource files public visibility with a mangled
name, this allows them to be forced into the output object.  The names
are given hidden visibility so that they do not pollute the namespace of
libgcj.so.

The mangling is as follows:

The resource name is broken into path components by '/' characters. Each component then has an '_' prepended and all '.' -> "$_" and '$' -> "$$".  The length of each component is then prepended to this and all are concatenated together and preceeded by "_ZGr".  "Gr" being an unused special-name designator that could be thought of as representing GNU-resource.  For example:

"java/util/iso4217.properties" mangles as:
"_ZGr5_java5_util20_iso4217$_properties"

This first part is to libiberty's demangler so that the mangling can be reversed.

OK to commit?

Tested on x86_64-pc-linux-gnu with no regressions.  Also tested with mipsel-linux-nm -C on a patched libgcj.a where it produces the expected results.

include/
2008-01-14  David Daney  <ddaney@avtrex.com>

	* demangle.h (demangle_component_type):  Add
	DEMANGLE_COMPONENT_JAVA_RESOURCE,
	DEMANGLE_COMPONENT_COMPOUND_NAME, and
	DEMANGLE_COMPONENT_CHARACTER as new enum values.
	(demangle_component): Add struct s_character to union u.

libiberty/
2008-01-14  David Daney  <ddaney@avtrex.com>

	* cp-demangle.c (d_dump): Handle DEMANGLE_COMPONENT_JAVA_RESOURCE,
	DEMANGLE_COMPONENT_COMPOUND_NAME, and
	DEMANGLE_COMPONENT_CHARACTER cases.
	(d_make_comp): Handle DEMANGLE_COMPONENT_COMPOUND_NAME and
	DEMANGLE_COMPONENT_JAVA_RESOURCE cases.
	(d_make_character): New function.
	(d_java_resource_part): Same.
	(d_java_resource): Same.
	(d_special_name): Handle "Gr" case.
	(d_print_comp): Handle DEMANGLE_COMPONENT_JAVA_RESOURCE,
	DEMANGLE_COMPONENT_COMPOUND_NAME, and
	DEMANGLE_COMPONENT_CHARACTER cases.
	(testsuite/demangle-expected): Add test for java resource name
	mangling.





[-- Attachment #2: demangle.patch --]
[-- Type: text/x-patch, Size: 6932 bytes --]

Index: include/demangle.h
===================================================================
RCS file: /cvs/src/src/include/demangle.h,v
retrieving revision 1.25
diff -u -p -r1.25 demangle.h
--- include/demangle.h	31 Aug 2007 20:20:44 -0000	1.25
+++ include/demangle.h	15 Jan 2008 00:21:18 -0000
@@ -362,7 +362,15 @@ enum demangle_component_type
      using 'n' instead of '-', we want a way to indicate a negative
      number which involves neither modifying the mangled string nor
      allocating a new copy of the literal in memory.  */
-  DEMANGLE_COMPONENT_LITERAL_NEG
+  DEMANGLE_COMPONENT_LITERAL_NEG,
+  /* A libgcj compiled resource.  The left subtree is the name of the
+     resource.  */
+  DEMANGLE_COMPONENT_JAVA_RESOURCE,
+  /* A name formed by the concatenation of two parts.  The left
+     subtree is the first part and the right subtree the second.  */
+  DEMANGLE_COMPONENT_COMPOUND_NAME,
+  /* A name formed by a single character.  */
+  DEMANGLE_COMPONENT_CHARACTER
 };
 
 /* Types which are only used internally.  */
@@ -448,6 +456,12 @@ struct demangle_component
       long number;
     } s_number;
 
+    /* For DEMANGLE_COMPONENT_CHARACTER.  */
+    struct
+    {
+      int character;
+    } s_character;
+
     /* For other types.  */
     struct
     {
Index: libiberty/cp-demangle.c
===================================================================
RCS file: /cvs/src/src/libiberty/cp-demangle.c,v
retrieving revision 1.69
diff -u -p -r1.69 cp-demangle.c
--- libiberty/cp-demangle.c	31 Aug 2007 20:20:49 -0000	1.69
+++ libiberty/cp-demangle.c	15 Jan 2008 00:21:31 -0000
@@ -650,6 +650,15 @@ d_dump (struct demangle_component *dc, i
     case DEMANGLE_COMPONENT_LITERAL_NEG:
       printf ("negative literal\n");
       break;
+    case DEMANGLE_COMPONENT_JAVA_RESOURCE:
+      printf ("java resource\n");
+      break;
+    case DEMANGLE_COMPONENT_COMPOUND_NAME:
+      printf ("compound name\n");
+      break;
+    case DEMANGLE_COMPONENT_CHARACTER:
+      printf ("character '%c'\n",  dc->u.s_character.character);
+      return;
     }
 
   d_dump (d_left (dc), indent + 2);
@@ -769,6 +778,7 @@ d_make_comp (struct d_info *di, enum dem
     case DEMANGLE_COMPONENT_TRINARY_ARG2:
     case DEMANGLE_COMPONENT_LITERAL:
     case DEMANGLE_COMPONENT_LITERAL_NEG:
+    case DEMANGLE_COMPONENT_COMPOUND_NAME:
       if (left == NULL || right == NULL)
 	return NULL;
       break;
@@ -795,6 +805,7 @@ d_make_comp (struct d_info *di, enum dem
     case DEMANGLE_COMPONENT_ARGLIST:
     case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
     case DEMANGLE_COMPONENT_CAST:
+    case DEMANGLE_COMPONENT_JAVA_RESOURCE:
       if (left == NULL)
 	return NULL;
       break;
@@ -1501,6 +1512,131 @@ d_operator_name (struct d_info *di)
     }
 }
 
+static struct demangle_component *
+d_make_character (struct d_info *di, int c)
+{
+  struct demangle_component *p;
+  p = d_make_empty (di);
+  if (p != NULL)
+    {
+      p->type = DEMANGLE_COMPONENT_CHARACTER;
+      p->u.s_character.character = c;
+    }
+  return p;
+}
+
+static struct demangle_component *
+d_java_resource_part (struct d_info *di)
+{
+  struct demangle_component *p = NULL;
+  struct demangle_component *next = NULL;
+  long len, i;
+  char c;
+  const char *str;
+
+  len = d_number (di);
+  if (len <= 1)
+    return NULL;
+
+  /* Eat the leading '_'.  */
+  if (d_next_char (di) != '_')
+    return NULL;
+  len--;
+
+  str = d_str (di);
+  i = 0;
+
+  while (len > 0)
+    {
+      c = str[i];
+      if (!c)
+	return NULL;
+
+      /* Each chunk is either a '$' escape...  */
+      if (c == '$')
+	{
+	  i++;
+	  switch (str[i++])
+	    {
+	    case '_':
+	      c = '.';
+	      break;
+	    case '$':
+	      c = '$';
+	      break;
+	    default:
+	      return NULL;
+	    }
+	  next = d_make_character (di, c);
+	  d_advance (di, i);
+	  str = d_str (di);
+	  len -= i;
+	  i = 0;
+	  if (next == NULL)
+	    return NULL;
+	}
+      /* ... or a sequence of characters.  */
+      else
+	{
+	  while (i < len && str[i] && str[i] != '$')
+	    i++;
+
+	  next = d_make_name (di, str, i);
+	  d_advance (di, i);
+	  str = d_str (di);
+	  len -= i;
+	  i = 0;
+	  if (next == NULL)
+	    return NULL;
+	}
+
+      if (p == NULL)
+	p = next;
+      else
+	{
+	  p = d_make_comp (di, DEMANGLE_COMPONENT_COMPOUND_NAME, p, next);
+	  if (p == NULL)
+	    return NULL;
+	}
+    }
+
+  return p;
+}
+
+static struct demangle_component *
+d_java_resource (struct d_info *di)
+{
+  struct demangle_component *p = NULL;
+  struct demangle_component *next = NULL;
+  struct demangle_component *t;
+
+  while (d_peek_char(di))
+    {
+      next = d_java_resource_part (di);
+      if (next == NULL)
+	return NULL;
+
+      if (p == NULL)
+	p = next;
+      else
+	{
+	  t = d_make_character (di, '/');
+	  if (t == NULL)
+	    return NULL;
+	  p = d_make_comp (di, DEMANGLE_COMPONENT_COMPOUND_NAME, p, t);
+	  if (p == NULL)
+	    return NULL;
+	  p = d_make_comp (di, DEMANGLE_COMPONENT_COMPOUND_NAME, p, next);
+	  if (p == NULL)
+	    return NULL;
+	}
+    }
+
+  p = d_make_comp (di, DEMANGLE_COMPONENT_JAVA_RESOURCE, p, NULL);
+
+  return p;
+}
+
 /* <special-name> ::= TV <type>
                   ::= TT <type>
                   ::= TI <type>
@@ -1514,6 +1650,7 @@ d_operator_name (struct d_info *di)
                   ::= TJ <type>
                   ::= GR <name>
 		  ::= GA <encoding>
+		  ::= Gr <resource name>
 */
 
 static struct demangle_component *
@@ -1605,6 +1742,9 @@ d_special_name (struct d_info *di)
 	  return d_make_comp (di, DEMANGLE_COMPONENT_HIDDEN_ALIAS,
 			      d_encoding (di, 0), NULL);
 
+	case 'r':
+	  return d_java_resource (di);
+
 	default:
 	  return NULL;
 	}
@@ -3552,6 +3692,20 @@ d_print_comp (struct d_print_info *dpi,
       }
       return;
 
+    case DEMANGLE_COMPONENT_JAVA_RESOURCE:
+      d_append_string (dpi, "java resource ");
+      d_print_comp (dpi, d_left (dc));
+      return;
+
+    case DEMANGLE_COMPONENT_COMPOUND_NAME:
+      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, d_right (dc));
+      return;
+
+    case DEMANGLE_COMPONENT_CHARACTER:
+      d_append_char (dpi, dc->u.s_character.character);
+      return;
+
     default:
       d_print_error (dpi);
       return;
Index: libiberty/testsuite/demangle-expected
===================================================================
RCS file: /cvs/src/src/libiberty/testsuite/demangle-expected,v
retrieving revision 1.37
diff -u -p -r1.37 demangle-expected
--- libiberty/testsuite/demangle-expected	6 May 2007 00:25:11 -0000	1.37
+++ libiberty/testsuite/demangle-expected	15 Jan 2008 00:21:33 -0000
@@ -3858,3 +3858,7 @@ foo()::var1
 --format=gnu-v3
 _ZZN7myspaceL3foo_1EvEN11localstruct1fEZNS_3fooEvE16otherlocalstruct
 myspace::foo()::localstruct::f(myspace::foo()::otherlocalstruct)
+# Java resource name
+--format=gnu-v3
+_ZGr5_java5_util20_iso4217$_properties
+java resource java/util/iso4217.properties

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Patch 2/2] Make java compiled resources public.
  2008-01-15  1:02 [Patch 1/2] Add demangling for java resource files to libiberty David Daney
@ 2008-01-15  1:23 ` David Daney
  2008-01-19 18:41   ` Tom Tromey
  2008-01-18 19:46 ` [Patch 1/2] Add demangling for java resource files to libiberty Ian Lance Taylor
  1 sibling, 1 reply; 10+ messages in thread
From: David Daney @ 2008-01-15  1:23 UTC (permalink / raw)
  To: Java Patch List; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1768 bytes --]

This is the meat of the patch.  As mentioned in the first part,  it is
part of:

...a two part patch to make embedded java resources public symbols in
libgcj.a.

The patch is motivated by the fact that there are no references to the resource files.  So when doing static linking there is no easy way to make the linker include them in the compiled object.

The patches give the resource files public visibility with a mangled name, this allows them to be forced into the output object.  The names are given hidden visibility so that they do not pollute the namespace of libgcj.so.

The mangling is as follows:

The resource name is broken into path components by '/' characters. Each component then has an '_' prepended and all '.' -> "$_" and '$' -> "$$".  The length of each component is then prepended to this and all are concatenated together and preceeded by "_ZGr".  "Gr" being an unused special-name designator that could be thought of as representing GNU-resource.  For example:

"java/util/iso4217.properties" mangles as:
"_ZGr5_java5_util20_iso4217$_properties"

This patch is nearly identical to http://gcc.gnu.org/ml/java-patches/2007-q4/msg00100.html , but incorporates Jakub's suggestions.

As before tested on x86-64-pc-linux-gnu with make check in libjava with no FAILures.

OK to commit?

2008-01-14  David Daney  <ddaney@avtrex.com>

	* class.c (hide)  Rename to...
	(java_hide_decl) ... this throughout, and make public.
	* resource.c (Jr_count): Remove.
	(compile_resource_data): Call java_mangle_resource_name to generate
	decl name.  Make resource decl public and hidden.
	* mangle.c (append_resource_name_hunk): New function.
	(java_mangle_resource_name): Same.
	* java-tree.h (java_hide_decl, java_mangle_resource_name): Declare
	functions.




[-- Attachment #2: resource.diff --]
[-- Type: text/x-patch, Size: 6324 bytes --]

Index: class.c
===================================================================
--- class.c	(revision 131121)
+++ class.c	(working copy)
@@ -742,8 +742,8 @@ build_java_method_type (tree fntype, tre
   return fntype;
 }
 
-static void
-hide (tree decl ATTRIBUTE_UNUSED)
+void
+java_hide_decl (tree decl ATTRIBUTE_UNUSED)
 {
 #ifdef HAVE_GAS_HIDDEN
   DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
@@ -872,7 +872,7 @@ add_field (tree class, tree name, tree f
       /* Hide everything that shouldn't be visible outside a DSO.  */
       if (flag_indirect_classes
 	  || (FIELD_PRIVATE (field)))
-	hide (field);
+	java_hide_decl (field);
       /* Considered external unless we are compiling it into this
 	 object file.  */
       DECL_EXTERNAL (field) = (is_compiled_class (class) != 2);
@@ -1031,7 +1031,7 @@ build_static_class_ref (tree type)
 	{
 	  TREE_PUBLIC (decl) = 1;
 	  if (CLASS_PRIVATE (TYPE_NAME (type)))
-	    hide (decl);
+	    java_hide_decl (decl);
 	}
       DECL_IGNORED_P (decl) = 1;
       DECL_ARTIFICIAL (decl) = 1;
@@ -1071,7 +1071,7 @@ build_classdollar_field (tree type)
       TREE_CONSTANT (decl) = 1;
       TREE_READONLY (decl) = 1;
       TREE_PUBLIC (decl) = 1;
-      hide (decl);
+      java_hide_decl (decl);
       DECL_IGNORED_P (decl) = 1;
       DECL_ARTIFICIAL (decl) = 1;
       MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
@@ -1760,7 +1760,7 @@ make_class_data (tree type)
       /* The only dispatch table exported from a DSO is the dispatch
 	 table for java.lang.Class.  */
       if (DECL_NAME (type_decl) != id_class)
-	hide (dtable_decl);
+	java_hide_decl (dtable_decl);
       if (! flag_indirect_classes)
 	rest_of_decl_compilation (dtable_decl, 1, 0);
       /* Maybe we're compiling Class as the first class.  If so, set
@@ -2613,7 +2613,7 @@ layout_class_method (tree this_class, tr
       || (METHOD_PRIVATE (method_decl) && METHOD_STATIC (method_decl)
 	  && ! METHOD_NATIVE (method_decl)
 	  && ! special_method_p (method_decl)))
-    hide (method_decl);
+    java_hide_decl (method_decl);
 
   /* Considered external unless it is being compiled into this object
      file, or it was already flagged as external.  */
Index: resource.c
===================================================================
--- resource.c	(revision 131121)
+++ resource.c	(working copy)
@@ -51,14 +51,10 @@ The Free Software Foundation is independ
 /* A list of all the resources files.  */
 static GTY(()) tree resources = NULL;
 
-/* Count of all the resources compiled in this invocation.  */
-static int Jr_count = 0;
-
 void
 compile_resource_data (const char *name, const char *buffer, int length)
 {
   tree rtype, field = NULL_TREE, data_type, rinit, data, decl;
-  char buf[60];
 
   data_type = build_prim_array_type (unsigned_byte_type_node,
 				     strlen (name) + length);
@@ -79,11 +75,10 @@ compile_resource_data (const char *name,
   TREE_CONSTANT (rinit) = 1;
   TREE_INVARIANT (rinit) = 1;
 
-  /* Generate a unique-enough identifier.  */
-  sprintf (buf, "_Jr%d", ++Jr_count);
-
-  decl = build_decl (VAR_DECL, get_identifier (buf), rtype);
+  decl = build_decl (VAR_DECL, java_mangle_resource_name (name), rtype);
   TREE_STATIC (decl) = 1;
+  TREE_PUBLIC (decl) = 1;
+  java_hide_decl (decl);
   DECL_ARTIFICIAL (decl) = 1;
   DECL_IGNORED_P (decl) = 1;
   TREE_READONLY (decl) = 1;
Index: mangle.c
===================================================================
--- mangle.c	(revision 131121)
+++ mangle.c	(working copy)
@@ -796,6 +796,86 @@ compression_table_add (tree type)
   TREE_VEC_ELT (compression_table, compression_next++) = type;
 }
 
+/* Prepend '_' so leading digits are encoded properly.  Also replace
+   '.' with "$_" and '$' with "$$".  The result is encoded with
+   append_gpp_mangled_name.  */
+
+static void
+append_resource_name_hunk(const unsigned char *hunk, int len)
+{
+  /* We need twice the length if all characters are escaped.  */
+  unsigned char *n = (unsigned char *)alloca (2 * len + 1);
+  unsigned char *d;
+  const unsigned char *w1;
+  const unsigned char *w2;
+  const unsigned char *limit;
+
+  d = n;
+
+  *d++ = '_';
+  memcpy (n + 1, hunk, len);
+
+  w1 = hunk;
+  limit = hunk + len;
+  while (w1 < limit)
+    {
+      int ch;
+      w2 = w1;
+      ch = UTF8_GET(w1, limit);
+      gcc_assert (ch > 0);
+      if (ch == '.')
+	{
+	  *d++ = '$';
+	  *d++ = '_';
+	}
+      else if (ch == '$')
+	{
+	  *d++ = '$';
+	  *d++ = '$';
+	}
+      else
+	{
+	  memcpy (d, w2, w1 - w2);
+	  d += w1 - w2;
+	}
+    }
+  append_gpp_mangled_name ((char *)n, d - n);
+}
+
+/* Mangle an embedded resource file name.  Each path component is
+   encoded with append_resource_name_hunk.  */
+
+tree
+java_mangle_resource_name (const char *name)
+{
+  const unsigned char *ptr;
+  const unsigned char *start_of_hunk;
+  const unsigned char *end_of_hunk;
+  const unsigned char *limit = (const unsigned char *)name + strlen(name);
+
+  init_mangling ();
+  MANGLE_RAW_STRING ("Gr");
+
+  ptr = (const unsigned char *)name;
+
+  while (ptr < limit)
+    {
+      start_of_hunk = ptr;
+      end_of_hunk = ptr;
+      while (ptr < limit)
+	{
+	  int ch;
+	  ch = UTF8_GET(ptr, limit);
+	  if (ch == '/')
+	    break;
+	  end_of_hunk = ptr;
+	}
+      append_resource_name_hunk (start_of_hunk, end_of_hunk - start_of_hunk);
+    }
+
+  return finish_mangling ();
+}
+
 /* Mangling initialization routine.  */
 
 static void
Index: java-tree.h
===================================================================
--- java-tree.h	(revision 131121)
+++ java-tree.h	(working copy)
@@ -1026,6 +1026,7 @@ extern tree parse_signature (struct JCF 
 extern tree add_field (tree, tree, tree, int);
 extern tree add_method (tree, int, tree, tree);
 extern tree add_method_1 (tree, int, tree, tree);
+extern void java_hide_decl (tree);
 extern tree make_class (void);
 extern tree push_class (tree, tree);
 extern tree unmangle_classname (const char *name, int name_length);
@@ -1205,6 +1206,7 @@ extern void java_check_methods (tree);
 extern void java_mangle_decl (tree);
 extern tree java_mangle_class_field (struct obstack *, tree);
 extern tree java_mangle_vtable (struct obstack *, tree);
+extern tree java_mangle_resource_name (const char *);
 extern void append_gpp_mangled_name (const char *, int);
 
 extern void add_predefined_file (tree);

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Patch 1/2] Add demangling for java resource files to libiberty
  2008-01-15  1:02 [Patch 1/2] Add demangling for java resource files to libiberty David Daney
  2008-01-15  1:23 ` [Patch 2/2] Make java compiled resources public David Daney
@ 2008-01-18 19:46 ` Ian Lance Taylor
  2008-01-25 22:10   ` David Daney
  1 sibling, 1 reply; 10+ messages in thread
From: Ian Lance Taylor @ 2008-01-18 19:46 UTC (permalink / raw)
  To: David Daney; +Cc: gcc-patches, binutils, Java Patch List

David Daney <ddaney@avtrex.com> writes:

> 2008-01-14  David Daney  <ddaney@avtrex.com>
> 
> 	* demangle.h (demangle_component_type):  Add
> 	DEMANGLE_COMPONENT_JAVA_RESOURCE,
> 	DEMANGLE_COMPONENT_COMPOUND_NAME, and
> 	DEMANGLE_COMPONENT_CHARACTER as new enum values.
> 	(demangle_component): Add struct s_character to union u.
> 
> libiberty/
> 2008-01-14  David Daney  <ddaney@avtrex.com>
> 
> 	* cp-demangle.c (d_dump): Handle DEMANGLE_COMPONENT_JAVA_RESOURCE,
> 	DEMANGLE_COMPONENT_COMPOUND_NAME, and
> 	DEMANGLE_COMPONENT_CHARACTER cases.
> 	(d_make_comp): Handle DEMANGLE_COMPONENT_COMPOUND_NAME and
> 	DEMANGLE_COMPONENT_JAVA_RESOURCE cases.
> 	(d_make_character): New function.
> 	(d_java_resource_part): Same.
> 	(d_java_resource): Same.
> 	(d_special_name): Handle "Gr" case.
> 	(d_print_comp): Handle DEMANGLE_COMPONENT_JAVA_RESOURCE,
> 	DEMANGLE_COMPONENT_COMPOUND_NAME, and
> 	DEMANGLE_COMPONENT_CHARACTER cases.
> 	(testsuite/demangle-expected): Add test for java resource name
> 	mangling.


This patch is OK.  It is OK for gcc 4.3 if the other part of the patch
(to libjava) is committed to gcc 4.3.  Otherwise please wait until
after the 4.3 release branch is made.


> +  while (d_peek_char(di))

Please add a space before the left parenthesis.


Thanks.

Ian

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Patch 2/2] Make java compiled resources public.
  2008-01-15  1:23 ` [Patch 2/2] Make java compiled resources public David Daney
@ 2008-01-19 18:41   ` Tom Tromey
  2008-01-22 22:00     ` David Daney
  0 siblings, 1 reply; 10+ messages in thread
From: Tom Tromey @ 2008-01-19 18:41 UTC (permalink / raw)
  To: David Daney; +Cc: Java Patch List, gcc-patches

>>>>> "David" == David Daney <ddaney@avtrex.com> writes:

David> OK to commit?

There are some whitespace problems with this patch, but otherwise it
is ok.  Thanks.

Also, would you mind replying to Gerald's notes on the documentation
patch?  I didn't see a reply to that.

David> +static void
David> +append_resource_name_hunk(const unsigned char *hunk, int len)

Space before '('.

David> +  unsigned char *n = (unsigned char *)alloca (2 * len + 1);

Space after ')'.

David> +      ch = UTF8_GET(w1, limit);

...

David> +  append_gpp_mangled_name ((char *)n, d - n);

...

David> +  const unsigned char *limit = (const unsigned char *)name + strlen(name);

...

David> +	  ch = UTF8_GET(ptr, limit);

...

Tom

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Patch 2/2] Make java compiled resources public.
  2008-01-19 18:41   ` Tom Tromey
@ 2008-01-22 22:00     ` David Daney
  2008-01-23 11:40       ` Andrew Haley
  0 siblings, 1 reply; 10+ messages in thread
From: David Daney @ 2008-01-22 22:00 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Java Patch List, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1827 bytes --]

Tom Tromey wrote:
>>>>>> "David" == David Daney <ddaney@avtrex.com> writes:
>>>>>>             
>
> David> OK to commit?
>
> There are some whitespace problems with this patch, but otherwise it
> is ok.  Thanks.
>   
This is an alternative version that I think may be better.  From IRC:

(11:47:20 AM) iant_work: daney: I suppose the alternative scheme would
be to use a single string, and also use an encoding for '/'
(11:47:31 AM) iant_work: is there an advantage to breaking it up?
(11:47:39 AM) iant_work: I don't care all that much myself
(11:49:18 AM) daney: I had considered that.  Internally to the java
runtime the breaking of the names on '/' signify parts of a path, but as
far as the name is concerned, it probably does not matter.
(11:49:59 AM) iant_work: daney: I don't care all that much; the mangling
will be simpler if you use a single string; but if separate strings is
better for some reason, it's OK with me
(11:50:45 AM) daney: The mangling would be shorter with a single string.
 I will change it.

The new version has the form: _ZGr##escaped_name, where ## is the length
of the escaped name.  I think the code (in jc1 as well as the
un-mangler) is cleaner and the mangled names are shorter (or the same
length).

This new version also bootstrapped on x86_64 with no failures in libjava.

OK to commit, or do you think the previous version is preferable?

2008-01-22  David Daney  <ddaney@avtrex.com>

    * class.c (hide)  Rename to...
    (java_hide_decl) ... this throughout, and make public.
    * resource.c (Jr_count): Remove.
    (compile_resource_data): Call java_mangle_resource_name to generate
    decl name.  Make resource decl public and hidden.
    * mangle.c (java_mangle_resource_name): New function.
    * java-tree.h (java_hide_decl, java_mangle_resource_name): Declare
    functions.



[-- Attachment #2: resource.diff --]
[-- Type: text/x-patch, Size: 5581 bytes --]

Index: class.c
===================================================================
--- class.c	(revision 131725)
+++ class.c	(working copy)
@@ -742,8 +742,8 @@ build_java_method_type (tree fntype, tre
   return fntype;
 }
 
-static void
-hide (tree decl ATTRIBUTE_UNUSED)
+void
+java_hide_decl (tree decl ATTRIBUTE_UNUSED)
 {
 #ifdef HAVE_GAS_HIDDEN
   DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
@@ -872,7 +872,7 @@ add_field (tree class, tree name, tree f
       /* Hide everything that shouldn't be visible outside a DSO.  */
       if (flag_indirect_classes
 	  || (FIELD_PRIVATE (field)))
-	hide (field);
+	java_hide_decl (field);
       /* Considered external unless we are compiling it into this
 	 object file.  */
       DECL_EXTERNAL (field) = (is_compiled_class (class) != 2);
@@ -1031,7 +1031,7 @@ build_static_class_ref (tree type)
 	{
 	  TREE_PUBLIC (decl) = 1;
 	  if (CLASS_PRIVATE (TYPE_NAME (type)))
-	    hide (decl);
+	    java_hide_decl (decl);
 	}
       DECL_IGNORED_P (decl) = 1;
       DECL_ARTIFICIAL (decl) = 1;
@@ -1071,7 +1071,7 @@ build_classdollar_field (tree type)
       TREE_CONSTANT (decl) = 1;
       TREE_READONLY (decl) = 1;
       TREE_PUBLIC (decl) = 1;
-      hide (decl);
+      java_hide_decl (decl);
       DECL_IGNORED_P (decl) = 1;
       DECL_ARTIFICIAL (decl) = 1;
       MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
@@ -1760,7 +1760,7 @@ make_class_data (tree type)
       /* The only dispatch table exported from a DSO is the dispatch
 	 table for java.lang.Class.  */
       if (DECL_NAME (type_decl) != id_class)
-	hide (dtable_decl);
+	java_hide_decl (dtable_decl);
       if (! flag_indirect_classes)
 	rest_of_decl_compilation (dtable_decl, 1, 0);
       /* Maybe we're compiling Class as the first class.  If so, set
@@ -2613,7 +2613,7 @@ layout_class_method (tree this_class, tr
       || (METHOD_PRIVATE (method_decl) && METHOD_STATIC (method_decl)
 	  && ! METHOD_NATIVE (method_decl)
 	  && ! special_method_p (method_decl)))
-    hide (method_decl);
+    java_hide_decl (method_decl);
 
   /* Considered external unless it is being compiled into this object
      file, or it was already flagged as external.  */
Index: resource.c
===================================================================
--- resource.c	(revision 131725)
+++ resource.c	(working copy)
@@ -51,14 +51,10 @@ The Free Software Foundation is independ
 /* A list of all the resources files.  */
 static GTY(()) tree resources = NULL;
 
-/* Count of all the resources compiled in this invocation.  */
-static int Jr_count = 0;
-
 void
 compile_resource_data (const char *name, const char *buffer, int length)
 {
   tree rtype, field = NULL_TREE, data_type, rinit, data, decl;
-  char buf[60];
 
   data_type = build_prim_array_type (unsigned_byte_type_node,
 				     strlen (name) + length);
@@ -79,11 +75,10 @@ compile_resource_data (const char *name,
   TREE_CONSTANT (rinit) = 1;
   TREE_INVARIANT (rinit) = 1;
 
-  /* Generate a unique-enough identifier.  */
-  sprintf (buf, "_Jr%d", ++Jr_count);
-
-  decl = build_decl (VAR_DECL, get_identifier (buf), rtype);
+  decl = build_decl (VAR_DECL, java_mangle_resource_name (name), rtype);
   TREE_STATIC (decl) = 1;
+  TREE_PUBLIC (decl) = 1;
+  java_hide_decl (decl);
   DECL_ARTIFICIAL (decl) = 1;
   DECL_IGNORED_P (decl) = 1;
   TREE_READONLY (decl) = 1;
Index: mangle.c
===================================================================
--- mangle.c	(revision 131725)
+++ mangle.c	(working copy)
@@ -796,6 +796,56 @@ compression_table_add (tree type)
   TREE_VEC_ELT (compression_table, compression_next++) = type;
 }
 
+/* Mangle an embedded resource file name.  "_ZGr" is the prefix, The
+   length and then the name itself of the resource name is appended
+   while escaping '$', '.', and '/' to: "$$", "$_", and "$S".  */
+
+tree
+java_mangle_resource_name (const char *name)
+{
+  int len = strlen (name);
+  char *n = (char *) alloca (2 * len + 1);
+  char *d;
+  const unsigned char *w1 = (unsigned char *) name;
+  const unsigned char *w2;
+  const unsigned char *limit = w1 + len;
+
+  d = n;
+
+  init_mangling ();
+  MANGLE_RAW_STRING ("Gr");
+
+  while (w1 < limit)
+    {
+      int ch;
+      w2 = w1;
+      ch = UTF8_GET (w1, limit);
+      gcc_assert (ch > 0);
+      switch (ch)
+	{
+	case '$':
+	  *d++ = '$';
+	  *d++ = '$';
+	  break;
+	case '.':
+	  *d++ = '$';
+	  *d++ = '_';
+	  break;
+	case '/':
+	  *d++ = '$';
+	  *d++ = 'S';
+	  break;
+	default:
+	  memcpy (d, w2, w1 - w2);
+	  d += w1 - w2;
+	  break;
+	}
+    }
+  append_gpp_mangled_name (n, d - n);
+
+  return finish_mangling ();
+}
+
 /* Mangling initialization routine.  */
 
 static void
Index: java-tree.h
===================================================================
--- java-tree.h	(revision 131725)
+++ java-tree.h	(working copy)
@@ -1026,6 +1026,7 @@ extern tree parse_signature (struct JCF 
 extern tree add_field (tree, tree, tree, int);
 extern tree add_method (tree, int, tree, tree);
 extern tree add_method_1 (tree, int, tree, tree);
+extern void java_hide_decl (tree);
 extern tree make_class (void);
 extern tree push_class (tree, tree);
 extern tree unmangle_classname (const char *name, int name_length);
@@ -1205,6 +1206,7 @@ extern void java_check_methods (tree);
 extern void java_mangle_decl (tree);
 extern tree java_mangle_class_field (struct obstack *, tree);
 extern tree java_mangle_vtable (struct obstack *, tree);
+extern tree java_mangle_resource_name (const char *);
 extern void append_gpp_mangled_name (const char *, int);
 
 extern void add_predefined_file (tree);

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Patch 2/2] Make java compiled resources public.
  2008-01-22 22:00     ` David Daney
@ 2008-01-23 11:40       ` Andrew Haley
  2008-01-23 23:05         ` David Daney
  0 siblings, 1 reply; 10+ messages in thread
From: Andrew Haley @ 2008-01-23 11:40 UTC (permalink / raw)
  To: David Daney; +Cc: Tom Tromey, Java Patch List, gcc-patches

David Daney wrote:
> Tom Tromey wrote:
>>>>>>> "David" == David Daney <ddaney@avtrex.com> writes:
>>>>>>>             
>> David> OK to commit?
>>
>> There are some whitespace problems with this patch, but otherwise it
>> is ok.  Thanks.
>>   
> This is an alternative version that I think may be better.  From IRC:
> 
> (11:47:20 AM) iant_work: daney: I suppose the alternative scheme would
> be to use a single string, and also use an encoding for '/'
> (11:47:31 AM) iant_work: is there an advantage to breaking it up?
> (11:47:39 AM) iant_work: I don't care all that much myself
> (11:49:18 AM) daney: I had considered that.  Internally to the java
> runtime the breaking of the names on '/' signify parts of a path, but as
> far as the name is concerned, it probably does not matter.
> (11:49:59 AM) iant_work: daney: I don't care all that much; the mangling
> will be simpler if you use a single string; but if separate strings is
> better for some reason, it's OK with me
> (11:50:45 AM) daney: The mangling would be shorter with a single string.
>  I will change it.
> 
> The new version has the form: _ZGr##escaped_name, where ## is the length
> of the escaped name.  I think the code (in jc1 as well as the
> un-mangler) is cleaner and the mangled names are shorter (or the same
> length).
> 
> This new version also bootstrapped on x86_64 with no failures in libjava.
> 
> OK to commit, or do you think the previous version is preferable?
> 
> 2008-01-22  David Daney  <ddaney@avtrex.com>
> 
>     * class.c (hide)  Rename to...
>     (java_hide_decl) ... this throughout, and make public.
>     * resource.c (Jr_count): Remove.
>     (compile_resource_data): Call java_mangle_resource_name to generate
>     decl name.  Make resource decl public and hidden.
>     * mangle.c (java_mangle_resource_name): New function.
>     * java-tree.h (java_hide_decl, java_mangle_resource_name): Declare
>     functions.
> 

This looks good, thanks.  One small nit: please don't use identifiers such
as "n" as names of variables of pointer type.  :-)

Otherwise OK.

Andrew.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Patch 2/2] Make java compiled resources public.
  2008-01-23 11:40       ` Andrew Haley
@ 2008-01-23 23:05         ` David Daney
  0 siblings, 0 replies; 10+ messages in thread
From: David Daney @ 2008-01-23 23:05 UTC (permalink / raw)
  To: Java Patch List; +Cc: Andrew Haley, Tom Tromey, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2898 bytes --]

Andrew Haley wrote:
> David Daney wrote:
>> Tom Tromey wrote:
>>>>>>>> "David" == David Daney <ddaney@avtrex.com> writes:
>>>>>>>>             
>>> David> OK to commit?
>>>
>>> There are some whitespace problems with this patch, but otherwise it
>>> is ok.  Thanks.
>>>   
>> This is an alternative version that I think may be better.  From IRC:
>>
>> (11:47:20 AM) iant_work: daney: I suppose the alternative scheme would
>> be to use a single string, and also use an encoding for '/'
>> (11:47:31 AM) iant_work: is there an advantage to breaking it up?
>> (11:47:39 AM) iant_work: I don't care all that much myself
>> (11:49:18 AM) daney: I had considered that.  Internally to the java
>> runtime the breaking of the names on '/' signify parts of a path, but as
>> far as the name is concerned, it probably does not matter.
>> (11:49:59 AM) iant_work: daney: I don't care all that much; the mangling
>> will be simpler if you use a single string; but if separate strings is
>> better for some reason, it's OK with me
>> (11:50:45 AM) daney: The mangling would be shorter with a single string.
>>  I will change it.
>>
>> The new version has the form: _ZGr##escaped_name, where ## is the length
>> of the escaped name.  I think the code (in jc1 as well as the
>> un-mangler) is cleaner and the mangled names are shorter (or the same
>> length).
>>
>> This new version also bootstrapped on x86_64 with no failures in
>> libjava.
>>
>> OK to commit, or do you think the previous version is preferable?
>>
>> 2008-01-22  David Daney  <ddaney@avtrex.com>
>>
>>     * class.c (hide)  Rename to...
>>     (java_hide_decl) ... this throughout, and make public.
>>     * resource.c (Jr_count): Remove.
>>     (compile_resource_data): Call java_mangle_resource_name to generate
>>     decl name.  Make resource decl public and hidden.
>>     * mangle.c (java_mangle_resource_name): New function.
>>     * java-tree.h (java_hide_decl, java_mangle_resource_name): Declare
>>     functions.
>>
>
> This looks good, thanks.  One small nit: please don't use identifiers
> such
> as "n" as names of variables of pointer type.  :-)
While the name "n" carries meaning in my world view, I have changed it
for the benefit of others.

>
> Otherwise OK.
Thanks.  This is what I committed.  It differes from the previous
version in the name of the variables as well as a '_' prepended to the
mangled form to allow the demangler to work with names starting with a
digit.

2008-01-23  David Daney  <ddaney@avtrex.com>

    * class.c (hide)  Rename to...
    (java_hide_decl) ... this throughout, and make public.
    * resource.c (Jr_count): Remove.
    (compile_resource_data): Call java_mangle_resource_name to generate
    decl name.  Make resource decl public and hidden.
    * mangle.c (java_mangle_resource_name): New function.
    * java-tree.h (java_hide_decl, java_mangle_resource_name): Declare
    functions.


[-- Attachment #2: resource.diff --]
[-- Type: text/x-patch, Size: 5719 bytes --]

Index: class.c
===================================================================
--- class.c	(revision 131766)
+++ class.c	(working copy)
@@ -742,8 +742,8 @@ build_java_method_type (tree fntype, tre
   return fntype;
 }
 
-static void
-hide (tree decl ATTRIBUTE_UNUSED)
+void
+java_hide_decl (tree decl ATTRIBUTE_UNUSED)
 {
 #ifdef HAVE_GAS_HIDDEN
   DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
@@ -872,7 +872,7 @@ add_field (tree class, tree name, tree f
       /* Hide everything that shouldn't be visible outside a DSO.  */
       if (flag_indirect_classes
 	  || (FIELD_PRIVATE (field)))
-	hide (field);
+	java_hide_decl (field);
       /* Considered external unless we are compiling it into this
 	 object file.  */
       DECL_EXTERNAL (field) = (is_compiled_class (class) != 2);
@@ -1031,7 +1031,7 @@ build_static_class_ref (tree type)
 	{
 	  TREE_PUBLIC (decl) = 1;
 	  if (CLASS_PRIVATE (TYPE_NAME (type)))
-	    hide (decl);
+	    java_hide_decl (decl);
 	}
       DECL_IGNORED_P (decl) = 1;
       DECL_ARTIFICIAL (decl) = 1;
@@ -1071,7 +1071,7 @@ build_classdollar_field (tree type)
       TREE_CONSTANT (decl) = 1;
       TREE_READONLY (decl) = 1;
       TREE_PUBLIC (decl) = 1;
-      hide (decl);
+      java_hide_decl (decl);
       DECL_IGNORED_P (decl) = 1;
       DECL_ARTIFICIAL (decl) = 1;
       MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
@@ -1760,7 +1760,7 @@ make_class_data (tree type)
       /* The only dispatch table exported from a DSO is the dispatch
 	 table for java.lang.Class.  */
       if (DECL_NAME (type_decl) != id_class)
-	hide (dtable_decl);
+	java_hide_decl (dtable_decl);
       if (! flag_indirect_classes)
 	rest_of_decl_compilation (dtable_decl, 1, 0);
       /* Maybe we're compiling Class as the first class.  If so, set
@@ -2613,7 +2613,7 @@ layout_class_method (tree this_class, tr
       || (METHOD_PRIVATE (method_decl) && METHOD_STATIC (method_decl)
 	  && ! METHOD_NATIVE (method_decl)
 	  && ! special_method_p (method_decl)))
-    hide (method_decl);
+    java_hide_decl (method_decl);
 
   /* Considered external unless it is being compiled into this object
      file, or it was already flagged as external.  */
Index: resource.c
===================================================================
--- resource.c	(revision 131766)
+++ resource.c	(working copy)
@@ -51,14 +51,10 @@ The Free Software Foundation is independ
 /* A list of all the resources files.  */
 static GTY(()) tree resources = NULL;
 
-/* Count of all the resources compiled in this invocation.  */
-static int Jr_count = 0;
-
 void
 compile_resource_data (const char *name, const char *buffer, int length)
 {
   tree rtype, field = NULL_TREE, data_type, rinit, data, decl;
-  char buf[60];
 
   data_type = build_prim_array_type (unsigned_byte_type_node,
 				     strlen (name) + length);
@@ -79,11 +75,10 @@ compile_resource_data (const char *name,
   TREE_CONSTANT (rinit) = 1;
   TREE_INVARIANT (rinit) = 1;
 
-  /* Generate a unique-enough identifier.  */
-  sprintf (buf, "_Jr%d", ++Jr_count);
-
-  decl = build_decl (VAR_DECL, get_identifier (buf), rtype);
+  decl = build_decl (VAR_DECL, java_mangle_resource_name (name), rtype);
   TREE_STATIC (decl) = 1;
+  TREE_PUBLIC (decl) = 1;
+  java_hide_decl (decl);
   DECL_ARTIFICIAL (decl) = 1;
   DECL_IGNORED_P (decl) = 1;
   TREE_READONLY (decl) = 1;
Index: mangle.c
===================================================================
--- mangle.c	(revision 131766)
+++ mangle.c	(working copy)
@@ -796,6 +796,59 @@ compression_table_add (tree type)
   TREE_VEC_ELT (compression_table, compression_next++) = type;
 }
 
+/* Mangle an embedded resource file name.  "_ZGr" is the prefix.  A
+   '_' is prepended to the name so that names starting with a digit
+   can be demangled.  The length and then the resulting name itself
+   are appended while escaping '$', '.', and '/' to: "$$", "$_", and
+   "$S".  */
+
+tree
+java_mangle_resource_name (const char *name)
+{
+  int len = strlen (name);
+  char *buf = (char *) alloca (2 * len + 1);
+  char *pos;
+  const unsigned char *w1 = (const unsigned char *) name;
+  const unsigned char *w2;
+  const unsigned char *limit = w1 + len;
+
+  pos = buf;
+
+  init_mangling ();
+  MANGLE_RAW_STRING ("Gr");
+
+  *pos++ = '_';
+  while (w1 < limit)
+    {
+      int ch;
+      w2 = w1;
+      ch = UTF8_GET (w1, limit);
+      gcc_assert (ch > 0);
+      switch (ch)
+	{
+	case '$':
+	  *pos++ = '$';
+	  *pos++ = '$';
+	  break;
+	case '.':
+	  *pos++ = '$';
+	  *pos++ = '_';
+	  break;
+	case '/':
+	  *pos++ = '$';
+	  *pos++ = 'S';
+	  break;
+	default:
+	  memcpy (pos, w2, w1 - w2);
+	  pos += w1 - w2;
+	  break;
+	}
+    }
+  append_gpp_mangled_name (buf, pos - buf);
+
+  return finish_mangling ();
+}
+
 /* Mangling initialization routine.  */
 
 static void
Index: java-tree.h
===================================================================
--- java-tree.h	(revision 131766)
+++ java-tree.h	(working copy)
@@ -1026,6 +1026,7 @@ extern tree parse_signature (struct JCF 
 extern tree add_field (tree, tree, tree, int);
 extern tree add_method (tree, int, tree, tree);
 extern tree add_method_1 (tree, int, tree, tree);
+extern void java_hide_decl (tree);
 extern tree make_class (void);
 extern tree push_class (tree, tree);
 extern tree unmangle_classname (const char *name, int name_length);
@@ -1205,6 +1206,7 @@ extern void java_check_methods (tree);
 extern void java_mangle_decl (tree);
 extern tree java_mangle_class_field (struct obstack *, tree);
 extern tree java_mangle_vtable (struct obstack *, tree);
+extern tree java_mangle_resource_name (const char *);
 extern void append_gpp_mangled_name (const char *, int);
 
 extern void add_predefined_file (tree);

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Patch 1/2] Add demangling for java resource files to libiberty
  2008-01-18 19:46 ` [Patch 1/2] Add demangling for java resource files to libiberty Ian Lance Taylor
@ 2008-01-25 22:10   ` David Daney
  2008-01-27  5:41     ` Ian Lance Taylor
  0 siblings, 1 reply; 10+ messages in thread
From: David Daney @ 2008-01-25 22:10 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-patches, binutils, Java Patch List

[-- Attachment #1: Type: text/plain, Size: 2478 bytes --]

Ian Lance Taylor wrote:
> David Daney <ddaney@avtrex.com> writes:
>
>   
>> 2008-01-14  David Daney  <ddaney@avtrex.com>
>>
>> 	* demangle.h (demangle_component_type):  Add
>> 	DEMANGLE_COMPONENT_JAVA_RESOURCE,
>> 	DEMANGLE_COMPONENT_COMPOUND_NAME, and
>> 	DEMANGLE_COMPONENT_CHARACTER as new enum values.
>> 	(demangle_component): Add struct s_character to union u.
>>
>> libiberty/
>> 2008-01-14  David Daney  <ddaney@avtrex.com>
>>
>> 	* cp-demangle.c (d_dump): Handle DEMANGLE_COMPONENT_JAVA_RESOURCE,
>> 	DEMANGLE_COMPONENT_COMPOUND_NAME, and
>> 	DEMANGLE_COMPONENT_CHARACTER cases.
>> 	(d_make_comp): Handle DEMANGLE_COMPONENT_COMPOUND_NAME and
>> 	DEMANGLE_COMPONENT_JAVA_RESOURCE cases.
>> 	(d_make_character): New function.
>> 	(d_java_resource_part): Same.
>> 	(d_java_resource): Same.
>> 	(d_special_name): Handle "Gr" case.
>> 	(d_print_comp): Handle DEMANGLE_COMPONENT_JAVA_RESOURCE,
>> 	DEMANGLE_COMPONENT_COMPOUND_NAME, and
>> 	DEMANGLE_COMPONENT_CHARACTER cases.
>> 	(testsuite/demangle-expected): Add test for java resource name
>> 	mangling.
>>     
>
>
> This patch is OK.  It is OK for gcc 4.3 if the other part of the patch
> (to libjava) is committed to gcc 4.3.  Otherwise please wait until
> after the 4.3 release branch is made.
>
>   
A slightly different mangling scheme was committed based on IRC discussions:
http://gcc.gnu.org/ml/java-patches/2008-q1/msg00026.html

This is the corresponding demangler patch.

Tested on x86_64-pc-linux-gnu.

OK to commit to 4.3?  Or should it wait for the branch?

include/
2008-01-14  David Daney  <ddaney@avtrex.com>

    * demangle.h (demangle_component_type):  Add
    DEMANGLE_COMPONENT_JAVA_RESOURCE,
    DEMANGLE_COMPONENT_COMPOUND_NAME, and
    DEMANGLE_COMPONENT_CHARACTER as new enum values.
    (demangle_component): Add struct s_character to union u.

libiberty/
2008-01-25  David Daney  <ddaney@avtrex.com>

    * cp-demangle.c (d_dump): Handle DEMANGLE_COMPONENT_JAVA_RESOURCE,
    DEMANGLE_COMPONENT_COMPOUND_NAME, and
    DEMANGLE_COMPONENT_CHARACTER cases.
    (d_make_comp): Handle DEMANGLE_COMPONENT_COMPOUND_NAME and
    DEMANGLE_COMPONENT_JAVA_RESOURCE cases.
    (d_make_character): New function.
    (d_java_resource): Same.
    (d_special_name): Handle "Gr" case.
    (d_print_comp): Handle DEMANGLE_COMPONENT_JAVA_RESOURCE,
    DEMANGLE_COMPONENT_COMPOUND_NAME, and
    DEMANGLE_COMPONENT_CHARACTER cases.
    * testsuite/demangle-expected: Add test for java resource name
    mangling.



[-- Attachment #2: demangle.patch --]
[-- Type: text/x-patch, Size: 6298 bytes --]

Index: include/demangle.h
===================================================================
RCS file: /cvs/src/src/include/demangle.h,v
retrieving revision 1.25
diff -u -p -r1.25 demangle.h
--- include/demangle.h	31 Aug 2007 20:20:44 -0000	1.25
+++ include/demangle.h	25 Jan 2008 21:51:32 -0000
@@ -362,7 +362,15 @@ enum demangle_component_type
      using 'n' instead of '-', we want a way to indicate a negative
      number which involves neither modifying the mangled string nor
      allocating a new copy of the literal in memory.  */
-  DEMANGLE_COMPONENT_LITERAL_NEG
+  DEMANGLE_COMPONENT_LITERAL_NEG,
+  /* A libgcj compiled resource.  The left subtree is the name of the
+     resource.  */
+  DEMANGLE_COMPONENT_JAVA_RESOURCE,
+  /* A name formed by the concatenation of two parts.  The left
+     subtree is the first part and the right subtree the second.  */
+  DEMANGLE_COMPONENT_COMPOUND_NAME,
+  /* A name formed by a single character.  */
+  DEMANGLE_COMPONENT_CHARACTER
 };
 
 /* Types which are only used internally.  */
@@ -448,6 +456,12 @@ struct demangle_component
       long number;
     } s_number;
 
+    /* For DEMANGLE_COMPONENT_CHARACTER.  */
+    struct
+    {
+      int character;
+    } s_character;
+
     /* For other types.  */
     struct
     {
Index: libiberty/cp-demangle.c
===================================================================
RCS file: /cvs/src/src/libiberty/cp-demangle.c,v
retrieving revision 1.69
diff -u -p -r1.69 cp-demangle.c
--- libiberty/cp-demangle.c	31 Aug 2007 20:20:49 -0000	1.69
+++ libiberty/cp-demangle.c	25 Jan 2008 21:51:35 -0000
@@ -650,6 +650,15 @@ d_dump (struct demangle_component *dc, i
     case DEMANGLE_COMPONENT_LITERAL_NEG:
       printf ("negative literal\n");
       break;
+    case DEMANGLE_COMPONENT_JAVA_RESOURCE:
+      printf ("java resource\n");
+      break;
+    case DEMANGLE_COMPONENT_COMPOUND_NAME:
+      printf ("compound name\n");
+      break;
+    case DEMANGLE_COMPONENT_CHARACTER:
+      printf ("character '%c'\n",  dc->u.s_character.character);
+      return;
     }
 
   d_dump (d_left (dc), indent + 2);
@@ -769,6 +778,7 @@ d_make_comp (struct d_info *di, enum dem
     case DEMANGLE_COMPONENT_TRINARY_ARG2:
     case DEMANGLE_COMPONENT_LITERAL:
     case DEMANGLE_COMPONENT_LITERAL_NEG:
+    case DEMANGLE_COMPONENT_COMPOUND_NAME:
       if (left == NULL || right == NULL)
 	return NULL;
       break;
@@ -795,6 +805,7 @@ d_make_comp (struct d_info *di, enum dem
     case DEMANGLE_COMPONENT_ARGLIST:
     case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
     case DEMANGLE_COMPONENT_CAST:
+    case DEMANGLE_COMPONENT_JAVA_RESOURCE:
       if (left == NULL)
 	return NULL;
       break;
@@ -1501,6 +1512,102 @@ d_operator_name (struct d_info *di)
     }
 }
 
+static struct demangle_component *
+d_make_character (struct d_info *di, int c)
+{
+  struct demangle_component *p;
+  p = d_make_empty (di);
+  if (p != NULL)
+    {
+      p->type = DEMANGLE_COMPONENT_CHARACTER;
+      p->u.s_character.character = c;
+    }
+  return p;
+}
+
+static struct demangle_component *
+d_java_resource (struct d_info *di)
+{
+  struct demangle_component *p = NULL;
+  struct demangle_component *next = NULL;
+  long len, i;
+  char c;
+  const char *str;
+
+  len = d_number (di);
+  if (len <= 1)
+    return NULL;
+
+  /* Eat the leading '_'.  */
+  if (d_next_char (di) != '_')
+    return NULL;
+  len--;
+
+  str = d_str (di);
+  i = 0;
+
+  while (len > 0)
+    {
+      c = str[i];
+      if (!c)
+	return NULL;
+
+      /* Each chunk is either a '$' escape...  */
+      if (c == '$')
+	{
+	  i++;
+	  switch (str[i++])
+	    {
+	    case 'S':
+	      c = '/';
+	      break;
+	    case '_':
+	      c = '.';
+	      break;
+	    case '$':
+	      c = '$';
+	      break;
+	    default:
+	      return NULL;
+	    }
+	  next = d_make_character (di, c);
+	  d_advance (di, i);
+	  str = d_str (di);
+	  len -= i;
+	  i = 0;
+	  if (next == NULL)
+	    return NULL;
+	}
+      /* ... or a sequence of characters.  */
+      else
+	{
+	  while (i < len && str[i] && str[i] != '$')
+	    i++;
+
+	  next = d_make_name (di, str, i);
+	  d_advance (di, i);
+	  str = d_str (di);
+	  len -= i;
+	  i = 0;
+	  if (next == NULL)
+	    return NULL;
+	}
+
+      if (p == NULL)
+	p = next;
+      else
+	{
+	  p = d_make_comp (di, DEMANGLE_COMPONENT_COMPOUND_NAME, p, next);
+	  if (p == NULL)
+	    return NULL;
+	}
+    }
+
+  p = d_make_comp (di, DEMANGLE_COMPONENT_JAVA_RESOURCE, p, NULL);
+
+  return p;
+}
+
 /* <special-name> ::= TV <type>
                   ::= TT <type>
                   ::= TI <type>
@@ -1514,6 +1621,7 @@ d_operator_name (struct d_info *di)
                   ::= TJ <type>
                   ::= GR <name>
 		  ::= GA <encoding>
+		  ::= Gr <resource name>
 */
 
 static struct demangle_component *
@@ -1605,6 +1713,9 @@ d_special_name (struct d_info *di)
 	  return d_make_comp (di, DEMANGLE_COMPONENT_HIDDEN_ALIAS,
 			      d_encoding (di, 0), NULL);
 
+	case 'r':
+	  return d_java_resource (di);
+
 	default:
 	  return NULL;
 	}
@@ -3552,6 +3663,20 @@ d_print_comp (struct d_print_info *dpi,
       }
       return;
 
+    case DEMANGLE_COMPONENT_JAVA_RESOURCE:
+      d_append_string (dpi, "java resource ");
+      d_print_comp (dpi, d_left (dc));
+      return;
+
+    case DEMANGLE_COMPONENT_COMPOUND_NAME:
+      d_print_comp (dpi, d_left (dc));
+      d_print_comp (dpi, d_right (dc));
+      return;
+
+    case DEMANGLE_COMPONENT_CHARACTER:
+      d_append_char (dpi, dc->u.s_character.character);
+      return;
+
     default:
       d_print_error (dpi);
       return;
Index: libiberty/testsuite/demangle-expected
===================================================================
RCS file: /cvs/src/src/libiberty/testsuite/demangle-expected,v
retrieving revision 1.37
diff -u -p -r1.37 demangle-expected
--- libiberty/testsuite/demangle-expected	6 May 2007 00:25:11 -0000	1.37
+++ libiberty/testsuite/demangle-expected	25 Jan 2008 21:51:38 -0000
@@ -3858,3 +3858,7 @@ foo()::var1
 --format=gnu-v3
 _ZZN7myspaceL3foo_1EvEN11localstruct1fEZNS_3fooEvE16otherlocalstruct
 myspace::foo()::localstruct::f(myspace::foo()::otherlocalstruct)
+# Java resource name
+--format=gnu-v3
+_ZGr32_java$Sutil$Siso4217$_properties
+java resource java/util/iso4217.properties

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Patch 1/2] Add demangling for java resource files to libiberty
  2008-01-25 22:10   ` David Daney
@ 2008-01-27  5:41     ` Ian Lance Taylor
  2008-01-27  6:29       ` David Daney
  0 siblings, 1 reply; 10+ messages in thread
From: Ian Lance Taylor @ 2008-01-27  5:41 UTC (permalink / raw)
  To: David Daney; +Cc: gcc-patches, binutils, Java Patch List

David Daney <ddaney@avtrex.com> writes:

> include/
> 2008-01-14  David Daney  <ddaney@avtrex.com>
> 
>     * demangle.h (demangle_component_type):  Add
>     DEMANGLE_COMPONENT_JAVA_RESOURCE,
>     DEMANGLE_COMPONENT_COMPOUND_NAME, and
>     DEMANGLE_COMPONENT_CHARACTER as new enum values.
>     (demangle_component): Add struct s_character to union u.
> 
> libiberty/
> 2008-01-25  David Daney  <ddaney@avtrex.com>
> 
>     * cp-demangle.c (d_dump): Handle DEMANGLE_COMPONENT_JAVA_RESOURCE,
>     DEMANGLE_COMPONENT_COMPOUND_NAME, and
>     DEMANGLE_COMPONENT_CHARACTER cases.
>     (d_make_comp): Handle DEMANGLE_COMPONENT_COMPOUND_NAME and
>     DEMANGLE_COMPONENT_JAVA_RESOURCE cases.
>     (d_make_character): New function.
>     (d_java_resource): Same.
>     (d_special_name): Handle "Gr" case.
>     (d_print_comp): Handle DEMANGLE_COMPONENT_JAVA_RESOURCE,
>     DEMANGLE_COMPONENT_COMPOUND_NAME, and
>     DEMANGLE_COMPONENT_CHARACTER cases.
>     * testsuite/demangle-expected: Add test for java resource name
>     mangling.

This is OK for 4.3 if 4.3 will include the java patches which can
generate these mangled names.

Thanks.

Ian

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Patch 1/2] Add demangling for java resource files to libiberty
  2008-01-27  5:41     ` Ian Lance Taylor
@ 2008-01-27  6:29       ` David Daney
  0 siblings, 0 replies; 10+ messages in thread
From: David Daney @ 2008-01-27  6:29 UTC (permalink / raw)
  To: gcc-patches, binutils; +Cc: Ian Lance Taylor, Java Patch List

Ian Lance Taylor wrote:
> David Daney <ddaney@avtrex.com> writes:
>
>   
>> include/
>> 2008-01-14  David Daney  <ddaney@avtrex.com>
>>
>>     * demangle.h (demangle_component_type):  Add
>>     DEMANGLE_COMPONENT_JAVA_RESOURCE,
>>     DEMANGLE_COMPONENT_COMPOUND_NAME, and
>>     DEMANGLE_COMPONENT_CHARACTER as new enum values.
>>     (demangle_component): Add struct s_character to union u.
>>
>> libiberty/
>> 2008-01-25  David Daney  <ddaney@avtrex.com>
>>
>>     * cp-demangle.c (d_dump): Handle DEMANGLE_COMPONENT_JAVA_RESOURCE,
>>     DEMANGLE_COMPONENT_COMPOUND_NAME, and
>>     DEMANGLE_COMPONENT_CHARACTER cases.
>>     (d_make_comp): Handle DEMANGLE_COMPONENT_COMPOUND_NAME and
>>     DEMANGLE_COMPONENT_JAVA_RESOURCE cases.
>>     (d_make_character): New function.
>>     (d_java_resource): Same.
>>     (d_special_name): Handle "Gr" case.
>>     (d_print_comp): Handle DEMANGLE_COMPONENT_JAVA_RESOURCE,
>>     DEMANGLE_COMPONENT_COMPOUND_NAME, and
>>     DEMANGLE_COMPONENT_CHARACTER cases.
>>     * testsuite/demangle-expected: Add test for java resource name
>>     mangling.
>>     
>
> This is OK for 4.3 if 4.3 will include the java patches which can
> generate these mangled names.
>   
The patch for the new mangling was committed a couple of days ago to GCC
4.3.

This patch now committed to GCC and binutils.

Thanks,
David Daney

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-01-27  6:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-15  1:02 [Patch 1/2] Add demangling for java resource files to libiberty David Daney
2008-01-15  1:23 ` [Patch 2/2] Make java compiled resources public David Daney
2008-01-19 18:41   ` Tom Tromey
2008-01-22 22:00     ` David Daney
2008-01-23 11:40       ` Andrew Haley
2008-01-23 23:05         ` David Daney
2008-01-18 19:46 ` [Patch 1/2] Add demangling for java resource files to libiberty Ian Lance Taylor
2008-01-25 22:10   ` David Daney
2008-01-27  5:41     ` Ian Lance Taylor
2008-01-27  6:29       ` David Daney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).