Skip to content

Commit

Permalink
Merge pull request #3238 from yebblies/typetocbuffer
Browse files Browse the repository at this point in the history
[DMDD] [refactor] Move Type::toCBuffer into a visitor class
  • Loading branch information
AndrejMitrovic committed Feb 11, 2014
2 parents 718a982 + cfbad72 commit 7b26cfe
Show file tree
Hide file tree
Showing 7 changed files with 416 additions and 504 deletions.
6 changes: 4 additions & 2 deletions src/doc.c
Expand Up @@ -37,6 +37,8 @@
#include "mtype.h"
#include "utf.h"

void functionToBufferFull(TypeFunction *tf, OutBuffer *buf, Identifier *ident, HdrGenState* hgs, TypeFunction *attrs, TemplateDeclaration *td);

struct Escape
{
const char *strings[256];
Expand Down Expand Up @@ -899,7 +901,7 @@ void prefix(OutBuffer *buf, Dsymbol *s)
else if (d->isAbstract())
buf->writestring("abstract ");

if (!d->isFuncDeclaration()) // toCBufferWithAttributes handles this
if (!d->isFuncDeclaration()) // functionToBufferFull handles this
{
if (d->isConst())
buf->writestring("const ");
Expand Down Expand Up @@ -928,7 +930,7 @@ void declarationToDocBuffer(Declaration *decl, OutBuffer *buf, TemplateDeclarati
if (origType->ty == Tfunction)
{
TypeFunction *attrType = (TypeFunction*)(decl->ident == Id::ctor ? origType : decl->type);
((TypeFunction*)origType)->toCBufferWithAttributes(buf, decl->ident, &hgs, attrType, td);
functionToBufferFull(((TypeFunction*)origType), buf, decl->ident, &hgs, attrType, td);
}
else
origType->toCBuffer(buf, decl->ident, &hgs);
Expand Down
8 changes: 4 additions & 4 deletions src/expression.c
Expand Up @@ -41,8 +41,9 @@
bool isArrayOpValid(Expression *e);
Expression *createTypeInfoArray(Scope *sc, Expression *args[], size_t dim);
Expression *expandVar(int result, VarDeclaration *v);
void functionToCBuffer2(TypeFunction *t, OutBuffer *buf, HdrGenState *hgs, int mod, const char *kind);
void functionToBufferWithIdent(TypeFunction *t, OutBuffer *buf, const char *ident);
TypeTuple *toArgTypes(Type *t);
void toBufferShort(Type *t, OutBuffer *buf, HdrGenState *hgs);

#define LOGSEMANTIC 0

Expand Down Expand Up @@ -1877,7 +1878,7 @@ void argExpTypesToCBuffer(OutBuffer *buf, Expressions *arguments, HdrGenState *h
if (i)
buf->writestring(", ");
argbuf.reset();
e->type->toCBuffer2(&argbuf, hgs, 0);
toBufferShort(e->type, &argbuf, hgs);
buf->write(&argbuf);
}
}
Expand Down Expand Up @@ -13910,9 +13911,8 @@ Expression *PrettyFuncInitExp::resolveLoc(Loc loc, Scope *sc)
if (fd)
{
const char *funcStr = fd->Dsymbol::toPrettyChars();
HdrGenState hgs;
OutBuffer buf;
functionToCBuffer2((TypeFunction *)fd->type, &buf, &hgs, 0, funcStr);
functionToBufferWithIdent((TypeFunction *)fd->type, &buf, funcStr);
s = buf.extractString();
}
else
Expand Down
8 changes: 4 additions & 4 deletions src/func.c
Expand Up @@ -28,8 +28,9 @@
#include "parse.h"
#include "rmem.h"

void functionToCBuffer2(TypeFunction *t, OutBuffer *buf, HdrGenState *hgs, int mod, const char *kind);
void functionToBufferWithIdent(TypeFunction *t, OutBuffer *buf, const char *ident);
void genCmain(Scope *sc);
void toBufferShort(Type *t, OutBuffer *buf, HdrGenState *hgs);

/********************************* FuncDeclaration ****************************/

Expand Down Expand Up @@ -3035,8 +3036,7 @@ const char *FuncDeclaration::toPrettyChars()
const char *FuncDeclaration::toFullSignature()
{
OutBuffer buf;
HdrGenState hgs;
functionToCBuffer2((TypeFunction *)type, &buf, &hgs, 0, toChars());
functionToBufferWithIdent((TypeFunction *)type, &buf, toChars());
return buf.extractString();
}

Expand Down Expand Up @@ -3953,7 +3953,7 @@ void FuncLiteralDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
TypeFunction *tf = (TypeFunction *)type;
// Don't print tf->mod, tf->trust, and tf->linkage
if (!inferRetType && tf->next)
tf->next->toCBuffer2(buf, hgs, 0);
toBufferShort(tf->next, buf, hgs);
Parameter::argsToCBuffer(buf, hgs, tf->parameters, tf->varargs);

CompoundStatement *cs = fbody->isCompoundStatement();
Expand Down

0 comments on commit 7b26cfe

Please sign in to comment.