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