Skip to content

Commit

Permalink
Move Module::toCBuffer and genhdrfile into free functions
Browse files Browse the repository at this point in the history
  • Loading branch information
yebblies committed Feb 20, 2014
1 parent 544577d commit 7fbd48d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
25 changes: 13 additions & 12 deletions src/hdrgen.c
Expand Up @@ -53,43 +53,44 @@ void linkageToBuffer(OutBuffer *buf, LINK linkage);
void functionToBufferFull(TypeFunction *tf, OutBuffer *buf, Identifier *ident, HdrGenState* hgs, TypeFunction *attrs, TemplateDeclaration *td);
void toBufferShort(Type *t, OutBuffer *buf, HdrGenState *hgs);
void expToCBuffer(OutBuffer *buf, HdrGenState *hgs, Expression *e, PREC pr);
void toCBuffer(Module *m, OutBuffer *buf, HdrGenState *hgs);

void Module::genhdrfile()
void genhdrfile(Module *m)
{
OutBuffer hdrbufr;
hdrbufr.doindent = 1;

hdrbufr.printf("// D import file generated from '%s'", srcfile->toChars());
hdrbufr.printf("// D import file generated from '%s'", m->srcfile->toChars());
hdrbufr.writenl();

HdrGenState hgs;
memset(&hgs, 0, sizeof(hgs));
hgs.hdrgen = 1;

toCBuffer(&hdrbufr, &hgs);
toCBuffer(m, &hdrbufr, &hgs);

// Transfer image to file
hdrfile->setbuffer(hdrbufr.data, hdrbufr.offset);
m->hdrfile->setbuffer(hdrbufr.data, hdrbufr.offset);
hdrbufr.data = NULL;

ensurePathToNameExists(Loc(), hdrfile->toChars());
writeFile(loc, hdrfile);
ensurePathToNameExists(Loc(), m->hdrfile->toChars());
writeFile(m->loc, m->hdrfile);
}


void Module::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
void toCBuffer(Module *m, OutBuffer *buf, HdrGenState *hgs)
{
if (md)
if (m->md)
{
buf->writestring("module ");
buf->writestring(md->toChars());
buf->writestring(m->md->toChars());
buf->writeByte(';');
buf->writenl();
}

for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (*members)[i];

for (size_t i = 0; i < m->members->dim; i++)
{
Dsymbol *s = (*m->members)[i];
s->toCBuffer(buf, hgs);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/hdrgen.h
Expand Up @@ -10,6 +10,8 @@

#include <string.h> // memset()

void genhdrfile(Module *m);

struct HdrGenState
{
int hdrgen; // 1 if generating header file
Expand Down
3 changes: 2 additions & 1 deletion src/mars.c
Expand Up @@ -35,6 +35,7 @@
#include "lib.h"
#include "json.h"
#include "declaration.h"
#include "hdrgen.h"

int response_expand(size_t *pargc, const char ***pargv);
void browse(const char *url);
Expand Down Expand Up @@ -1507,7 +1508,7 @@ Language changes listed by -transition=id:\n\
Module *m = modules[i];
if (global.params.verbose)
fprintf(global.stdmsg, "import %s\n", m->toChars());
m->genhdrfile();
genhdrfile(m);
}
}
if (global.errors)
Expand Down
2 changes: 0 additions & 2 deletions src/module.h
Expand Up @@ -116,7 +116,6 @@ class Module : public Package

static Module *load(Loc loc, Identifiers *packages, Identifier *ident);

void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
const char *kind();
File *setOutfile(const char *name, const char *dir, const char *arg, const char *ext);
void setDocfile();
Expand All @@ -126,7 +125,6 @@ class Module : public Package
void semantic(); // semantic analysis
void semantic2(); // pass 2 semantic analysis
void semantic3(); // pass 3 semantic analysis
void genhdrfile(); // generate D import file
void genobjfile(int multiobj);
void gensymfile();
void gendocfile();
Expand Down

0 comments on commit 7fbd48d

Please sign in to comment.