]>
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 | ||
13 | #include "root/root.h" | |
14 | #include "dsymbol.h" | |
15 | ||
16 | class ClassDeclaration; | |
17 | struct ModuleDeclaration; | |
18 | struct Macro; | |
19 | struct Escape; | |
20 | class VarDeclaration; | |
21 | class Library; | |
22 | ||
23 | enum PKG | |
24 | { | |
25 | PKGunknown, // not yet determined whether it's a package.d or not | |
26 | PKGmodule, // already determined that's an actual package.d | |
27 | PKGpackage // already determined that's an actual package | |
28 | }; | |
29 | ||
30 | class Package : public ScopeDsymbol | |
31 | { | |
32 | public: | |
33 | PKG isPkgMod; | |
34 | unsigned tag; // auto incremented tag, used to mask package tree in scopes | |
35 | Module *mod; // != NULL if isPkgMod == PKGmodule | |
36 | ||
37 | Package(Identifier *ident); | |
f9ab59ff | 38 | const char *kind() const; |
b4c522fa IB |
39 | |
40 | static DsymbolTable *resolve(Identifiers *packages, Dsymbol **pparent, Package **ppkg); | |
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(); | |
c5e94699 | 50 | void resolvePKGunknown(); |
b4c522fa IB |
51 | }; |
52 | ||
53 | class Module : public Package | |
54 | { | |
55 | public: | |
56 | static Module *rootModule; | |
57 | static DsymbolTable *modules; // symbol table of all modules | |
58 | static Modules amodules; // array of all modules | |
59 | static Dsymbols deferred; // deferred Dsymbol's needing semantic() run on them | |
60 | static Dsymbols deferred2; // deferred Dsymbol's needing semantic2() run on them | |
61 | static Dsymbols deferred3; // deferred Dsymbol's needing semantic3() run on them | |
62 | static unsigned dprogress; // progress resolving the deferred list | |
63 | static void _init(); | |
64 | ||
65 | static AggregateDeclaration *moduleinfo; | |
66 | ||
67 | ||
68 | const char *arg; // original argument name | |
69 | ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration | |
70 | File *srcfile; // input source file | |
b4c522fa IB |
71 | File *objfile; // output .obj file |
72 | File *hdrfile; // 'header' file | |
73 | File *docfile; // output documentation file | |
74 | unsigned errors; // if any errors in file | |
75 | unsigned numlines; // number of lines in source file | |
76 | int isDocFile; // if it is a documentation input file, not D source | |
77 | bool isPackageFile; // if it is a package.d | |
37482edc | 78 | Strings contentImportedFiles; // array of files whose content was imported |
b4c522fa IB |
79 | int needmoduleinfo; |
80 | ||
81 | int selfimports; // 0: don't know, 1: does not, 2: does | |
82 | bool selfImports(); // returns true if module imports itself | |
83 | ||
84 | int rootimports; // 0: don't know, 1: does not, 2: does | |
85 | bool rootImports(); // returns true if module imports root module | |
86 | ||
87 | int insearch; | |
88 | Identifier *searchCacheIdent; | |
89 | Dsymbol *searchCacheSymbol; // cached value of search | |
90 | int searchCacheFlags; // cached flags | |
91 | ||
92 | // module from command line we're imported from, | |
93 | // i.e. a module that will be taken all the | |
94 | // way to an object file | |
95 | Module *importedFrom; | |
96 | ||
97 | Dsymbols *decldefs; // top level declarations for this Module | |
98 | ||
99 | Modules aimports; // all imported modules | |
100 | ||
101 | unsigned debuglevel; // debug level | |
5bc13e52 IB |
102 | Identifiers *debugids; // debug identifiers |
103 | Identifiers *debugidsNot; // forward referenced debug identifiers | |
b4c522fa IB |
104 | |
105 | unsigned versionlevel; // version level | |
5bc13e52 IB |
106 | Identifiers *versionids; // version identifiers |
107 | Identifiers *versionidsNot; // forward referenced version identifiers | |
b4c522fa IB |
108 | |
109 | Macro *macrotable; // document comment macros | |
110 | Escape *escapetable; // document comment escapes | |
111 | ||
112 | size_t nameoffset; // offset of module name from start of ModuleInfo | |
113 | size_t namelen; // length of module name in characters | |
114 | ||
115 | Module(const char *arg, Identifier *ident, int doDocComment, int doHdrGen); | |
116 | static Module* create(const char *arg, Identifier *ident, int doDocComment, int doHdrGen); | |
117 | ||
118 | static Module *load(Loc loc, Identifiers *packages, Identifier *ident); | |
119 | ||
f9ab59ff | 120 | const char *kind() const; |
b4c522fa IB |
121 | File *setOutfile(const char *name, const char *dir, const char *arg, const char *ext); |
122 | void setDocfile(); | |
123 | bool read(Loc loc); // read file, returns 'true' if succeed, 'false' otherwise. | |
124 | Module *parse(); // syntactic parse | |
125 | void importAll(Scope *sc); | |
b4c522fa IB |
126 | int needModuleInfo(); |
127 | Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly); | |
128 | bool isPackageAccessible(Package *p, Prot protection, int flags = 0); | |
129 | Dsymbol *symtabInsert(Dsymbol *s); | |
130 | void deleteObjFile(); | |
131 | static void addDeferredSemantic(Dsymbol *s); | |
132 | static void addDeferredSemantic2(Dsymbol *s); | |
133 | static void addDeferredSemantic3(Dsymbol *s); | |
134 | static void runDeferredSemantic(); | |
135 | static void runDeferredSemantic2(); | |
136 | static void runDeferredSemantic3(); | |
137 | static void clearCache(); | |
138 | int imports(Module *m); | |
139 | ||
140 | bool isRoot() { return this->importedFrom == this; } | |
141 | // true if the module source file is directly | |
142 | // listed in command line. | |
143 | bool isCoreModule(Identifier *ident); | |
144 | ||
145 | // Back end | |
146 | ||
147 | int doppelganger; // sub-module | |
148 | Symbol *cov; // private uint[] __coverage; | |
149 | unsigned *covb; // bit array of valid code line numbers | |
150 | ||
151 | Symbol *sictor; // module order independent constructor | |
152 | Symbol *sctor; // module constructor | |
153 | Symbol *sdtor; // module destructor | |
154 | Symbol *ssharedctor; // module shared constructor | |
155 | Symbol *sshareddtor; // module shared destructor | |
156 | Symbol *stest; // module unit test | |
157 | ||
158 | Symbol *sfilename; // symbol for filename | |
159 | ||
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; | |
169 | Identifiers *packages; // array of Identifier's representing packages | |
170 | bool isdeprecated; // if it is a deprecated module | |
171 | Expression *msg; | |
172 | ||
173 | ModuleDeclaration(Loc loc, Identifiers *packages, Identifier *id); | |
174 | ||
175 | const char *toChars(); | |
176 | }; |