| 1 |
// Compiler implementation of the D programming language |
|---|
| 2 |
// Copyright (c) 1999-2006 by Digital Mars |
|---|
| 3 |
// All Rights Reserved |
|---|
| 4 |
// Initial header generation implementation by Dave Fladebo |
|---|
| 5 |
// http://www.digitalmars.com |
|---|
| 6 |
// License for redistribution is by either the Artistic License |
|---|
| 7 |
// in artistic.txt, or the GNU General Public License in gnu.txt. |
|---|
| 8 |
// See the included readme.txt for details. |
|---|
| 9 |
|
|---|
| 10 |
// Routines to emit header files |
|---|
| 11 |
|
|---|
| 12 |
#ifdef _DH |
|---|
| 13 |
|
|---|
| 14 |
#define PRETTY_PRINT |
|---|
| 15 |
#define TEST_EMIT_ALL 0 // For Testing |
|---|
| 16 |
|
|---|
| 17 |
#define LOG 0 |
|---|
| 18 |
|
|---|
| 19 |
#include <stdio.h> |
|---|
| 20 |
#include <stdlib.h> |
|---|
| 21 |
#include <assert.h> |
|---|
| 22 |
#if __DMC__ |
|---|
| 23 |
#include <complex.h> |
|---|
| 24 |
#endif |
|---|
| 25 |
|
|---|
| 26 |
#if IN_GCC || IN_DMDFE |
|---|
| 27 |
#include "mem.h" |
|---|
| 28 |
#else |
|---|
| 29 |
#if _WIN32 |
|---|
| 30 |
#include "..\root\mem.h" |
|---|
| 31 |
#elif linux |
|---|
| 32 |
#include "../root/mem.h" |
|---|
| 33 |
#else |
|---|
| 34 |
#error "fix this" |
|---|
| 35 |
#endif |
|---|
| 36 |
#endif |
|---|
| 37 |
|
|---|
| 38 |
#include "id.h" |
|---|
| 39 |
#include "init.h" |
|---|
| 40 |
|
|---|
| 41 |
#include "attrib.h" |
|---|
| 42 |
#include "cond.h" |
|---|
| 43 |
#include "enum.h" |
|---|
| 44 |
#include "import.h" |
|---|
| 45 |
#include "module.h" |
|---|
| 46 |
#include "mtype.h" |
|---|
| 47 |
#include "scope.h" |
|---|
| 48 |
#include "staticassert.h" |
|---|
| 49 |
#include "template.h" |
|---|
| 50 |
#include "utf.h" |
|---|
| 51 |
#include "version.h" |
|---|
| 52 |
|
|---|
| 53 |
#include "declaration.h" |
|---|
| 54 |
#include "aggregate.h" |
|---|
| 55 |
#include "expression.h" |
|---|
| 56 |
#include "statement.h" |
|---|
| 57 |
#include "mtype.h" |
|---|
| 58 |
#include "hdrgen.h" |
|---|
| 59 |
|
|---|
| 60 |
void argsToCBuffer(OutBuffer *buf, Array *arguments, HdrGenState *hgs); |
|---|
| 61 |
|
|---|
| 62 |
void Module::genhdrfile() |
|---|
| 63 |
{ |
|---|
| 64 |
OutBuffer hdrbufr; |
|---|
| 65 |
|
|---|
| 66 |
hdrbufr.printf("// D import file generated from '%s'", srcfile->toChars()); |
|---|
| 67 |
hdrbufr.writenl(); |
|---|
| 68 |
|
|---|
| 69 |
HdrGenState hgs; |
|---|
| 70 |
memset(&hgs, 0, sizeof(hgs)); |
|---|
| 71 |
hgs.hdrgen = 1; |
|---|
| 72 |
|
|---|
| 73 |
toCBuffer(&hdrbufr, &hgs); |
|---|
| 74 |
|
|---|
| 75 |
// Transfer image to file |
|---|
| 76 |
hdrfile->setbuffer(hdrbufr.data, hdrbufr.offset); |
|---|
| 77 |
hdrbufr.data = NULL; |
|---|
| 78 |
|
|---|
| 79 |
char *pt = FileName::path(hdrfile->toChars()); |
|---|
| 80 |
if (*pt) |
|---|
| 81 |
FileName::ensurePathExists(pt); |
|---|
| 82 |
mem.free(pt); |
|---|
| 83 |
hdrfile->writev(); |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
void Module::toCBuffer(OutBuffer *buf, HdrGenState *hgs) |
|---|
| 88 |
{ |
|---|
| 89 |
if (md) |
|---|
| 90 |
{ |
|---|
| 91 |
buf->writestring("module "); |
|---|
| 92 |
buf->writestring(md->toChars()); |
|---|
| 93 |
buf->writebyte(';'); |
|---|
| 94 |
buf->writenl(); |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
for (int i = 0; i < members->dim; i++) |
|---|
| 98 |
{ Dsymbol *s = (Dsymbol *)members->data[i]; |
|---|
| 99 |
|
|---|
| 100 |
s->toHBuffer(buf, hgs); |
|---|
| 101 |
} |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
void Dsymbol::toHBuffer(OutBuffer *buf, HdrGenState *hgs) |
|---|
| 106 |
{ |
|---|
| 107 |
toCBuffer(buf, hgs); |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
/*************************************/ |
|---|
| 112 |
|
|---|
| 113 |
#endif // #ifdef _DH |
|---|