char *cpp_mangle(Dsymbol *s) { /* * <mangled-name> ::= _Z <encoding> * <encoding> ::= <function name> <bare-function-type> * ::= <data name> * ::= <special-name> */ CppMangleState cms; memset(&cms, 0, sizeof(cms)); cms.components.setDim(0); OutBuffer buf; #if MACHOBJ buf.writestring("__Z"); #else buf.writestring("_Z"); #endif cpp_mangle_name(&buf, &cms, s); FuncDeclaration *fd = s->isFuncDeclaration(); if (fd) { // add <bare-function-type> TypeFunction *tf = (TypeFunction *)fd->type; assert(tf->ty == Tfunction); Parameter::argsCppMangle(&buf, &cms, tf->parameters, tf->varargs); } buf.writeByte(0); return (char *)buf.extractData(); }
void TypeClass::toCppMangle(OutBuffer *buf, CppMangleState *cms) { if (!cms->substitute(buf, this)) { buf->writeByte('P'); if (!cms->substitute(buf, sym)) cpp_mangle_name(buf, cms, sym); } }
void visit(TypeClass *t) { if (substitute(t)) return; buf.writeByte('P'); if (!substitute(t->sym)) { cpp_mangle_name(t->sym); store(t->sym); } store(t); }
void TypeEnum::toCppMangle(OutBuffer *buf, CppMangleState *cms) { if (!cms->substitute(buf, this)) { if (isConst()) buf->writeByte('K'); if (!cms->substitute(buf, sym)) cpp_mangle_name(buf, cms, sym); if (isConst()) cms->store(this); } }
void visit(TypeEnum *t) { if (substitute(t)) return; if (t->isConst()) buf.writeByte('K'); if (!substitute(t->sym)) { cpp_mangle_name(t->sym); store(t->sym); } if (t->isConst()) store(t); }
void visit(TypeClass *t) { if (substitute(t)) return; if (t->isImmutable() || t->isShared()) { visit((Type *)t); } buf.writeByte('P'); if (t->isConst()) buf.writeByte('K'); if (!substitute(t->sym)) { cpp_mangle_name(t->sym); store(t->sym); } if (t->isConst()) store(NULL); store(t); }
void source_name(Dsymbol *s) { char *name = s->ident->toChars(); TemplateInstance *ti = s->isTemplateInstance(); if (ti) { if (!substitute(ti->tempdecl)) { store(ti->tempdecl); name = ti->name->toChars(); buf.printf("%d%s", strlen(name), name); } buf.writeByte('I'); bool is_var_arg = false; for (size_t i = 0; i < ti->tiargs->dim; i++) { RootObject *o = (RootObject *)(*ti->tiargs)[i]; TemplateParameter *tp = NULL; TemplateValueParameter *tv = NULL; TemplateTupleParameter *tt = NULL; if (!is_var_arg) { TemplateDeclaration *td = ti->tempdecl->isTemplateDeclaration(); tp = (*td->parameters)[i]; tv = tp->isTemplateValueParameter(); tt = tp->isTemplateTupleParameter(); } /* * <template-arg> ::= <type> # type or template * ::= <expr-primary> # simple expressions */ if (tt) { buf.writeByte('I'); is_var_arg = true; tp = NULL; } if (tv) { // <expr-primary> ::= L <type> <value number> E # integer literal if (tv->valType->isintegral()) { Expression* e = isExpression(o); assert(e); buf.writeByte('L'); tv->valType->accept(this); if (tv->valType->isunsigned()) { buf.printf("%llu", e->toUInteger()); } else { dinteger_t val = e->toInteger(); if (val < 0) { val = -val; buf.writeByte('n'); } buf.printf("%lld", val); } buf.writeByte('E'); } else { s->error("ICE: C++ %s template value parameter is not supported", tv->valType->toChars()); assert(0); } } else if (!tp || tp->isTemplateTypeParameter()) { Type *t = isType(o); assert(t); t->accept(this); } else if (tp->isTemplateAliasParameter()) { Dsymbol* d = isDsymbol(o); Expression* e = isExpression(o); if (!d && !e) { s->error("ICE: %s is unsupported parameter for C++ template: (%s)", o->toChars()); assert(0); } if (d && d->isFuncDeclaration()) { bool is_nested = d->toParent() && !d->toParent()->isModule() && ((TypeFunction *)d->isFuncDeclaration()->type)->linkage == LINKcpp; if (is_nested) buf.writeByte('X'); buf.writeByte('L'); mangle_function(d->isFuncDeclaration()); buf.writeByte('E'); if (is_nested) buf.writeByte('E'); } else if (e && e->op == TOKvar && ((VarExp*)e)->var->isVarDeclaration()) { VarDeclaration *vd = ((VarExp*)e)->var->isVarDeclaration(); buf.writeByte('L'); mangle_variable(vd, true); buf.writeByte('E'); } else if (d && d->isTemplateDeclaration() && d->isTemplateDeclaration()->onemember) { if (!substitute(d)) { cpp_mangle_name(d); store(d); } } else { s->error("ICE: %s is unsupported parameter for C++ template", o->toChars()); assert(0); } } else { s->error("ICE: C++ templates support only integral value , type parameters, alias templates and alias function parameters"); assert(0); } } if (is_var_arg) { buf.writeByte('E'); } buf.writeByte('E'); return; } else { buf.printf("%d%s", strlen(name), name); } }
void TypeEnum::toCppMangle(OutBuffer *buf, CppMangleState *cms) { if (!cms->substitute(buf, sym)) cpp_mangle_name(buf, cms, sym); }