www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3043] New: Template symbol arg cannot be demangled

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3043

           Summary: Template symbol arg cannot be demangled
           Product: D
           Version: 2.030
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: patch, spec
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: rsinfu gmail.com


Created an attachment (id=388)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=388)
Patch (DMD 2.030)

=== Problem ===

Under the current spec, a template symbol argument is mangled to an LName:
--------------------
TemplateArg:
    T Type          // type argument
    V Type Value    // value argument
    S LName         // symbol argument

LName:
    Number Name
--------------------
This rule is troublesome for demangling. When Name is a QualifiedName (e.g.
template symbol), which starts with a Number, then there will be contiguous
Numbers in a mangled argument: "S Number Number Name Number Name ...". A
demangler will not be able to demangle such input correctly.

For example, this code
--------------------
module test;
struct Temp(alias a) {}
template sym() {}
pragma(msg, Temp!(sym).mangleof);
--------------------
prints "4test20__T4TempS94test3symZ4Temp". Here sym is mangled to
"S94test3sym"; the Number is "9" and the Name is "4test3sym". But a demangler
will recognize the Number and the Name as "94" and "test3sym", respectively.


=== Proposal ===

A template symbol argument may be
 (a) template declaration, template instance, template mixin,
     package, module,
 (b) variable or function.
(a) is mangled to a QualifiedName and (b) is mangled to a MangledName. These
two groups should be treated differently.

My proposal is this:
--------------------
TemplateArg:
    S TemplateSymbolArg

TemplateSymbolArg:
    QualifiedName   // (a) qualified name
    M LName         // (b) mangled var/func name (_D, _Z, etc.)
--------------------
This grammar does not generate contiguous Numbers. The prefix "M" is necessary
to avoid a same-mangled-name collision between QualifiedName and LName.

The attached patch modifies DMD 2.030 so that template symbol argument is
mangled with this rule.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 01 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3043


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au





I don't think problems can ever happen. I solved this ages ago in my
compile-time demangler. The demangler knows the length of the string,
("S94test3sym") so it can tell that "94" is impossible as the length;
therefore, it must be "9".

I think this bug is probably invalid.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 16 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3043


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX



22:57:21 PST ---
http://www.dsource.org/projects/dmd/changeset/745

Fixing this would break binary compatibility and all the existing demanglers.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 09 2010