[Issue 2484] Templated classes have no moduleinfo

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Apr 24 08:24:36 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=2484


nfxjfg at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #8 from nfxjfg at gmail.com 2010-04-24 08:24:31 PDT ---
Here's a partial patch against dmd 1.057:

diff --git a/dsymbol.c b/dsymbol.c
index 7614e13..5fca88e 100644
--- a/dsymbol.c
+++ b/dsymbol.c
@@ -715,6 +715,20 @@ ScopeDsymbol::ScopeDsymbol(Identifier *id)
     prots = NULL;
 }

+void ScopeDsymbol::addLocalClass(ClassDeclarations * aclasses) {
+    //????????????????????????
+    if (!members)
+        return;
+
+    //printf("members->dim = %d\n", members->dim);
+    for (int i = 0; i < members->dim; i++)
+    {   Dsymbol *member = (Dsymbol *)members->data[i];
+
+        //printf("\tmember '%s'\n", member->toChars());
+        member->addLocalClass(aclasses);
+    }
+}
+
 Dsymbol *ScopeDsymbol::syntaxCopy(Dsymbol *s)
 {
     //printf("ScopeDsymbol::syntaxCopy('%s')\n", toChars());
diff --git a/dsymbol.h b/dsymbol.h
index e566515..49f8750 100644
--- a/dsymbol.h
+++ b/dsymbol.h
@@ -270,6 +270,8 @@ struct ScopeDsymbol : Dsymbol
     static Dsymbol *getNth(Array *members, size_t nth, size_t *pn = NULL);

     ScopeDsymbol *isScopeDsymbol() { return this; }
+
+    void addLocalClass(ClassDeclarations *);
 };

 // With statement scope
diff --git a/template.h b/template.h
index 90b5161..ecbd04e 100644
--- a/template.h
+++ b/template.h
@@ -87,6 +87,9 @@ struct TemplateDeclaration : ScopeDsymbol
     int isOverloadable();

     void makeParamNamesVisibleInConstraint(Scope *paramscope);
+
+    // don't add uninstantiated template classes
+    void addLocalClass(ClassDeclarations *) {}
 };

 struct TemplateParameter
diff --git a/toobj.c b/toobj.c
index e2d2403..1431e0e 100644
--- a/toobj.c
+++ b/toobj.c
@@ -92,13 +92,7 @@ void Module::genmoduleinfo()

     ClassDeclarations aclasses;

-    //printf("members->dim = %d\n", members->dim);
-    for (int i = 0; i < members->dim; i++)
-    {  Dsymbol *member = (Dsymbol *)members->data[i];
-
-       //printf("\tmember '%s'\n", member->toChars());
-       member->addLocalClass(&aclasses);
-    }
+    addLocalClass(&aclasses);

     // importedModules[]
     int aimports_dim = aimports.dim;


Here's a test case:

import tango.io.Stdout;

class This {}

struct X {
    class Foo {
    }
}

class C(T) { }

void main() {
    class Goo { } //not detected
    auto z = new Goo();
    C!(int) x = new C!(int);
    ClassInfo cobj = Object.classinfo;
    foreach (ModuleInfo m; ModuleInfo) {
        foreach (ClassInfo ci; m.localClasses) {
            if (ci is This.classinfo) {
                foreach (c; m.localClasses)
                    Stdout.formatln("{}", c.name);
        }
    }
}

It prints:
d.This
d.X.Foo
d.C!(int).C

As can be seen, class Goo is still missing. It seems the patch doesn't search
through functions. Maybe there are other cases where it still fails.

-- 
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