]> git.ipfire.org Git - people/ms/gcc.git/blob - gcc/d/dmd/module.h
bc89ac4677eeb3826c3e30ccd056da9e773bf26c
[people/ms/gcc.git] / gcc / d / dmd / module.h
1
2 /* Compiler implementation of the D programming language
3 * Copyright (C) 1999-2023 by The D Language Foundation, All Rights Reserved
4 * written by Walter Bright
5 * https://www.digitalmars.com
6 * Distributed under the Boost Software License, Version 1.0.
7 * https://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 "dsymbol.h"
14
15 struct ModuleDeclaration;
16 struct Escape;
17 struct FileBuffer;
18
19 struct MacroTable
20 {
21 void* internal; // PIMPL
22 };
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
38 const char *kind() const override;
39
40 bool equals(const RootObject * const o) const override;
41
42 Package *isPackage() override final { return this; }
43
44 bool isAncestorPackageOf(const Package * const pkg) const;
45
46 Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly) override;
47 void accept(Visitor *v) override { v->visit(this); }
48
49 Module *isPackageMod();
50 };
51
52 class Module final : 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
62 static void _init();
63
64 static AggregateDeclaration *moduleinfo;
65
66
67 DString arg; // original argument name
68 ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration
69 FileName srcfile; // input source file
70 FileName objfile; // output .obj file
71 FileName hdrfile; // 'header' file
72 FileName docfile; // output documentation file
73 DArray<unsigned char> src; // Raw content of the file
74 unsigned errors; // if any errors in file
75 unsigned numlines; // number of lines in source file
76 FileType filetype; // source file type
77 bool hasAlwaysInlines; // contains references to functions that must be inlined
78 bool isPackageFile; // if it is a package.d
79 Package *pkg; // if isPackageFile is true, the Package that contains this package.d
80 Strings contentImportedFiles; // array of files whose content was imported
81 int needmoduleinfo;
82 ThreeState selfimports;
83 ThreeState rootimports;
84 void* tagSymTab; // ImportC: tag symbols that conflict with other symbols used as the index
85 OutBuffer defines; // collect all the #define lines here
86 bool selfImports(); // returns true if module imports itself
87
88 bool rootImports(); // returns true if module imports root module
89
90 Identifier *searchCacheIdent;
91 Dsymbol *searchCacheSymbol; // cached value of search
92 int searchCacheFlags; // cached flags
93 bool insearch;
94
95 // module from command line we're imported from,
96 // i.e. a module that will be taken all the
97 // way to an object file
98 Module *importedFrom;
99
100 Dsymbols *decldefs; // top level declarations for this Module
101
102 Modules aimports; // all imported modules
103
104 unsigned debuglevel; // debug level
105 Identifiers *debugids; // debug identifiers
106 Identifiers *debugidsNot; // forward referenced debug identifiers
107
108 unsigned versionlevel; // version level
109 Identifiers *versionids; // version identifiers
110 Identifiers *versionidsNot; // forward referenced version identifiers
111
112 MacroTable macrotable; // document comment macros
113 Escape *escapetable; // document comment escapes
114
115 size_t nameoffset; // offset of module name from start of ModuleInfo
116 size_t namelen; // length of module name in characters
117
118 static Module* create(const char *arg, Identifier *ident, int doDocComment, int doHdrGen);
119 static const char *find(const char *filename);
120 static Module *load(const Loc &loc, Identifiers *packages, Identifier *ident);
121
122 const char *kind() const override;
123 bool read(const Loc &loc); // read file, returns 'true' if succeed, 'false' otherwise.
124 Module *parse(); // syntactic parse
125 void importAll(Scope *sc) override;
126 int needModuleInfo();
127 Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly) override;
128 bool isPackageAccessible(Package *p, Visibility visibility, int flags = 0) override;
129 Dsymbol *symtabInsert(Dsymbol *s) override;
130 void deleteObjFile();
131 static void runDeferredSemantic();
132 static void runDeferredSemantic2();
133 static void runDeferredSemantic3();
134 int imports(Module *m);
135
136 bool isRoot() { return this->importedFrom == this; }
137 // true if the module source file is directly
138 // listed in command line.
139 bool isCoreModule(Identifier *ident);
140
141 // Back end
142
143 int doppelganger; // sub-module
144 Symbol *cov; // private uint[] __coverage;
145 unsigned *covb; // bit array of valid code line numbers
146
147 Symbol *sictor; // module order independent constructor
148 Symbol *sctor; // module constructor
149 Symbol *sdtor; // module destructor
150 Symbol *ssharedctor; // module shared constructor
151 Symbol *sshareddtor; // module shared destructor
152 Symbol *stest; // module unit test
153
154 Symbol *sfilename; // symbol for filename
155
156 void *ctfe_cov; // stores coverage information from ctfe
157
158 Module *isModule() override { return this; }
159 void accept(Visitor *v) override { v->visit(this); }
160 };
161
162
163 struct ModuleDeclaration
164 {
165 Loc loc;
166 Identifier *id;
167 DArray<Identifier*> packages; // array of Identifier's representing packages
168 bool isdeprecated; // if it is a deprecated module
169 Expression *msg;
170
171 const char *toChars() const;
172 };