| 1 |
// Compiler implementation of the D programming language |
|---|
| 2 |
// Copyright (c) 1999-2008 by Digital Mars |
|---|
| 3 |
// All Rights Reserved |
|---|
| 4 |
// written by Walter Bright |
|---|
| 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 |
#ifndef DMD_MODULE_H |
|---|
| 11 |
#define DMD_MODULE_H |
|---|
| 12 |
|
|---|
| 13 |
#ifdef __DMC__ |
|---|
| 14 |
#pragma once |
|---|
| 15 |
#endif /* __DMC__ */ |
|---|
| 16 |
|
|---|
| 17 |
#include "root.h" |
|---|
| 18 |
#include "dsymbol.h" |
|---|
| 19 |
|
|---|
| 20 |
struct ModuleInfoDeclaration; |
|---|
| 21 |
struct ClassDeclaration; |
|---|
| 22 |
struct ModuleDeclaration; |
|---|
| 23 |
struct Macro; |
|---|
| 24 |
struct Escape; |
|---|
| 25 |
struct VarDeclaration; |
|---|
| 26 |
struct Library; |
|---|
| 27 |
|
|---|
| 28 |
// Back end |
|---|
| 29 |
#if IN_GCC |
|---|
| 30 |
union tree_node; typedef union tree_node elem; |
|---|
| 31 |
#else |
|---|
| 32 |
struct elem; |
|---|
| 33 |
#endif |
|---|
| 34 |
|
|---|
| 35 |
struct Package : ScopeDsymbol |
|---|
| 36 |
{ |
|---|
| 37 |
Package(Identifier *ident); |
|---|
| 38 |
const char *kind(); |
|---|
| 39 |
|
|---|
| 40 |
static DsymbolTable *resolve(Array *packages, Dsymbol **pparent, Package **ppkg); |
|---|
| 41 |
|
|---|
| 42 |
Package *isPackage() { return this; } |
|---|
| 43 |
|
|---|
| 44 |
virtual void semantic(Scope *sc) { } |
|---|
| 45 |
}; |
|---|
| 46 |
|
|---|
| 47 |
struct Module : Package |
|---|
| 48 |
{ |
|---|
| 49 |
static Module *rootModule; |
|---|
| 50 |
static DsymbolTable *modules; // symbol table of all modules |
|---|
| 51 |
static Array amodules; // array of all modules |
|---|
| 52 |
static Array deferred; // deferred Dsymbol's needing semantic() run on them |
|---|
| 53 |
static unsigned dprogress; // progress resolving the deferred list |
|---|
| 54 |
static void init(); |
|---|
| 55 |
|
|---|
| 56 |
static ClassDeclaration *moduleinfo; |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
const char *arg; // original argument name |
|---|
| 60 |
ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration |
|---|
| 61 |
File *srcfile; // input source file |
|---|
| 62 |
File *objfile; // output .obj file |
|---|
| 63 |
File *hdrfile; // 'header' file |
|---|
| 64 |
File *symfile; // output symbol file |
|---|
| 65 |
File *docfile; // output documentation file |
|---|
| 66 |
unsigned errors; // if any errors in file |
|---|
| 67 |
unsigned numlines; // number of lines in source file |
|---|
| 68 |
int isHtml; // if it is an HTML file |
|---|
| 69 |
int isDocFile; // if it is a documentation input file, not D source |
|---|
| 70 |
int needmoduleinfo; |
|---|
| 71 |
#ifdef IN_GCC |
|---|
| 72 |
int strictlyneedmoduleinfo; |
|---|
| 73 |
#endif |
|---|
| 74 |
|
|---|
| 75 |
int selfimports; // 0: don't know, 1: does not, 2: does |
|---|
| 76 |
int selfImports(); // returns !=0 if module imports itself |
|---|
| 77 |
|
|---|
| 78 |
int insearch; |
|---|
| 79 |
Identifier *searchCacheIdent; |
|---|
| 80 |
Dsymbol *searchCacheSymbol; // cached value of search |
|---|
| 81 |
int searchCacheFlags; // cached flags |
|---|
| 82 |
|
|---|
| 83 |
int semanticstarted; // has semantic() been started? |
|---|
| 84 |
int semanticRun; // has semantic() been done? |
|---|
| 85 |
int root; // != 0 if this is a 'root' module, |
|---|
| 86 |
// i.e. a module that will be taken all the |
|---|
| 87 |
// way to an object file |
|---|
| 88 |
Module *importedFrom; // module from command line we're imported from, |
|---|
| 89 |
// i.e. a module that will be taken all the |
|---|
| 90 |
// way to an object file |
|---|
| 91 |
|
|---|
| 92 |
Array *decldefs; // top level declarations for this Module |
|---|
| 93 |
|
|---|
| 94 |
Array aimports; // all imported modules |
|---|
| 95 |
|
|---|
| 96 |
ModuleInfoDeclaration *vmoduleinfo; |
|---|
| 97 |
|
|---|
| 98 |
unsigned debuglevel; // debug level |
|---|
| 99 |
Array *debugids; // debug identifiers |
|---|
| 100 |
Array *debugidsNot; // forward referenced debug identifiers |
|---|
| 101 |
|
|---|
| 102 |
unsigned versionlevel; // version level |
|---|
| 103 |
Array *versionids; // version identifiers |
|---|
| 104 |
Array *versionidsNot; // forward referenced version identifiers |
|---|
| 105 |
|
|---|
| 106 |
Macro *macrotable; // document comment macros |
|---|
| 107 |
Escape *escapetable; // document comment escapes |
|---|
| 108 |
bool safe; // TRUE if module is marked as 'safe' |
|---|
| 109 |
|
|---|
| 110 |
size_t nameoffset; // offset of module name from start of ModuleInfo |
|---|
| 111 |
size_t namelen; // length of module name in characters |
|---|
| 112 |
|
|---|
| 113 |
Module(char *arg, Identifier *ident, int doDocComment, int doHdrGen); |
|---|
| 114 |
~Module(); |
|---|
| 115 |
|
|---|
| 116 |
static Module *load(Loc loc, Array *packages, Identifier *ident); |
|---|
| 117 |
|
|---|
| 118 |
void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
|---|
| 119 |
void toJsonBuffer(OutBuffer *buf); |
|---|
| 120 |
const char *kind(); |
|---|
| 121 |
void setDocfile(); // set docfile member |
|---|
| 122 |
void read(Loc loc); // read file |
|---|
| 123 |
#if IN_GCC |
|---|
| 124 |
void parse(bool dump_source = false); // syntactic parse |
|---|
| 125 |
#else |
|---|
| 126 |
void parse(); // syntactic parse |
|---|
| 127 |
#endif |
|---|
| 128 |
void importAll(Scope *sc); |
|---|
| 129 |
void semantic(); // semantic analysis |
|---|
| 130 |
void semantic2(); // pass 2 semantic analysis |
|---|
| 131 |
void semantic3(); // pass 3 semantic analysis |
|---|
| 132 |
void inlineScan(); // scan for functions to inline |
|---|
| 133 |
void setHdrfile(); // set hdrfile member |
|---|
| 134 |
#ifdef _DH |
|---|
| 135 |
void genhdrfile(); // generate D import file |
|---|
| 136 |
#endif |
|---|
| 137 |
void genobjfile(int multiobj); |
|---|
| 138 |
void gensymfile(); |
|---|
| 139 |
void gendocfile(); |
|---|
| 140 |
int needModuleInfo(); |
|---|
| 141 |
Dsymbol *search(Loc loc, Identifier *ident, int flags); |
|---|
| 142 |
Dsymbol *symtabInsert(Dsymbol *s); |
|---|
| 143 |
void deleteObjFile(); |
|---|
| 144 |
void addDeferredSemantic(Dsymbol *s); |
|---|
| 145 |
static void runDeferredSemantic(); |
|---|
| 146 |
static void clearCache(); |
|---|
| 147 |
int imports(Module *m); |
|---|
| 148 |
|
|---|
| 149 |
// Back end |
|---|
| 150 |
|
|---|
| 151 |
int doppelganger; // sub-module |
|---|
| 152 |
Symbol *cov; // private uint[] __coverage; |
|---|
| 153 |
unsigned *covb; // bit array of valid code line numbers |
|---|
| 154 |
|
|---|
| 155 |
Symbol *sictor; // module order independent constructor |
|---|
| 156 |
Symbol *sctor; // module constructor |
|---|
| 157 |
Symbol *sdtor; // module destructor |
|---|
| 158 |
Symbol *ssharedctor; // module shared constructor |
|---|
| 159 |
Symbol *sshareddtor; // module shared destructor |
|---|
| 160 |
Symbol *stest; // module unit test |
|---|
| 161 |
|
|---|
| 162 |
Symbol *sfilename; // symbol for filename |
|---|
| 163 |
|
|---|
| 164 |
Symbol *massert; // module assert function |
|---|
| 165 |
Symbol *toModuleAssert(); // get module assert function |
|---|
| 166 |
|
|---|
| 167 |
Symbol *munittest; // module unittest failure function |
|---|
| 168 |
Symbol *toModuleUnittest(); // get module unittest failure function |
|---|
| 169 |
|
|---|
| 170 |
Symbol *marray; // module array bounds function |
|---|
| 171 |
Symbol *toModuleArray(); // get module array bounds function |
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
static Symbol *gencritsec(); |
|---|
| 175 |
elem *toEfilename(); |
|---|
| 176 |
|
|---|
| 177 |
Symbol *toSymbol(); |
|---|
| 178 |
void genmoduleinfo(); |
|---|
| 179 |
|
|---|
| 180 |
Module *isModule() { return this; } |
|---|
| 181 |
}; |
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
struct ModuleDeclaration |
|---|
| 185 |
{ |
|---|
| 186 |
Identifier *id; |
|---|
| 187 |
Array *packages; // array of Identifier's representing packages |
|---|
| 188 |
bool safe; |
|---|
| 189 |
|
|---|
| 190 |
ModuleDeclaration(Array *packages, Identifier *id, bool safe); |
|---|
| 191 |
|
|---|
| 192 |
char *toChars(); |
|---|
| 193 |
}; |
|---|
| 194 |
|
|---|
| 195 |
#endif /* DMD_MODULE_H */ |
|---|