]>
Commit | Line | Data |
---|---|---|
b4c522fa IB |
1 | |
2 | /* Compiler implementation of the D programming language | |
a3b38b77 | 3 | * Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved |
b4c522fa IB |
4 | * written by Walter Bright |
5 | * http://www.digitalmars.com | |
6 | * Distributed under the Boost Software License, Version 1.0. | |
7 | * http://www.boost.org/LICENSE_1_0.txt | |
8 | * https://github.com/dlang/dmd/blob/master/src/dmd/module.h | |
9 | */ | |
10 | ||
11 | #pragma once | |
12 | ||
b4c522fa IB |
13 | #include "dsymbol.h" |
14 | ||
b4c522fa | 15 | struct ModuleDeclaration; |
b4c522fa | 16 | struct Escape; |
5fee5ec3 IB |
17 | struct FileBuffer; |
18 | ||
19 | struct MacroTable | |
20 | { | |
21 | void* internal; // PIMPL | |
22 | }; | |
b4c522fa IB |
23 | |
24 | enum PKG | |
25 | { | |
26 | PKGunknown, // not yet determined whether it's a package.d or not | |
27 | PKGmodule, // already determined that's an actual package.d | |
28 | PKGpackage // already determined that's an actual package | |
29 | }; | |
30 | ||
31 | class Package : public ScopeDsymbol | |
32 | { | |
33 | public: | |
34 | PKG isPkgMod; | |
35 | unsigned tag; // auto incremented tag, used to mask package tree in scopes | |
36 | Module *mod; // != NULL if isPkgMod == PKGmodule | |
37 | ||
f9ab59ff | 38 | const char *kind() const; |
b4c522fa | 39 | |
5fee5ec3 | 40 | bool equals(const RootObject *o) const; |
b4c522fa IB |
41 | |
42 | Package *isPackage() { return this; } | |
43 | ||
44 | bool isAncestorPackageOf(const Package * const pkg) const; | |
45 | ||
b4c522fa IB |
46 | Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly); |
47 | void accept(Visitor *v) { v->visit(this); } | |
48 | ||
49 | Module *isPackageMod(); | |
50 | }; | |
51 | ||
52 | class Module : public Package | |
53 | { | |
54 | public: | |
55 | static Module *rootModule; | |
56 | static DsymbolTable *modules; // symbol table of all modules | |
57 | static Modules amodules; // array of all modules | |
58 | static Dsymbols deferred; // deferred Dsymbol's needing semantic() run on them | |
59 | static Dsymbols deferred2; // deferred Dsymbol's needing semantic2() run on them | |
60 | static Dsymbols deferred3; // deferred Dsymbol's needing semantic3() run on them | |
61 | static unsigned dprogress; // progress resolving the deferred list | |
5fee5ec3 | 62 | |
b4c522fa IB |
63 | static void _init(); |
64 | ||
65 | static AggregateDeclaration *moduleinfo; | |
66 | ||
67 | ||
5fee5ec3 | 68 | DString arg; // original argument name |
b4c522fa | 69 | ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration |
5fee5ec3 IB |
70 | FileName srcfile; // input source file |
71 | FileName objfile; // output .obj file | |
72 | FileName hdrfile; // 'header' file | |
73 | FileName docfile; // output documentation file | |
74 | FileBuffer *srcBuffer; // set during load(), free'd in parse() | |
b4c522fa IB |
75 | unsigned errors; // if any errors in file |
76 | unsigned numlines; // number of lines in source file | |
5fee5ec3 IB |
77 | bool isHdrFile; // if it is a header (.di) file |
78 | bool isCFile; // if it is a C (.c) file | |
79 | bool isDocFile; // if it is a documentation input file, not D source | |
80 | bool hasAlwaysInlines; // contains references to functions that must be inlined | |
b4c522fa | 81 | bool isPackageFile; // if it is a package.d |
5a0aa603 | 82 | Package *pkg; // if isPackageFile is true, the Package that contains this package.d |
37482edc | 83 | Strings contentImportedFiles; // array of files whose content was imported |
b4c522fa | 84 | int needmoduleinfo; |
b4c522fa | 85 | int selfimports; // 0: don't know, 1: does not, 2: does |
5fee5ec3 | 86 | void* tagSymTab; // ImportC: tag symbols that conflict with other symbols used as the index |
b4c522fa IB |
87 | bool selfImports(); // returns true if module imports itself |
88 | ||
89 | int rootimports; // 0: don't know, 1: does not, 2: does | |
90 | bool rootImports(); // returns true if module imports root module | |
91 | ||
92 | int insearch; | |
93 | Identifier *searchCacheIdent; | |
94 | Dsymbol *searchCacheSymbol; // cached value of search | |
95 | int searchCacheFlags; // cached flags | |
96 | ||
97 | // module from command line we're imported from, | |
98 | // i.e. a module that will be taken all the | |
99 | // way to an object file | |
100 | Module *importedFrom; | |
101 | ||
102 | Dsymbols *decldefs; // top level declarations for this Module | |
103 | ||
104 | Modules aimports; // all imported modules | |
105 | ||
106 | unsigned debuglevel; // debug level | |
5bc13e52 | 107 | Identifiers *debugids; // debug identifiers |
5fee5ec3 | 108 | Identifiers *debugidsNot; // forward referenced debug identifiers |
b4c522fa IB |
109 | |
110 | unsigned versionlevel; // version level | |
5bc13e52 | 111 | Identifiers *versionids; // version identifiers |
5fee5ec3 | 112 | Identifiers *versionidsNot; // forward referenced version identifiers |
b4c522fa | 113 | |
5fee5ec3 | 114 | MacroTable macrotable; // document comment macros |
b4c522fa IB |
115 | Escape *escapetable; // document comment escapes |
116 | ||
117 | size_t nameoffset; // offset of module name from start of ModuleInfo | |
118 | size_t namelen; // length of module name in characters | |
119 | ||
b4c522fa IB |
120 | static Module* create(const char *arg, Identifier *ident, int doDocComment, int doHdrGen); |
121 | ||
122 | static Module *load(Loc loc, Identifiers *packages, Identifier *ident); | |
123 | ||
f9ab59ff | 124 | const char *kind() const; |
5fee5ec3 | 125 | bool read(const Loc &loc); // read file, returns 'true' if succeed, 'false' otherwise. |
b4c522fa IB |
126 | Module *parse(); // syntactic parse |
127 | void importAll(Scope *sc); | |
b4c522fa IB |
128 | int needModuleInfo(); |
129 | Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly); | |
5fee5ec3 | 130 | bool isPackageAccessible(Package *p, Visibility visibility, int flags = 0); |
b4c522fa IB |
131 | Dsymbol *symtabInsert(Dsymbol *s); |
132 | void deleteObjFile(); | |
b4c522fa IB |
133 | static void runDeferredSemantic(); |
134 | static void runDeferredSemantic2(); | |
135 | static void runDeferredSemantic3(); | |
b4c522fa IB |
136 | int imports(Module *m); |
137 | ||
138 | bool isRoot() { return this->importedFrom == this; } | |
139 | // true if the module source file is directly | |
140 | // listed in command line. | |
141 | bool isCoreModule(Identifier *ident); | |
142 | ||
143 | // Back end | |
144 | ||
145 | int doppelganger; // sub-module | |
146 | Symbol *cov; // private uint[] __coverage; | |
147 | unsigned *covb; // bit array of valid code line numbers | |
148 | ||
149 | Symbol *sictor; // module order independent constructor | |
150 | Symbol *sctor; // module constructor | |
151 | Symbol *sdtor; // module destructor | |
152 | Symbol *ssharedctor; // module shared constructor | |
153 | Symbol *sshareddtor; // module shared destructor | |
154 | Symbol *stest; // module unit test | |
155 | ||
156 | Symbol *sfilename; // symbol for filename | |
157 | ||
5fee5ec3 IB |
158 | void *ctfe_cov; // stores coverage information from ctfe |
159 | ||
b4c522fa IB |
160 | Module *isModule() { return this; } |
161 | void accept(Visitor *v) { v->visit(this); } | |
162 | }; | |
163 | ||
164 | ||
165 | struct ModuleDeclaration | |
166 | { | |
167 | Loc loc; | |
168 | Identifier *id; | |
5fee5ec3 | 169 | DArray<Identifier*> packages; // array of Identifier's representing packages |
b4c522fa IB |
170 | bool isdeprecated; // if it is a deprecated module |
171 | Expression *msg; | |
172 | ||
5fee5ec3 | 173 | const char *toChars() const; |
b4c522fa | 174 | }; |