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