Example #1
0
    void visit(Declaration *d)
    {
        //printf("Declaration::mangle(this = %p, '%s', parent = '%s', linkage = %d)\n",
        //        d, d->toChars(), d->parent ? d->parent->toChars() : "null", d->linkage);
        if (!d->parent || d->parent->isModule() || d->linkage == LINKcpp) // if at global scope
        {
            switch (d->linkage)
            {
                case LINKd:
                    break;

                case LINKc:
                case LINKwindows:
                case LINKpascal:
                    result = d->ident->toChars();
                    break;

                case LINKcpp:
                    result = toCppMangle(d);
                    break;

                case LINKdefault:
                    d->error("forward declaration");
                    result = d->ident->toChars();
                    break;

                default:
                    fprintf(stderr, "'%s', linkage = %d\n", d->toChars(), d->linkage);
                    assert(0);
            }
        }

        if (!result)
        {
            OutBuffer buf;
            buf.writestring("_D");
            mangleDecl(&buf, d);
            result = buf.extractString();
        }

    #ifdef DEBUG
        assert(result);
        size_t len = strlen(result);
        assert(len > 0);
        for (size_t i = 0; i < len; i++)
        {
            assert(result[i] == '_' ||
                   result[i] == '@' ||
                   result[i] == '?' ||
                   result[i] == '$' ||
                   isalnum(result[i]) || result[i] & 0x80);
        }
    #endif
    }
Example #2
0
    void visit(Declaration *d)
    {
        //printf("Declaration::mangle(this = %p, '%s', parent = '%s', linkage = %d)\n",
        //        d, d->toChars(), d->parent ? d->parent->toChars() : "null", d->linkage);
        if (!d->parent || d->parent->isModule() || d->linkage == LINKcpp) // if at global scope
        {
            switch (d->linkage)
            {
                case LINKd:
                    break;

                case LINKc:
                case LINKwindows:
                case LINKpascal:
                    buf->writestring(d->ident->toChars());
                    return;

                case LINKcpp:
                    buf->writestring(toCppMangle(d));
                    return;

                case LINKdefault:
                    d->error("forward declaration");
                    buf->writestring(d->ident->toChars());
                    return;

                default:
                    fprintf(stderr, "'%s', linkage = %d\n", d->toChars(), d->linkage);
                    assert(0);
                    return;
            }
        }

        buf->writestring("_D");
        mangleDecl(d);

    #ifdef DEBUG
        assert(buf->data);
        size_t len = buf->offset;
        assert(len > 0);
        for (size_t i = 0; i < len; i++)
        {
            assert(buf->data[i] == '_' ||
                   buf->data[i] == '@' ||
                   buf->data[i] == '?' ||
                   buf->data[i] == '$' ||
                   isalnum(buf->data[i]) || buf->data[i] & 0x80);
        }
    #endif
    }