[Issue 3043] New: Template symbol arg cannot be demangled

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jun 1 03:48:14 PDT 2009


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 at digitalmars.com
        ReportedBy: rsinfu at 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: -------


More information about the Digitalmars-d-bugs mailing list