Skip to content

Commit

Permalink
Merge pull request #3121 from ibuclaw/subsitute
Browse files Browse the repository at this point in the history
Fix CppMangleVisitor::substitute and Remove CppMangleVisitor::exist
  • Loading branch information
dnadlinger committed Jan 20, 2014
2 parents 2401bf3 + beac974 commit af6a1b7
Showing 1 changed file with 67 additions and 95 deletions.
162 changes: 67 additions & 95 deletions src/cppmangle.c
Expand Up @@ -74,19 +74,6 @@ class CppMangleVisitor : public Visitor
return 1;
}
}
components.push(p);
return 0;
}

int exist(RootObject *p)
{
for (size_t i = 0; i < components.dim; i++)
{
if (p == components[i])
{
return 1;
}
}
return 0;
}

Expand All @@ -103,15 +90,13 @@ class CppMangleVisitor : public Visitor

void prefix_name(Dsymbol *s)
{
if (!substitute(s))
{
Dsymbol *p = s->toParent();
if (p && !p->isModule())
{
prefix_name(p);
}
source_name(s);
}
if (substitute(s))
return;
Dsymbol *p = s->toParent();
if (p && !p->isModule())
prefix_name(p);
source_name(s);
store(s);
}

public:
Expand Down Expand Up @@ -165,10 +150,11 @@ class CppMangleVisitor : public Visitor
* C++ analog.
* u <source-name>
*/
if (!substitute(t))
{ assert(t->deco);
buf.printf("u%d%s", strlen(t->deco), t->deco);
}
if (substitute(t))
return;
assert(t->deco);
buf.printf("u%d%s", strlen(t->deco), t->deco);
store(t);
}

void visit(TypeBasic *t)
Expand Down Expand Up @@ -232,6 +218,7 @@ class CppMangleVisitor : public Visitor
{
if (substitute(t))
return;
store(t);
}

if (t->isConst())
Expand All @@ -246,20 +233,20 @@ class CppMangleVisitor : public Visitor

void visit(TypeVector *t)
{
if (!substitute(t))
{
buf.writestring("U8__vector");
t->basetype->accept(this);
}
if (substitute(t))
return;
buf.writestring("U8__vector");
t->basetype->accept(this);
store(t);
}

void visit(TypeSArray *t)
{
if (!substitute(t))
{
buf.printf("A%llu_", t->dim ? t->dim->toInteger() : 0);
t->next->accept(this);
}
if (substitute(t))
return;
buf.printf("A%llu_", t->dim ? t->dim->toInteger() : 0);
t->next->accept(this);
store(t);
}

void visit(TypeDArray *t)
Expand All @@ -274,26 +261,20 @@ class CppMangleVisitor : public Visitor

void visit(TypePointer *t)
{
if (!exist(t))
{
buf.writeByte('P');
t->next->accept(this);
store(t);
}
else
substitute(t);
if (substitute(t))
return;
buf.writeByte('P');
t->next->accept(this);
store(t);
}

void visit(TypeReference *t)
{
if (!exist(t))
{
buf.writeByte('R');
t->next->accept(this);
store(t);
}
else
substitute(t);
if (substitute(t))
return;
buf.writeByte('R');
t->next->accept(this);
store(t);
}

void visit(TypeFunction *t)
Expand All @@ -320,18 +301,15 @@ class CppMangleVisitor : public Visitor
TypeFunctions for non-static member functions, and non-static
member functions of different classes.
*/
if (!exist(t))
{
buf.writeByte('F');
if (t->linkage == LINKc)
buf.writeByte('Y');
t->next->accept(this);
argsCppMangle(t->parameters, t->varargs);
buf.writeByte('E');
store(t);
}
else
substitute(t);
if (substitute(t))
return;
buf.writeByte('F');
if (t->linkage == LINKc)
buf.writeByte('Y');
t->next->accept(this);
argsCppMangle(t->parameters, t->varargs);
buf.writeByte('E');
store(t);
}

void visit(TypeDelegate *t)
Expand All @@ -341,36 +319,32 @@ class CppMangleVisitor : public Visitor

void visit(TypeStruct *t)
{
if (!exist(t))
if (substitute(t))
return;
if (t->isConst())
buf.writeByte('K');
if (!substitute(t->sym))
{
if (t->isConst())
buf.writeByte('K');

if (!substitute(t->sym))
cpp_mangle_name(t->sym);

if (t->isConst())
store(t);
cpp_mangle_name(t->sym);
store(t->sym);
}
else
substitute(t);
if (t->isConst())
store(t);
}

void visit(TypeEnum *t)
{
if (!exist(t))
if (substitute(t))
return;
if (t->isConst())
buf.writeByte('K');
if (!substitute(t->sym))
{
if (t->isConst())
buf.writeByte('K');

if (!substitute(t->sym))
cpp_mangle_name(t->sym);

if (t->isConst())
store(t);
cpp_mangle_name(t->sym);
store(t->sym);
}
else
substitute(t);
if (t->isConst())
store(t);
}

void visit(TypeTypedef *t)
Expand All @@ -380,17 +354,15 @@ class CppMangleVisitor : public Visitor

void visit(TypeClass *t)
{
if (!exist(t))
if (substitute(t))
return;
buf.writeByte('P');
if (!substitute(t->sym))
{
buf.writeByte('P');

if (!substitute(t->sym))
cpp_mangle_name(t->sym);

store(t);
cpp_mangle_name(t->sym);
store(t->sym);
}
else
substitute(t);
store(t);
}

struct ArgsCppMangleCtx
Expand Down

0 comments on commit af6a1b7

Please sign in to comment.