Re: [PATCH 5/7] [D] libiberty: Fixes for demangling qualified symbol names

2017-05-01 Thread Iain Buclaw
On 15 April 2017 at 17:25, Iain Buclaw  wrote:
> This patch removes `dlang_parse_symbol', and replaces it with
> `dlang_parse_qualified' and `dlang_parse_mangle'.  All callers have
> been updated to reflect as to whether we expect either a `MangleName'
> or `QualifiedName' to be the next token we encounter, which matches
> many clarifications that have been made in the specification.
>
> This also removes the special case of matching `V' - or encoded
> extern(Pascal) functions - and instead uses a more generic approach in
> that if a `CallConvention' symbol was encountered whilst consuming
> `QualifiedName', it *must* be followed by another `QualifiedName',
> otherwise we've reached the end of the matched rule.  It still defeats
> the purpose of the aiming to having a context-free grammar, but at
> least it's a little less evil than before.
>
> ---

FYI, the following amendments were made to a commented grammar rule
---
 /* Qualified names are identifiers separated by their encoded length.
Nested functions also encode their argument types without specifying
what they return.

  QualifiedName:
  SymbolName
  SymbolName QualifiedName
  SymbolName TypeFunctionNoReturn QualifiedName
- SymbolName M TypeFunctionNoReturn QualifiedName
+ SymbolName M TypeModifiers TypeFunctionNoReturn QualifiedName
  ^
The start pointer should be at the above location.
  */
---
Along with relevant code adjustment in the patch.  I also discovered
that this also fixed a another problematic symbol, so added that to
the testsuite also.

Regards
Iain
---
libiberty/ChangeLog:

2017-05-01  Iain Buclaw  

	* d-demangle.c (dlang_parse_symbol): Remove function.
	(dlang_parse_qualified): New function.
	(dlang_parse_mangle): New function.
	(dlang_type): Update to call dlang_parse_qualified.
	(dlang_identifier): Update to call either dlang_parse_qualified or
	dlang_parse_mangle.
	(dlang_type_modifier_p): Remove function.
	(dlang_call_convention_p): Don't allow for type modifiers in mangle.
	(dlang_template_args): Update to call dlang_identifier.
	(dlang_demangle): Update to call dlang_parse_mangle.
	* testsuite/d-demangle-expected: Add tests.


diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
index b30641f0a6..8b0f628016 100644
--- a/libiberty/d-demangle.c
+++ b/libiberty/d-demangle.c
@@ -186,7 +186,10 @@ static const char *dlang_type (string *, const char *);
 
 static const char *dlang_value (string *, const char *, const char *, char);
 
-static const char *dlang_parse_symbol (string *, const char *,
+static const char *dlang_parse_qualified (string *, const char *,
+	  enum dlang_symbol_kinds);
+
+static const char *dlang_parse_mangle (string *, const char *,
    enum dlang_symbol_kinds);
 
 static const char *dlang_parse_tuple (string *, const char *);
@@ -561,7 +564,7 @@ dlang_type (string *decl, const char *mangled)
 case 'E': /* enum T */
 case 'T': /* typedef T */
   mangled++;
-  return dlang_parse_symbol (decl, mangled, dlang_type_name);
+  return dlang_parse_qualified (decl, mangled, dlang_type_name);
 case 'D': /* delegate T */
 {
   string mods;
@@ -743,12 +746,10 @@ dlang_identifier (string *decl, const char *mangled,
 	  /* Check whether template parameter is a function with a valid
 	 return type or an untyped identifier.  */
 	  if (ISDIGIT (*mangled))
-	mangled = dlang_parse_symbol (decl, mangled, dlang_template_ident);
+	mangled = dlang_parse_qualified (decl, mangled,
+	 dlang_template_ident);
 	  else if (strncmp (mangled, "_D", 2) == 0)
-	{
-	  mangled += 2;
-	  mangled = dlang_parse_symbol (decl, mangled, dlang_function);
-	}
+	mangled = dlang_parse_mangle (decl, mangled, dlang_function);
 
 	  /* Check for name length mismatch.  */
 	  if (mangled && (mangled - pend) == psize)
@@ -1298,49 +1299,11 @@ dlang_value (string *decl, const char *mangled, const char *name, char type)
   return mangled;
 }
 
-/* Extract the type modifiers from MANGLED and return the string
-   length that it consumes in MANGLED on success or 0 on failure.  */
-static int
-dlang_type_modifier_p (const char *mangled)
-{
-  int i;
-
-  switch (*mangled)
-{
-case 'x': case 'y':
-  return 1;
-
-case 'O':
-  mangled++;
-  i = dlang_type_modifier_p (mangled);
-  return i + 1;
-
-case 'N':
-  mangled++;
-  if (*mangled == 'g')
-	{
-	  mangled++;
-	  i = dlang_type_modifier_p (mangled);
-	  return i + 2;
-	}
-}
-
-  return 0;
-}
-
 /* Extract the function calling convention from MANGLED and
return 1 on success or 0 on failure.  */
 static int
 dlang_call_convention_p (const char *mangled)
 {
-  /* Prefix for functions needing 'this' */
-  if (*mangled == 'M')
-{
-  mangled++;
-  /* Also skip over any type modifiers.  */
-  

Re: [PATCH 5/7] [D] libiberty: Fixes for demangling qualified symbol names

2017-04-25 Thread Iain Buclaw
On 25 April 2017 at 17:35, Jeff Law  wrote:
> On 04/15/2017 09:25 AM, Iain Buclaw wrote:
>>
>> This patch removes `dlang_parse_symbol', and replaces it with
>> `dlang_parse_qualified' and `dlang_parse_mangle'.  All callers have
>> been updated to reflect as to whether we expect either a `MangleName'
>> or `QualifiedName' to be the next token we encounter, which matches
>> many clarifications that have been made in the specification.
>>
>> This also removes the special case of matching `V' - or encoded
>> extern(Pascal) functions - and instead uses a more generic approach in
>> that if a `CallConvention' symbol was encountered whilst consuming
>> `QualifiedName', it*must*  be followed by another `QualifiedName',
>> otherwise we've reached the end of the matched rule.  It still defeats
>> the purpose of the aiming to having a context-free grammar, but at
>> least it's a little less evil than before.
>>
>> ---
>>
>>
>> 05-d-demangle-qualified-name.patch
>>
>>
>> commit 8701a7e99b9146719881adcf019ecbebe836b755
>> Author: Iain Buclaw
>> Date:   Sat Apr 15 11:54:27 2017 +0200
>>
>>  libiberty/ChangeLog:
>>   2017-04-15  Iain Buclaw
>> * d-demangle.c (dlang_parse_symbol): Remove function.
>> (dlang_parse_qualified): New function.
>> (dlang_parse_mangle): New function.
>> (dlang_type): Update to call dlang_parse_qualified.
>> (dlang_identifier): Update to call either dlang_parse_qualified or
>> dlang_parse_mangle.
>> (dlang_type_modifier_p): Remove function.
>> (dlang_call_convention_p): Don't allow for type modifiers in
>> mangle.
>> (dlang_template_args): Update to call dlang_identifier.
>> (dlang_demangle): Update to call dlang_parse_mangle.
>> * testsuite/d-demangle-expected: Add tests.
>
> OK for the trunk.
>
> What's the state of patch 4/7?  I got the distinct impression you wanted to
> update & repost that patch.
> Jeff

Thanks, yes, apologies.  I got rather side-tracked, I'll submit it now.

--
Iain


Re: [PATCH 5/7] [D] libiberty: Fixes for demangling qualified symbol names

2017-04-25 Thread Jeff Law

On 04/15/2017 09:25 AM, Iain Buclaw wrote:

This patch removes `dlang_parse_symbol', and replaces it with
`dlang_parse_qualified' and `dlang_parse_mangle'.  All callers have
been updated to reflect as to whether we expect either a `MangleName'
or `QualifiedName' to be the next token we encounter, which matches
many clarifications that have been made in the specification.

This also removes the special case of matching `V' - or encoded
extern(Pascal) functions - and instead uses a more generic approach in
that if a `CallConvention' symbol was encountered whilst consuming
`QualifiedName', it*must*  be followed by another `QualifiedName',
otherwise we've reached the end of the matched rule.  It still defeats
the purpose of the aiming to having a context-free grammar, but at
least it's a little less evil than before.

---


05-d-demangle-qualified-name.patch


commit 8701a7e99b9146719881adcf019ecbebe836b755
Author: Iain Buclaw
Date:   Sat Apr 15 11:54:27 2017 +0200

 libiberty/ChangeLog:
 
 2017-04-15  Iain Buclaw
 
 	* d-demangle.c (dlang_parse_symbol): Remove function.

(dlang_parse_qualified): New function.
(dlang_parse_mangle): New function.
(dlang_type): Update to call dlang_parse_qualified.
(dlang_identifier): Update to call either dlang_parse_qualified or
dlang_parse_mangle.
(dlang_type_modifier_p): Remove function.
(dlang_call_convention_p): Don't allow for type modifiers in mangle.
(dlang_template_args): Update to call dlang_identifier.
(dlang_demangle): Update to call dlang_parse_mangle.
* testsuite/d-demangle-expected: Add tests.

OK for the trunk.

What's the state of patch 4/7?  I got the distinct impression you wanted 
to update & repost that patch.

Jeff